[PATCH 2/2] drm/amd/pm: ensure the fw_info is not null before using it

2024-08-09 Thread Tim Huang
This resolves the dereference null return value warning
reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c 
b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c
index ca1c7ae8d146..f06b29e33ba4 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/processpptables.c
@@ -1183,6 +1183,8 @@ static int init_overdrive_limits(struct pp_hwmgr *hwmgr,
fw_info = smu_atom_get_data_table(hwmgr->adev,
 GetIndexIntoMasterTable(DATA, FirmwareInfo),
 &size, &frev, &crev);
+   PP_ASSERT_WITH_CODE(fw_info != NULL,
+   "Missing firmware info!", return -EINVAL);
 
if ((fw_info->ucTableFormatRevision == 1)
&& (le16_to_cpu(fw_info->usStructureSize) >= 
sizeof(ATOM_FIRMWARE_INFO_V1_4)))
-- 
2.43.0



[PATCH 1/2] drm/amdgpu: ensure the connector is not null before using it

2024-08-09 Thread Tim Huang
This resolves the dereference null return value warning
reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
index 092ec11258cd..046d4c4e0299 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
@@ -1474,7 +1474,7 @@ bool amdgpu_display_crtc_scaling_mode_fixup(struct 
drm_crtc *crtc,
if ((!(mode->flags & DRM_MODE_FLAG_INTERLACE)) &&
((amdgpu_encoder->underscan_type == UNDERSCAN_ON) ||
 ((amdgpu_encoder->underscan_type == UNDERSCAN_AUTO) &&
- connector->display_info.is_hdmi &&
+ connector && connector->display_info.is_hdmi &&
  amdgpu_display_is_hdtv_mode(mode {
if (amdgpu_encoder->underscan_hborder != 0)
amdgpu_crtc->h_border = 
amdgpu_encoder->underscan_hborder;
-- 
2.43.0



[PATCH] drm/amd/display: fix double free issue during amdgpu module unload

2024-08-06 Thread Tim Huang
Flexible endpoints use DIGs from available inflexible endpoints,
so only the encoders of inflexible links need to be freed.
Otherwise, a double free issue may occur when unloading the
amdgpu module.

[  279.190523] RIP: 0010:__slab_free+0x152/0x2f0
[  279.190577] Call Trace:
[  279.190580]  
[  279.190582]  ? show_regs+0x69/0x80
[  279.190590]  ? die+0x3b/0x90
[  279.190595]  ? do_trap+0xc8/0xe0
[  279.190601]  ? do_error_trap+0x73/0xa0
[  279.190605]  ? __slab_free+0x152/0x2f0
[  279.190609]  ? exc_invalid_op+0x56/0x70
[  279.190616]  ? __slab_free+0x152/0x2f0
[  279.190642]  ? asm_exc_invalid_op+0x1f/0x30
[  279.190648]  ? dcn10_link_encoder_destroy+0x19/0x30 [amdgpu]
[  279.191096]  ? __slab_free+0x152/0x2f0
[  279.191102]  ? dcn10_link_encoder_destroy+0x19/0x30 [amdgpu]
[  279.191469]  kfree+0x260/0x2b0
[  279.191474]  dcn10_link_encoder_destroy+0x19/0x30 [amdgpu]
[  279.191821]  link_destroy+0xd7/0x130 [amdgpu]
[  279.192248]  dc_destruct+0x90/0x270 [amdgpu]
[  279.192666]  dc_destroy+0x19/0x40 [amdgpu]
[  279.193020]  amdgpu_dm_fini+0x16e/0x200 [amdgpu]
[  279.193432]  dm_hw_fini+0x26/0x40 [amdgpu]
[  279.193795]  amdgpu_device_fini_hw+0x24c/0x400 [amdgpu]
[  279.194108]  amdgpu_driver_unload_kms+0x4f/0x70 [amdgpu]
[  279.194436]  amdgpu_pci_remove+0x40/0x80 [amdgpu]
[  279.194632]  pci_device_remove+0x3a/0xa0
[  279.194638]  device_remove+0x40/0x70
[  279.194642]  device_release_driver_internal+0x1ad/0x210
[  279.194647]  driver_detach+0x4e/0xa0
[  279.194650]  bus_remove_driver+0x6f/0xf0
[  279.194653]  driver_unregister+0x33/0x60
[  279.194657]  pci_unregister_driver+0x44/0x90
[  279.194662]  amdgpu_exit+0x19/0x1f0 [amdgpu]
[  279.194939]  __do_sys_delete_module.isra.0+0x198/0x2f0
[  279.194946]  __x64_sys_delete_module+0x16/0x20
[  279.194950]  do_syscall_64+0x58/0x120
[  279.194954]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[  279.194980]  

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/display/dc/link/link_factory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/link/link_factory.c 
b/drivers/gpu/drm/amd/display/dc/link/link_factory.c
index 8246006857b3..49d069dae29b 100644
--- a/drivers/gpu/drm/amd/display/dc/link/link_factory.c
+++ b/drivers/gpu/drm/amd/display/dc/link/link_factory.c
@@ -385,7 +385,7 @@ static void link_destruct(struct dc_link *link)
if (link->panel_cntl)
link->panel_cntl->funcs->destroy(&link->panel_cntl);
 
-   if (link->link_enc) {
+   if (link->link_enc && !link->is_dig_mapping_flexible) {
/* Update link encoder resource tracking variables. These are 
used for
 * the dynamic assignment of link encoders to streams. Virtual 
links
 * are not assigned encoder resources on creation.
-- 
2.43.0



[PATCH 3/4] drm/amdgpu: fix unchecked return value warning for amdgpu_atombios

2024-08-01 Thread Tim Huang
This resolves the unchecded return value warning reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 35 
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 7dc102f0bc1d..0c8975ac5af9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -1018,8 +1018,9 @@ int amdgpu_atombios_get_clock_dividers(struct 
amdgpu_device *adev,
if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
args.v3.ulClockParams = cpu_to_le32((clock_type << 24) 
| clock);
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, 
index, (uint32_t *)&args,
-   sizeof(args));
+   if 
(amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
dividers->post_div = args.v3.ucPostDiv;
dividers->enable_post_div = (args.v3.ucCntlFlag &
@@ -1039,8 +1040,9 @@ int amdgpu_atombios_get_clock_dividers(struct 
amdgpu_device *adev,
if (strobe_mode)
args.v5.ucInputFlag = 
ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, 
index, (uint32_t *)&args,
-   sizeof(args));
+   if 
(amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
dividers->post_div = args.v5.ucPostDiv;
dividers->enable_post_div = (args.v5.ucCntlFlag &
@@ -1058,8 +1060,9 @@ int amdgpu_atombios_get_clock_dividers(struct 
amdgpu_device *adev,
/* fusion */
args.v4.ulClock = cpu_to_le32(clock);   /* 10 khz */
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, index, 
(uint32_t *)&args,
-   sizeof(args));
+   if (amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
dividers->real_clock = le32_to_cpu(args.v4.ulClock);
@@ -1070,8 +1073,9 @@ int amdgpu_atombios_get_clock_dividers(struct 
amdgpu_device *adev,
args.v6_in.ulClock.ulComputeClockFlag = clock_type;
args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock);/* 10 
khz */
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, index, 
(uint32_t *)&args,
-   sizeof(args));
+   if (amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
dividers->whole_fb_div = 
le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
dividers->frac_fb_div = 
le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
@@ -1113,8 +1117,9 @@ int amdgpu_atombios_get_memory_pll_dividers(struct 
amdgpu_device *adev,
if (strobe_mode)
args.ucInputFlag |= 
MPLL_INPUT_FLAG_STROBE_MODE_EN;
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, 
index, (uint32_t *)&args,
-   sizeof(args));
+   if 
(amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
mpll_param->clkfrac = 
le16_to_cpu(args.ulFbDiv.usFbDivFrac);
mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
@@ -1211,8 +1216,9 @@ int amdgpu_atombios_get_max_vddc(struct amdgpu_device 
*adev, u8 voltage_type,
args.v2.ucVoltageMode = 0;
args.v2.usVoltageLevel = 0;
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, index, 
(uint32_t *)&args,
-   sizeof(args));
+   if (amdgpu_atom_execute_table(adev->mode_info.atom_context,
+   index, (uint32_t *)&args, sizeof(args)))
+   return -EINVAL;
 
*voltage = le16_to_cpu(args.v2.usVoltageLevel);
break;
@@ -1221,8 +1227,9 @@ int amdgpu_atombios_get_max_vddc(struct amdgpu_device 
*adev, u8 voltage_type,
args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
args.v3.usVoltageL

[PATCH 4/4] drm/amdgpu: check return for setting engine dram timings

2024-08-01 Thread Tim Huang
This resolves the unchecded return value warning reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 8 
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h | 4 ++--
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c   | 8 +---
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 0c8975ac5af9..093141ad6ed0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -1145,8 +1145,8 @@ int amdgpu_atombios_get_memory_pll_dividers(struct 
amdgpu_device *adev,
return 0;
 }
 
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-u32 eng_clock, u32 mem_clock)
+int amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
+   u32 eng_clock, u32 mem_clock)
 {
SET_ENGINE_CLOCK_PS_ALLOCATION args;
int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
@@ -1161,8 +1161,8 @@ void amdgpu_atombios_set_engine_dram_timings(struct 
amdgpu_device *adev,
if (mem_clock)
args.sReserved.ulClock = cpu_to_le32(mem_clock & 
SET_CLOCK_FREQ_MASK);
 
-   amdgpu_atom_execute_table(adev->mode_info.atom_context, index, 
(uint32_t *)&args,
-   sizeof(args));
+   return amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
+(uint32_t *)&args, sizeof(args));
 }
 
 void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
index 0811474e8fd3..0e16432d9a72 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
@@ -163,8 +163,8 @@ int amdgpu_atombios_get_memory_pll_dividers(struct 
amdgpu_device *adev,
bool strobe_mode,
struct atom_mpll_param *mpll_param);
 
-void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
-u32 eng_clock, u32 mem_clock);
+int amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
+   u32 eng_clock, u32 mem_clock);
 
 bool
 amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c 
b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
index a1baa13ab2c2..43028e776c93 100644
--- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
+++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
@@ -4755,13 +4755,15 @@ static int si_populate_memory_timing_parameters(struct 
amdgpu_device *adev,
u32 dram_timing;
u32 dram_timing2;
u32 burst_time;
+   int ret;
 
arb_regs->mc_arb_rfsh_rate =
(u8)si_calculate_memory_refresh_rate(adev, pl->sclk);
 
-   amdgpu_atombios_set_engine_dram_timings(adev,
-   pl->sclk,
-   pl->mclk);
+   ret = amdgpu_atombios_set_engine_dram_timings(adev, pl->sclk,
+ pl->mclk);
+   if (ret)
+   return ret;
 
dram_timing  = RREG32(MC_ARB_DRAM_TIMING);
dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
-- 
2.43.0



[PATCH 2/4] drm/amdgpu: fix unchecked return value warning for amdgpu_gfx

2024-08-01 Thread Tim Huang
This resolves the unchecded return value warning reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 82452606ae6c..5c9f36f01db0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -860,8 +860,11 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, 
struct ras_common_if *r
int r;
 
if (amdgpu_ras_is_supported(adev, ras_block->block)) {
-   if (!amdgpu_persistent_edc_harvesting_supported(adev))
-   amdgpu_ras_reset_error_status(adev, 
AMDGPU_RAS_BLOCK__GFX);
+   if (!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)
@@ -1005,7 +1008,10 @@ uint32_t amdgpu_kiq_rreg(struct amdgpu_device *adev, 
uint32_t reg, uint32_t xcc_
pr_err("critical bug! too many kiq readers\n");
goto failed_unlock;
}
-   amdgpu_ring_alloc(ring, 32);
+   r = amdgpu_ring_alloc(ring, 32);
+   if (r)
+   goto failed_unlock;
+
amdgpu_ring_emit_rreg(ring, reg, reg_val_offs);
r = amdgpu_fence_emit_polling(ring, &seq, MAX_KIQ_REG_WAIT);
if (r)
@@ -1071,7 +1077,10 @@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, 
uint32_t reg, uint32_t v, uint3
}
 
spin_lock_irqsave(&kiq->ring_lock, flags);
-   amdgpu_ring_alloc(ring, 32);
+   r = amdgpu_ring_alloc(ring, 32);
+   if (r)
+   goto failed_unlock;
+
amdgpu_ring_emit_wreg(ring, reg, v);
r = amdgpu_fence_emit_polling(ring, &seq, MAX_KIQ_REG_WAIT);
if (r)
@@ -1107,6 +1116,7 @@ void amdgpu_kiq_wreg(struct amdgpu_device *adev, uint32_t 
reg, uint32_t v, uint3
 
 failed_undo:
amdgpu_ring_undo(ring);
+failed_unlock:
spin_unlock_irqrestore(&kiq->ring_lock, flags);
 failed_kiq_write:
dev_err(adev->dev, "failed to write reg:%x\n", reg);
-- 
2.43.0



[PATCH 1/4] drm/amd/pm: fix unchecked return value warning for vega10_hwmgr

2024-08-01 Thread Tim Huang
This resolves the unchecked return value warning reported by Coverity.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
index 6e717ddbb029..9ace863792d4 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
@@ -2934,9 +2934,7 @@ static int vega10_stop_dpm(struct pp_hwmgr *hwmgr, 
uint32_t bitmap)
}
}
 
-   vega10_enable_smc_features(hwmgr, false, feature_mask);
-
-   return 0;
+   return vega10_enable_smc_features(hwmgr, false, feature_mask);
 }
 
 /**
-- 
2.43.0



[PATCH] drm/amdgpu: fix Coverity explicit null dereferenced warnings

2024-07-24 Thread Tim Huang
This is to address the Coverity explicit null dereferenced warnings
by NULL returns from amdgpu_mes_ctx_get_offs* but without follow-up
Checks. Meanwhile refactor the code to keep only one *_get_gpu/cpu_addr.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 14 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 17 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c   | 14 +++---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c   |  8 
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c| 14 +++---
 drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c   | 12 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c   | 12 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c   | 12 ++--
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c   | 12 ++--
 11 files changed, 55 insertions(+), 64 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
index e499d6ba306b..fb708b695db8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
@@ -1082,7 +1082,7 @@ int amdgpu_mes_add_ring(struct amdgpu_device *adev, int 
gang_id,
int offset = offsetof(struct amdgpu_mes_ctx_meta_data,
  compute[ring->idx].mec_hpd);
ring->eop_gpu_addr =
-   amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
+   amdgpu_ring_get_gpu_addr(ring, offset);
}
 
switch (queue_type) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index ad49cecb20b8..01dd7b30ba74 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -169,16 +169,6 @@ void amdgpu_ring_undo(struct amdgpu_ring *ring)
ring->funcs->end_use(ring);
 }
 
-#define amdgpu_ring_get_gpu_addr(ring, offset) \
-   (ring->is_mes_queue ?   \
-(ring->mes_ctx->meta_data_gpu_addr + offset) : \
-(ring->adev->wb.gpu_addr + offset * 4))
-
-#define amdgpu_ring_get_cpu_addr(ring, offset) \
-   (ring->is_mes_queue ?   \
-(void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset) : \
-(&ring->adev->wb.wb[offset]))
-
 /**
  * amdgpu_ring_init - init driver ring struct.
  *
@@ -332,8 +322,8 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct 
amdgpu_ring *ring,
 
offset = amdgpu_mes_ctx_get_offs(ring,
 AMDGPU_MES_CTX_RING_OFFS);
-   ring->gpu_addr = amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset);
-   ring->ring = amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset);
+   ring->gpu_addr = amdgpu_ring_get_gpu_addr(ring, offset);
+   ring->ring = amdgpu_ring_get_cpu_addr(ring, offset);
amdgpu_ring_clear_ring(ring);
 
} else if (ring->ring_obj == NULL) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
index 582053f1cd56..f65f13d147b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
@@ -436,14 +436,15 @@ static inline void amdgpu_ring_patch_cond_exec(struct 
amdgpu_ring *ring,
ring->ring[offset] = cur - offset;
 }
 
-#define amdgpu_mes_ctx_get_offs_gpu_addr(ring, offset) \
-   (ring->is_mes_queue && ring->mes_ctx ?  \
-(ring->mes_ctx->meta_data_gpu_addr + offset) : 0)
-
-#define amdgpu_mes_ctx_get_offs_cpu_addr(ring, offset) \
-   (ring->is_mes_queue && ring->mes_ctx ?  \
-(void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset) : \
-NULL)
+#define amdgpu_ring_get_gpu_addr(ring, offset) \
+   (ring->is_mes_queue ?   \
+   (ring->mes_ctx->meta_data_gpu_addr + offset) :  \
+   (ring->adev->wb.gpu_addr + offset * 4))
+
+#define amdgpu_ring_get_cpu_addr(ring, offset) \
+   (ring->is_mes_queue ?   \
+   ((void *)((uint8_t *)(ring->mes_ctx->meta_data_ptr) + offset)) : \
+   ((void *)(&ring->adev->wb.wb[offset])))
 
 int amdgpu_ring_test_helper(struct amdgpu_ring *ring);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
index 183a976ba29d..8eca0f1733ce 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c
@@ -80,7 +

[PATCH] drm/amdgpu: add missed harvest check for VCN IP v4/v5

2024-07-23 Thread Tim Huang
To prevent below probe failure, add a check for models with VCN
IP v4.0.6 where VCN1 may be harvested.

v2:
Apply the same check to VCN IP v4.0 and v5.0.

[   54.070117] RIP: 0010:vcn_v4_0_5_start_dpg_mode+0x9be/0x36b0 [amdgpu]
[   54.071055] Code: 80 fb ff 8d 82 00 80 fe ff 81 fe 00 06 00 00 0f 43
c2 49 69 d5 38 0d 00 00 48 8d 71 04 c1 e8 02 4c 01 f2 48 89 b2 50 f6 02
00 <89> 01 48 8b 82 50 f6 02 00 48 8d 48 04 48 89 8a 50 f6 02 00 c7 00
[   54.072408] RSP: 0018:b17985f736f8 EFLAGS: 00010286
[   54.072793] RAX: 00d6 RBX: 99a82f68 RCX:

[   54.073315] RDX: 99a82f68 RSI: 0004 RDI:
99a82f68
[   54.073835] RBP: b17985f73730 R08: 0001 R09:

[   54.074353] R10: 0008 R11: b17983c05000 R12:

[   54.074879] R13:  R14: 99a82f68 R15:
0001
[   54.075400] FS:  7f8d9c79a000() GS:99ab2f14()
knlGS:
[   54.075988] CS:  0010 DS:  ES:  CR0: 80050033
[   54.076408] CR2:  CR3: 000140c3a000 CR4:
00750ef0
[   54.076927] PKRU: 5554
[   54.077132] Call Trace:
[   54.077319]  
[   54.077484]  ? show_regs+0x69/0x80
[   54.077747]  ? __die+0x28/0x70
[   54.077979]  ? page_fault_oops+0x180/0x4b0
[   54.078286]  ? do_user_addr_fault+0x2d2/0x680
[   54.078610]  ? exc_page_fault+0x84/0x190
[   54.078910]  ? asm_exc_page_fault+0x2b/0x30
[   54.079224]  ? vcn_v4_0_5_start_dpg_mode+0x9be/0x36b0 [amdgpu]
[   54.079941]  ? vcn_v4_0_5_start_dpg_mode+0xe6/0x36b0 [amdgpu]
[   54.080617]  vcn_v4_0_5_set_powergating_state+0x82/0x19b0 [amdgpu]
[   54.081316]  amdgpu_device_ip_set_powergating_state+0x64/0xc0
[amdgpu]
[   54.082057]  amdgpu_vcn_ring_begin_use+0x6f/0x1d0 [amdgpu]
[   54.082727]  amdgpu_ring_alloc+0x44/0x70 [amdgpu]
[   54.083351]  amdgpu_vcn_dec_sw_ring_test_ring+0x40/0x110 [amdgpu]
[   54.084054]  amdgpu_ring_test_helper+0x22/0x90 [amdgpu]
[   54.084698]  vcn_v4_0_5_hw_init+0x87/0xc0 [amdgpu]
[   54.085307]  amdgpu_device_init+0x1f96/0x2780 [amdgpu]
[   54.085951]  amdgpu_driver_load_kms+0x1e/0xc0 [amdgpu]
[   54.086591]  amdgpu_pci_probe+0x19f/0x550 [amdgpu]
[   54.087215]  local_pci_probe+0x48/0xa0
[   54.087509]  pci_device_probe+0xc9/0x250
[   54.087812]  really_probe+0x1a4/0x3f0
[   54.088101]  __driver_probe_device+0x7d/0x170
[   54.088443]  driver_probe_device+0x24/0xa0
[   54.088765]  __driver_attach+0xdd/0x1d0
[   54.089068]  ? __pfx___driver_attach+0x10/0x10
[   54.089417]  bus_for_each_dev+0x8e/0xe0
[   54.089718]  driver_attach+0x22/0x30
[   54.09]  bus_add_driver+0x120/0x220
[   54.090303]  driver_register+0x62/0x120
[   54.090606]  ? __pfx_amdgpu_init+0x10/0x10 [amdgpu]
[   54.091255]  __pci_register_driver+0x62/0x70
[   54.091593]  amdgpu_init+0x67/0xff0 [amdgpu]
[   54.092190]  do_one_initcall+0x5f/0x330
[   54.092495]  do_init_module+0x68/0x240
[   54.092794]  load_module+0x201c/0x2110
[   54.093093]  init_module_from_file+0x97/0xd0
[   54.093428]  ? init_module_from_file+0x97/0xd0
[   54.093777]  idempotent_init_module+0x11c/0x2a0
[   54.094134]  __x64_sys_finit_module+0x64/0xc0
[   54.094476]  do_syscall_64+0x58/0x120
[   54.094767]  entry_SYSCALL_64_after_hwframe+0x6e/0x76

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 6 ++
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 6 ++
 drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 6 ++
 3 files changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index f6d96a44d75f..776c539bfdda 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
@@ -1045,6 +1045,9 @@ static int vcn_v4_0_start(struct amdgpu_device *adev)
amdgpu_dpm_enable_uvd(adev, true);
 
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   if (adev->vcn.harvest_config & (1 << i))
+   continue;
+
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
 
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) {
@@ -1498,6 +1501,9 @@ static int vcn_v4_0_stop(struct amdgpu_device *adev)
int i, r = 0;
 
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   if (adev->vcn.harvest_config & (1 << i))
+   continue;
+
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
fw_shared->sq.queue_mode |= FW_QUEUE_DPG_HOLD_OFF;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
index f45495de6875..8d75061f9f38 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
@@ -958,6 +958,9 @@ static int vcn_v4_0_5_start(struct amdgpu_device *adev)
amdgpu_dpm_enable_uvd(adev, true);
 
for (i = 0; i < adev->vcn.num_vcn_i

[PATCH] drm/amdgpu: fix potential probe issue for VCN IP v4.0.6

2024-07-23 Thread Tim Huang
To prevent below probe failure, add a check for models with VCN
IP v4.0.6 where VCN1 may be harvested.

[   54.070117] RIP: 0010:vcn_v4_0_5_start_dpg_mode+0x9be/0x36b0 [amdgpu]
[   54.071055] Code: 80 fb ff 8d 82 00 80 fe ff 81 fe 00 06 00 00 0f 43
c2 49 69 d5 38 0d 00 00 48 8d 71 04 c1 e8 02 4c 01 f2 48 89 b2 50 f6 02
00 <89> 01 48 8b 82 50 f6 02 00 48 8d 48 04 48 89 8a 50 f6 02 00 c7 00
[   54.072408] RSP: 0018:b17985f736f8 EFLAGS: 00010286
[   54.072793] RAX: 00d6 RBX: 99a82f68 RCX:

[   54.073315] RDX: 99a82f68 RSI: 0004 RDI:
99a82f68
[   54.073835] RBP: b17985f73730 R08: 0001 R09:

[   54.074353] R10: 0008 R11: b17983c05000 R12:

[   54.074879] R13:  R14: 99a82f68 R15:
0001
[   54.075400] FS:  7f8d9c79a000() GS:99ab2f14()
knlGS:
[   54.075988] CS:  0010 DS:  ES:  CR0: 80050033
[   54.076408] CR2:  CR3: 000140c3a000 CR4:
00750ef0
[   54.076927] PKRU: 5554
[   54.077132] Call Trace:
[   54.077319]  
[   54.077484]  ? show_regs+0x69/0x80
[   54.077747]  ? __die+0x28/0x70
[   54.077979]  ? page_fault_oops+0x180/0x4b0
[   54.078286]  ? do_user_addr_fault+0x2d2/0x680
[   54.078610]  ? exc_page_fault+0x84/0x190
[   54.078910]  ? asm_exc_page_fault+0x2b/0x30
[   54.079224]  ? vcn_v4_0_5_start_dpg_mode+0x9be/0x36b0 [amdgpu]
[   54.079941]  ? vcn_v4_0_5_start_dpg_mode+0xe6/0x36b0 [amdgpu]
[   54.080617]  vcn_v4_0_5_set_powergating_state+0x82/0x19b0 [amdgpu]
[   54.081316]  amdgpu_device_ip_set_powergating_state+0x64/0xc0
[amdgpu]
[   54.082057]  amdgpu_vcn_ring_begin_use+0x6f/0x1d0 [amdgpu]
[   54.082727]  amdgpu_ring_alloc+0x44/0x70 [amdgpu]
[   54.083351]  amdgpu_vcn_dec_sw_ring_test_ring+0x40/0x110 [amdgpu]
[   54.084054]  amdgpu_ring_test_helper+0x22/0x90 [amdgpu]
[   54.084698]  vcn_v4_0_5_hw_init+0x87/0xc0 [amdgpu]
[   54.085307]  amdgpu_device_init+0x1f96/0x2780 [amdgpu]
[   54.085951]  amdgpu_driver_load_kms+0x1e/0xc0 [amdgpu]
[   54.086591]  amdgpu_pci_probe+0x19f/0x550 [amdgpu]
[   54.087215]  local_pci_probe+0x48/0xa0
[   54.087509]  pci_device_probe+0xc9/0x250
[   54.087812]  really_probe+0x1a4/0x3f0
[   54.088101]  __driver_probe_device+0x7d/0x170
[   54.088443]  driver_probe_device+0x24/0xa0
[   54.088765]  __driver_attach+0xdd/0x1d0
[   54.089068]  ? __pfx___driver_attach+0x10/0x10
[   54.089417]  bus_for_each_dev+0x8e/0xe0
[   54.089718]  driver_attach+0x22/0x30
[   54.09]  bus_add_driver+0x120/0x220
[   54.090303]  driver_register+0x62/0x120
[   54.090606]  ? __pfx_amdgpu_init+0x10/0x10 [amdgpu]
[   54.091255]  __pci_register_driver+0x62/0x70
[   54.091593]  amdgpu_init+0x67/0xff0 [amdgpu]
[   54.092190]  do_one_initcall+0x5f/0x330
[   54.092495]  do_init_module+0x68/0x240
[   54.092794]  load_module+0x201c/0x2110
[   54.093093]  init_module_from_file+0x97/0xd0
[   54.093428]  ? init_module_from_file+0x97/0xd0
[   54.093777]  idempotent_init_module+0x11c/0x2a0
[   54.094134]  __x64_sys_finit_module+0x64/0xc0
[   54.094476]  do_syscall_64+0x58/0x120
[   54.094767]  entry_SYSCALL_64_after_hwframe+0x6e/0x76

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
index f45495de6875..8d75061f9f38 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
@@ -958,6 +958,9 @@ static int vcn_v4_0_5_start(struct amdgpu_device *adev)
amdgpu_dpm_enable_uvd(adev, true);
 
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   if (adev->vcn.harvest_config & (1 << i))
+   continue;
+
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
 
if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) {
@@ -1162,6 +1165,9 @@ static int vcn_v4_0_5_stop(struct amdgpu_device *adev)
int i, r = 0;
 
for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
+   if (adev->vcn.harvest_config & (1 << i))
+   continue;
+
fw_shared = adev->vcn.inst[i].fw_shared.cpu_addr;
fw_shared->sq.queue_mode |= FW_QUEUE_DPG_HOLD_OFF;
 
-- 
2.43.0



[PATCH] drm/amd/pm: early return if disabling DPMS for GFX IP v11.5.2

2024-07-14 Thread Tim Huang
This was intended to add support for GFX IP v11.5.2, but it needs
to be applied to all GFX11 and subsequent APUs. Therefore the code
should be revised to accommodate this.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 16 
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index d79bdb1e8cdf..06684e29db23 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1922,20 +1922,12 @@ static int smu_disable_dpms(struct smu_context *smu)
}
 
/*
-* For SMU 13.0.4/11 and 14.0.0, PMFW will handle the features 
disablement properly
+* For GFX11 and subsequent APUs, PMFW will handle the features 
disablement properly
 * for gpu reset and S0i3 cases. Driver involvement is unnecessary.
 */
-   if (amdgpu_in_reset(adev) || adev->in_s0ix) {
-   switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
-   case IP_VERSION(13, 0, 4):
-   case IP_VERSION(13, 0, 11):
-   case IP_VERSION(14, 0, 0):
-   case IP_VERSION(14, 0, 1):
-   return 0;
-   default:
-   break;
-   }
-   }
+   if (IP_VERSION_MAJ(amdgpu_ip_version(adev, GC_HWIP, 0)) >= 11 &&
+   smu->is_apu && (amdgpu_in_reset(adev) || adev->in_s0ix))
+   return 0;
 
/*
 * For gpu reset, runpm and hibernation through BACO,
-- 
2.43.0



[PATCH] drm/amd/pm: avoid to load smu firmware for APUs

2024-06-30 Thread Tim Huang
Certain call paths still load the SMU firmware for APUs,
which needs to be skipped.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 8 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 +++-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c| 2 +-
 4 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 18488c02d1cf..c55518fe542c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -7324,11 +7324,9 @@ static int gfx_v10_0_hw_init(void *handle)
 * loaded firstly, so in direct type, it has to load smc ucode
 * here before rlc.
 */
-   if (!(adev->flags & AMD_IS_APU)) {
-   r = amdgpu_pm_load_smu_firmware(adev, NULL);
-   if (r)
-   return r;
-   }
+   r = amdgpu_pm_load_smu_firmware(adev, NULL);
+   if (r)
+   return r;
gfx_v10_0_disable_gpa_mode(adev);
}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 38150398a31b..0ad35e96d2b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -4558,11 +4558,9 @@ static int gfx_v11_0_hw_init(void *handle)
 * loaded firstly, so in direct type, it has to load smc ucode
 * here before rlc.
 */
-   if (!(adev->flags & AMD_IS_APU)) {
-   r = amdgpu_pm_load_smu_firmware(adev, NULL);
-   if (r)
-   return r;
-   }
+   r = amdgpu_pm_load_smu_firmware(adev, NULL);
+   if (r)
+   return r;
}
 
gfx_v11_0_constants_init(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index ccb26f78252a..40edda2c3003 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -3306,11 +3306,9 @@ static int gfx_v12_0_hw_init(void *handle)
 * loaded firstly, so in direct type, it has to load smc ucode
 * here before rlc.
 */
-   if (!(adev->flags & AMD_IS_APU)) {
-   r = amdgpu_pm_load_smu_firmware(adev, NULL);
-   if (r)
-   return r;
-   }
+   r = amdgpu_pm_load_smu_firmware(adev, NULL);
+   if (r)
+   return r;
}
 
gfx_v12_0_constants_init(adev);
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c 
b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index b3b5e7b74c85..a1b8a82d77cf 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
@@ -618,7 +618,7 @@ int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, 
uint32_t *smu_versio
const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
int r = 0;
 
-   if (!pp_funcs || !pp_funcs->load_firmware)
+   if (!pp_funcs || !pp_funcs->load_firmware || adev->flags & AMD_IS_APU)
return 0;
 
mutex_lock(&adev->pm.mutex);
-- 
2.43.0



[PATCH 7/7] drm/amdgpu: add firmware for PSP IP v14.0.4

2024-06-30 Thread Tim Huang
This patch is to add firmware for PSP 14.0.4.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/psp_v13_0.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c 
b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
index 407477b895d1..1251ee38a676 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
@@ -57,6 +57,8 @@ MODULE_FIRMWARE("amdgpu/psp_14_0_0_toc.bin");
 MODULE_FIRMWARE("amdgpu/psp_14_0_0_ta.bin");
 MODULE_FIRMWARE("amdgpu/psp_14_0_1_toc.bin");
 MODULE_FIRMWARE("amdgpu/psp_14_0_1_ta.bin");
+MODULE_FIRMWARE("amdgpu/psp_14_0_4_toc.bin");
+MODULE_FIRMWARE("amdgpu/psp_14_0_4_ta.bin");
 
 /* For large FW files the time to complete can be very long */
 #define USBC_PD_POLLING_LIMIT_S 240
-- 
2.43.0



[PATCH 5/7] drm/amdgpu: add SMU IP v14.0.4 discovery support

2024-06-30 Thread Tim Huang
This patch is to add SMU 14.0.4 support

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 43499789b6ec..b241f61fe9c9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -2028,6 +2028,7 @@ static int amdgpu_discovery_set_smu_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(14, 0, 1):
case IP_VERSION(14, 0, 2):
case IP_VERSION(14, 0, 3):
+   case IP_VERSION(14, 0, 4):
amdgpu_device_ip_block_add(adev, &smu_v14_0_ip_block);
break;
default:
-- 
2.43.0



[PATCH 3/7] drm/amd/pm: smu v14.0.4 reuse smu v14.0.0 dpmtable

2024-06-30 Thread Tim Huang
From: Li Ma 

Replace IP VERSION with smu->is_apu in if condition.
And the dpmtable of smu v14.0.4 is same as smu v14.0.0.

Signed-off-by: Li Ma 
Reviewed-by: Yifan Zhang 
---
 .../gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c| 18 ---
 .../drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c  | 30 +--
 2 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
index 5ffd7144d99e..095ee7e2c4bb 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
@@ -136,8 +136,7 @@ int smu_v14_0_load_microcode(struct smu_context *smu)
1 & ~MP1_SMN_PUB_CTRL__LX3_RESET_MASK);
 
for (i = 0; i < adev->usec_timeout; i++) {
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 
0, 1))
+   if (smu->is_apu)
mp1_fw_flags = RREG32_PCIE(MP1_Public |
   
(smnMP1_FIRMWARE_FLAGS_14_0_0 & 0x));
else
@@ -210,8 +209,7 @@ int smu_v14_0_check_fw_status(struct smu_context *smu)
struct amdgpu_device *adev = smu->adev;
uint32_t mp1_fw_flags;
 
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 1))
+   if (smu->is_apu)
mp1_fw_flags = RREG32_PCIE(MP1_Public |
   (smnMP1_FIRMWARE_FLAGS_14_0_0 & 
0x));
else
@@ -866,8 +864,7 @@ static int smu_v14_0_set_irq_state(struct amdgpu_device 
*adev,
WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_ENA, 0);
 
/* For MP1 SW irqs */
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 
0, 1)) {
+   if (smu->is_apu) {
val = RREG32_SOC15(MP1, 0, 
regMP1_SMN_IH_SW_INT_CTRL_mp1_14_0_0);
val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT_CTRL, 
INT_MASK, 1);
WREG32_SOC15(MP1, 0, 
regMP1_SMN_IH_SW_INT_CTRL_mp1_14_0_0, val);
@@ -900,8 +897,7 @@ static int smu_v14_0_set_irq_state(struct amdgpu_device 
*adev,
WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_ENA, val);
 
/* For MP1 SW irqs */
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 
0, 1)) {
+   if (smu->is_apu) {
val = RREG32_SOC15(MP1, 0, 
regMP1_SMN_IH_SW_INT_mp1_14_0_0);
val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, ID, 0xFE);
val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, VALID, 0);
@@ -1494,8 +1490,7 @@ int smu_v14_0_set_vcn_enable(struct smu_context *smu,
if (adev->vcn.harvest_config & (1 << i))
continue;
 
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
1)) {
+   if (smu->is_apu) {
if (i == 0)
ret = smu_cmn_send_smc_msg_with_param(smu, 
enable ?
  
SMU_MSG_PowerUpVcn0 : SMU_MSG_PowerDownVcn0,
@@ -1527,8 +1522,7 @@ int smu_v14_0_set_jpeg_enable(struct smu_context *smu,
if (adev->jpeg.harvest_config & (1 << i))
continue;
 
-   if (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
0) ||
-   amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
1)) {
+   if (smu->is_apu) {
if (i == 0)
ret = smu_cmn_send_smc_msg_with_param(smu, 
enable ?
  
SMU_MSG_PowerUpJpeg0 : SMU_MSG_PowerDownJpeg0,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
index 18abfbd6d059..3a9d58c036ea 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_0_ppt.c
@@ -723,10 +723,10 @@ static int smu_v14_0_common_get_dpm_freq_by_index(struct 
smu_context *smu,
uint32_t dpm_level,
uint32_t *freq)
 {
-   if (amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 0))
-   smu_v14_0_0_get_dpm_freq_by_index(smu, clk_type, dpm_level, 
freq);
-   else if (amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(14, 0, 
1))
+   if 

[PATCH 6/7] drm/amdgpu: enable mode2 reset for SMU IP v14.0.4

2024-06-30 Thread Tim Huang
Set the default reset method to mode2 for SMU 14.0.4.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/soc21.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c 
b/drivers/gpu/drm/amd/amdgpu/soc21.c
index b43c50f1c7ad..6cc86d13f32a 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
@@ -389,6 +389,7 @@ soc21_asic_reset_method(struct amdgpu_device *adev)
case IP_VERSION(13, 0, 11):
case IP_VERSION(14, 0, 0):
case IP_VERSION(14, 0, 1):
+   case IP_VERSION(14, 0, 4):
return AMD_RESET_METHOD_MODE2;
default:
if (amdgpu_dpm_is_baco_supported(adev))
-- 
2.43.0



[PATCH 4/7] drm/amd/pm: add SMU IP v14.0.4 support

2024-06-30 Thread Tim Huang
This patch is to add SMU 14.0.4 support.

Signed-off-by: Li Ma 
Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c  | 1 +
 drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 00384b381289..d79bdb1e8cdf 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -727,6 +727,7 @@ static int smu_set_funcs(struct amdgpu_device *adev)
break;
case IP_VERSION(14, 0, 0):
case IP_VERSION(14, 0, 1):
+   case IP_VERSION(14, 0, 4):
smu_v14_0_0_set_ppt_funcs(smu);
break;
case IP_VERSION(14, 0, 2):
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
index 095ee7e2c4bb..09973615f210 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c
@@ -243,6 +243,7 @@ int smu_v14_0_check_fw_version(struct smu_context *smu)
 
switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
case IP_VERSION(14, 0, 0):
+   case IP_VERSION(14, 0, 4):
smu->smc_driver_if_version = 
SMU14_DRIVER_IF_VERSION_SMU_V14_0_0;
break;
case IP_VERSION(14, 0, 1):
@@ -757,6 +758,7 @@ int smu_v14_0_gfx_off_control(struct smu_context *smu, bool 
enable)
case IP_VERSION(14, 0, 1):
case IP_VERSION(14, 0, 2):
case IP_VERSION(14, 0, 3):
+   case IP_VERSION(14, 0, 4):
if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))
return 0;
if (enable)
-- 
2.43.0



[PATCH 2/7] drm/amdgpu: add PSP IP v14.0.4 discovery support

2024-06-30 Thread Tim Huang
This patch is to add PSP 14.0.4 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 8f5de513d951..43499789b6ec 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -1964,6 +1964,7 @@ static int amdgpu_discovery_set_psp_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(13, 0, 14):
case IP_VERSION(14, 0, 0):
case IP_VERSION(14, 0, 1):
+   case IP_VERSION(14, 0, 4):
amdgpu_device_ip_block_add(adev, &psp_v13_0_ip_block);
break;
case IP_VERSION(13, 0, 4):
-- 
2.43.0



[PATCH 1/7] drm/amdgpu: add PSP IP v14.0.4 support

2024-06-30 Thread Tim Huang
This patch is to add PSP 14.0.4 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 drivers/gpu/drm/amd/amdgpu/psp_v13_0.c  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index e15814d9ca17..800cc7a148b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -219,6 +219,7 @@ static int psp_early_init(void *handle)
case IP_VERSION(13, 0, 11):
case IP_VERSION(14, 0, 0):
case IP_VERSION(14, 0, 1):
+   case IP_VERSION(14, 0, 4):
psp_v13_0_set_psp_funcs(psp);
psp->boot_time_tmr = false;
break;
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c 
b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
index b52e15e2dcc7..407477b895d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c
@@ -106,6 +106,7 @@ static int psp_v13_0_init_microcode(struct psp_context *psp)
case IP_VERSION(13, 0, 11):
case IP_VERSION(14, 0, 0):
case IP_VERSION(14, 0, 1):
+   case IP_VERSION(14, 0, 4):
err = psp_init_toc_microcode(psp, ucode_prefix);
if (err)
return err;
-- 
2.43.0



[PATCH 2/3] drm/amdgpu: add VPE IP v6.1.3 discovery support

2024-06-30 Thread Tim Huang
This patch is to add VPE 6.1.3 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index c9dc921d6a92..8f5de513d951 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -2363,6 +2363,7 @@ static int amdgpu_discovery_set_vpe_ip_blocks(struct 
amdgpu_device *adev)
switch (amdgpu_ip_version(adev, VPE_HWIP, 0)) {
case IP_VERSION(6, 1, 0):
case IP_VERSION(6, 1, 1):
+   case IP_VERSION(6, 1, 3):
amdgpu_device_ip_block_add(adev, &vpe_v6_1_ip_block);
break;
default:
-- 
2.43.0



[PATCH 3/3] drm/amdgpu: add firmware for VPE IP v6.1.3

2024-06-30 Thread Tim Huang
This patch is to add firmware for VPE 6.1.3.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/vpe_v6_1.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/vpe_v6_1.c 
b/drivers/gpu/drm/amd/amdgpu/vpe_v6_1.c
index 09315dd5a1ec..45876883bbf3 100644
--- a/drivers/gpu/drm/amd/amdgpu/vpe_v6_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/vpe_v6_1.c
@@ -34,6 +34,7 @@
 
 MODULE_FIRMWARE("amdgpu/vpe_6_1_0.bin");
 MODULE_FIRMWARE("amdgpu/vpe_6_1_1.bin");
+MODULE_FIRMWARE("amdgpu/vpe_6_1_3.bin");
 
 #define VPE_THREAD1_UCODE_OFFSET   0x8000
 
-- 
2.43.0



[PATCH 1/3] drm/amdgpu: add VPE IP v6.1.3 support

2024-06-30 Thread Tim Huang
This patch is to add VPE 6.1.3 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
index bad232859972..5acd20ff5979 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vpe.c
@@ -302,6 +302,7 @@ static int vpe_early_init(void *handle)
 
switch (amdgpu_ip_version(adev, VPE_HWIP, 0)) {
case IP_VERSION(6, 1, 0):
+   case IP_VERSION(6, 1, 3):
vpe_v6_1_set_funcs(vpe);
break;
case IP_VERSION(6, 1, 1):
-- 
2.43.0



[PATCH 1/2] drm/amdgpu: add NBIO IP v7.11.3 discovery support

2024-06-30 Thread Tim Huang
This patch is to add NBIO 7.11.3 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index b1ee5bafa493..c9dc921d6a92 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -2701,6 +2701,7 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device 
*adev)
break;
case IP_VERSION(7, 11, 0):
case IP_VERSION(7, 11, 1):
+   case IP_VERSION(7, 11, 3):
adev->nbio.funcs = &nbio_v7_11_funcs;
adev->nbio.hdp_flush_reg = &nbio_v7_11_hdp_flush_reg;
break;
-- 
2.43.0



[PATCH 2/2] drm/amdgpu: Add NBIO IP v7.11.3 support

2024-06-30 Thread Tim Huang
Enable setting soc21 common clockgating for NBIO 7.11.3.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/soc21.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c 
b/drivers/gpu/drm/amd/amdgpu/soc21.c
index b04c763015d3..b43c50f1c7ad 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
@@ -953,6 +953,7 @@ static int soc21_common_set_clockgating_state(void *handle,
case IP_VERSION(7, 7, 1):
case IP_VERSION(7, 11, 0):
case IP_VERSION(7, 11, 1):
+   case IP_VERSION(7, 11, 3):
adev->nbio.funcs->update_medium_grain_clock_gating(adev,
state == AMD_CG_STATE_GATE);
adev->nbio.funcs->update_medium_grain_light_sleep(adev,
-- 
2.43.0



[PATCH 3/3] drm/amdgpu: add firmware for SDMA IP v6.1.2

2024-06-30 Thread Tim Huang
This patch is to add firmware for SDMA 6.1.2.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c 
b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
index c833b6b8373b..dab4c2db8c9d 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c
@@ -50,6 +50,7 @@ MODULE_FIRMWARE("amdgpu/sdma_6_0_2.bin");
 MODULE_FIRMWARE("amdgpu/sdma_6_0_3.bin");
 MODULE_FIRMWARE("amdgpu/sdma_6_1_0.bin");
 MODULE_FIRMWARE("amdgpu/sdma_6_1_1.bin");
+MODULE_FIRMWARE("amdgpu/sdma_6_1_2.bin");
 
 #define SDMA1_REG_OFFSET 0x600
 #define SDMA0_HYP_DEC_REG_START 0x5880
-- 
2.43.0



[PATCH 2/3] drm/amdkfd: add KFD support for SDMA IP v6.1.2

2024-06-30 Thread Tim Huang
Enable KFD setting SDMA info for SDMA 6.1.2.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index e6debd63a116..f4d20adaa068 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -99,6 +99,7 @@ static void kfd_device_info_set_sdma_info(struct kfd_dev *kfd)
case IP_VERSION(6, 0, 3):
case IP_VERSION(6, 1, 0):
case IP_VERSION(6, 1, 1):
+   case IP_VERSION(6, 1, 2):
case IP_VERSION(7, 0, 0):
case IP_VERSION(7, 0, 1):
kfd->device_info.num_sdma_queues_per_engine = 8;
@@ -119,6 +120,7 @@ static void kfd_device_info_set_sdma_info(struct kfd_dev 
*kfd)
case IP_VERSION(6, 0, 3):
case IP_VERSION(6, 1, 0):
case IP_VERSION(6, 1, 1):
+   case IP_VERSION(6, 1, 2):
case IP_VERSION(7, 0, 0):
case IP_VERSION(7, 0, 1):
/* Reserve 1 for paging and 1 for gfx */
-- 
2.43.0



[PATCH 1/3] drm/amdgpu: add SDMA IP v6.1.2 discovery support

2024-06-30 Thread Tim Huang
This patch is to add SDMA 6.1.2 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 39f29de6ed36..b1ee5bafa493 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -2208,6 +2208,7 @@ static int amdgpu_discovery_set_sdma_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(6, 0, 3):
case IP_VERSION(6, 1, 0):
case IP_VERSION(6, 1, 1):
+   case IP_VERSION(6, 1, 2):
amdgpu_device_ip_block_add(adev, &sdma_v6_0_ip_block);
break;
case IP_VERSION(7, 0, 0):
-- 
2.43.0



[PATCH 7/7] drm/amdgpu: add firmware for GC IP v11.5.2

2024-06-30 Thread Tim Huang
This patch is to add firmware for GC 11.5.2.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 4 
 drivers/gpu/drm/amd/amdgpu/imu_v11_0.c | 1 +
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 ++
 3 files changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 9acdabd7719a..38150398a31b 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -93,6 +93,10 @@ MODULE_FIRMWARE("amdgpu/gc_11_5_1_pfp.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_me.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_mec.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_rlc.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_pfp.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_me.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_mec.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_rlc.bin");
 
 static const struct amdgpu_hwip_reg_entry gc_reg_list_11_0[] = {
SOC15_REG_ENTRY_STR(GC, 0, regGRBM_STATUS),
diff --git a/drivers/gpu/drm/amd/amdgpu/imu_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/imu_v11_0.c
index a9f5d9e4610d..6c1891889c4d 100644
--- a/drivers/gpu/drm/amd/amdgpu/imu_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/imu_v11_0.c
@@ -38,6 +38,7 @@ MODULE_FIRMWARE("amdgpu/gc_11_0_3_imu.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_0_4_imu.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_0_imu.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_imu.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_imu.bin");
 
 static int imu_v11_0_init_microcode(struct amdgpu_device *adev)
 {
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index 3b1f6ad99100..1376b6ff1b77 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -51,6 +51,8 @@ MODULE_FIRMWARE("amdgpu/gc_11_5_0_mes_2.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_0_mes1.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_mes_2.bin");
 MODULE_FIRMWARE("amdgpu/gc_11_5_1_mes1.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_mes_2.bin");
+MODULE_FIRMWARE("amdgpu/gc_11_5_2_mes1.bin");
 
 static int mes_v11_0_hw_init(void *handle);
 static int mes_v11_0_hw_fini(void *handle);
-- 
2.43.0



[PATCH 5/7] drm/amdgpu: add GC IP v11.5.2 to GC 11.5.0 family

2024-06-30 Thread Tim Huang
This patch is to add GC 11.5.2 to GC 11.5.0 family.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
Reviewed-by: Veerabadhran Gopalakrishnan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index df753ebfd109..39f29de6ed36 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -1808,6 +1808,7 @@ static int amdgpu_discovery_set_common_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
amdgpu_device_ip_block_add(adev, &soc21_common_ip_block);
break;
case IP_VERSION(12, 0, 0):
@@ -1861,6 +1862,7 @@ static int amdgpu_discovery_set_gmc_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
amdgpu_device_ip_block_add(adev, &gmc_v11_0_ip_block);
break;
case IP_VERSION(12, 0, 0):
@@ -2152,6 +2154,7 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
amdgpu_device_ip_block_add(adev, &gfx_v11_0_ip_block);
break;
case IP_VERSION(12, 0, 0):
@@ -2323,6 +2326,7 @@ static int amdgpu_discovery_set_mes_ip_blocks(struct 
amdgpu_device *adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
amdgpu_device_ip_block_add(adev, &mes_v11_0_ip_block);
adev->enable_mes = true;
adev->enable_mes_kiq = true;
@@ -2632,6 +2636,7 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device 
*adev)
break;
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
adev->family = AMDGPU_FAMILY_GC_11_5_0;
break;
case IP_VERSION(12, 0, 0):
@@ -2656,6 +2661,7 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device 
*adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
adev->flags |= AMD_IS_APU;
break;
default:
-- 
2.43.0



[PATCH 6/7] drm/amdkfd: add KFD support for GC IP v11.5.2

2024-06-30 Thread Tim Huang
Enable KFD for GC 11.5.2.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c   | 1 +
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 5 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index ead43386a7ef..cd7b81b7b939 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -1678,6 +1678,7 @@ int kfd_get_gpu_cache_info(struct kfd_node *kdev, struct 
kfd_gpu_cache_info **pc
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
case IP_VERSION(12, 0, 0):
case IP_VERSION(12, 0, 1):
num_of_cache_types =
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 6040ee7918bf..e6debd63a116 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -175,6 +175,7 @@ static void 
kfd_device_info_set_event_interrupt_class(struct kfd_dev *kfd)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
kfd->device_info.event_interrupt_class = 
&event_interrupt_class_v11;
break;
case IP_VERSION(12, 0, 0):
@@ -438,6 +439,10 @@ struct kfd_dev *kgd2kfd_probe(struct amdgpu_device *adev, 
bool vf)
gfx_target_version = 110501;
f2g = &gfx_v11_kfd2kgd;
break;
+   case IP_VERSION(11, 5, 2):
+   gfx_target_version = 110502;
+   f2g = &gfx_v11_kfd2kgd;
+   break;
case IP_VERSION(12, 0, 0):
gfx_target_version = 12;
f2g = &gfx_v12_kfd2kgd;
-- 
2.43.0



[PATCH 3/7] drm/amdgpu: add tmz support for GC IP v11.5.2

2024-06-30 Thread Tim Huang
Add tmz support for GC 11.5.2.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 3a7622611916..c02659025656 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -848,6 +848,7 @@ void amdgpu_gmc_tmz_set(struct amdgpu_device *adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
/* Don't enable it by default yet.
 */
if (amdgpu_tmz < 1) {
-- 
2.43.0



[PATCH 4/7] drm/amdgpu: add GC IP v11.5.2 soc21 support

2024-06-30 Thread Tim Huang
Add CG and PG flags for GFX IP v11.5.2 and
PG flags for VCN IP v4.0.5.

Signed-off-by: Saleemkhan Jamadar 
Signed-off-by: Li Ma 
Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
Reviewed-by: Veerabadhran Gopalakrishnan 
---
 drivers/gpu/drm/amd/amdgpu/soc21.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c 
b/drivers/gpu/drm/amd/amdgpu/soc21.c
index 15845ecca7c7..b04c763015d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
@@ -752,6 +752,32 @@ static int soc21_common_early_init(void *handle)
AMD_PG_SUPPORT_JPEG;
adev->external_rev_id = adev->rev_id + 0xc1;
break;
+   case IP_VERSION(11, 5, 2):
+   adev->cg_flags = AMD_CG_SUPPORT_VCN_MGCG |
+   AMD_CG_SUPPORT_JPEG_MGCG |
+   AMD_CG_SUPPORT_GFX_CGCG |
+   AMD_CG_SUPPORT_GFX_CGLS |
+   AMD_CG_SUPPORT_GFX_MGCG |
+   AMD_CG_SUPPORT_GFX_FGCG |
+   AMD_CG_SUPPORT_REPEATER_FGCG |
+   AMD_CG_SUPPORT_GFX_PERF_CLK |
+   AMD_CG_SUPPORT_GFX_3D_CGCG |
+   AMD_CG_SUPPORT_GFX_3D_CGLS  |
+   AMD_CG_SUPPORT_MC_MGCG |
+   AMD_CG_SUPPORT_MC_LS |
+   AMD_CG_SUPPORT_HDP_LS |
+   AMD_CG_SUPPORT_HDP_DS |
+   AMD_CG_SUPPORT_HDP_SD |
+   AMD_CG_SUPPORT_ATHUB_MGCG |
+   AMD_CG_SUPPORT_ATHUB_LS |
+   AMD_CG_SUPPORT_IH_CG |
+   AMD_CG_SUPPORT_BIF_MGCG |
+   AMD_CG_SUPPORT_BIF_LS;
+   adev->pg_flags = AMD_PG_SUPPORT_VCN |
+   AMD_PG_SUPPORT_JPEG |
+   AMD_PG_SUPPORT_GFX_PG;
+   adev->external_rev_id = adev->rev_id + 0x40;
+   break;
default:
/* FIXME: not supported yet */
return -EINVAL;
-- 
2.43.0



[PATCH 2/7] drm/amdgpu: add GFXHUB IP v11.5.2 support

2024-06-30 Thread Tim Huang
This patch is to add GFXHUB 11.5.2 support.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
index cad883783834..b88a6fa173b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c
@@ -592,6 +592,7 @@ static void gmc_v11_0_set_gfxhub_funcs(struct amdgpu_device 
*adev)
break;
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
adev->gfxhub.funcs = &gfxhub_v11_5_0_funcs;
break;
default:
@@ -754,6 +755,7 @@ static int gmc_v11_0_sw_init(void *handle)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
set_bit(AMDGPU_GFXHUB(0), adev->vmhubs_mask);
set_bit(AMDGPU_MMHUB0(0), adev->vmhubs_mask);
/*
-- 
2.43.0



[PATCH 1/7] drm/amdgpu: initialize GC IP v11.5.2

2024-06-30 Thread Tim Huang
Initialize GC 11.5.2 and set gfx hw configuration.

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 0d078d0db162..9acdabd7719a 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -1054,6 +1054,7 @@ static int gfx_v11_0_gpu_early_init(struct amdgpu_device 
*adev)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
adev->gfx.config.max_hw_contexts = 8;
adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
@@ -1534,6 +1535,7 @@ static int gfx_v11_0_sw_init(void *handle)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
adev->gfx.me.num_me = 1;
adev->gfx.me.num_pipe_per_me = 1;
adev->gfx.me.num_queue_per_pipe = 1;
@@ -2782,7 +2784,8 @@ static int 
gfx_v11_0_wait_for_rlc_autoload_complete(struct amdgpu_device *adev)
amdgpu_ip_version(adev, GC_HWIP, 0) ==
IP_VERSION(11, 0, 4) ||
amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 0) 
||
-   amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 1))
+   amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 1) 
||
+   amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(11, 5, 2))
bootload_status = RREG32_SOC15(GC, 0,
regRLC_RLCS_BOOTLOAD_STATUS_gc_11_0_1);
else
@@ -5296,6 +5299,7 @@ static void gfx_v11_cntl_power_gating(struct 
amdgpu_device *adev, bool enable)
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
WREG32_SOC15(GC, 0, regRLC_PG_DELAY_3, 
RLC_PG_DELAY_3_DEFAULT_GC_11_0_1);
break;
default:
@@ -5332,6 +5336,7 @@ static int gfx_v11_0_set_powergating_state(void *handle,
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
if (!enable)
amdgpu_gfx_off_ctrl(adev, false);
 
@@ -5364,6 +5369,7 @@ static int gfx_v11_0_set_clockgating_state(void *handle,
case IP_VERSION(11, 0, 4):
case IP_VERSION(11, 5, 0):
case IP_VERSION(11, 5, 1):
+   case IP_VERSION(11, 5, 2):
gfx_v11_0_update_gfx_clock_gating(adev,
state ==  AMD_CG_STATE_GATE);
break;
-- 
2.43.0



[PATCH 2/2] drm/amdgpu: fix mc_data out-of-bounds read warning

2024-05-06 Thread Tim Huang
Clear warning that read mc_data[i-1] may out-of-bounds.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
index 52b12c1718eb..7dc102f0bc1d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
@@ -1484,6 +1484,8 @@ int amdgpu_atombios_init_mc_reg_table(struct 
amdgpu_device *adev,

(u32)le32_to_cpu(*((u32 *)reg_data + j));
j++;
} else if 
((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == 
DATA_EQU_PREV) {
+   if (i 
== 0)
+   
continue;

reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =

reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
}
-- 
2.39.2



[PATCH 1/2] drm/amdgpu: fix ucode out-of-bounds read warning

2024-05-06 Thread Tim Huang
Clear warning that read ucode[] may out-of-bounds.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index b8280be6225d..c3d89088123d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -213,6 +213,9 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device 
*cgs_device,
struct amdgpu_firmware_info *ucode;
 
id = fw_type_convert(cgs_device, type);
+   if (id >= AMDGPU_UCODE_ID_MAXIMUM)
+   return -EINVAL;
+
ucode = &adev->firmware.ucode[id];
if (ucode->fw == NULL)
return -EINVAL;
-- 
2.39.2



[PATCH 3/3] drm/amdgpu: fix uninitialized variable warning for jpeg_v4

2024-05-05 Thread Tim Huang
Clear warning that using uninitialized variable r.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c 
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
index da6bb9022b80..4c8f9772437b 100644
--- a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
@@ -187,7 +187,7 @@ static int jpeg_v4_0_5_hw_init(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct amdgpu_ring *ring;
-   int r, i;
+   int i, r = 0;
 
// TODO: Enable ring test with DPG support
if (adev->pg_flags & AMD_PG_SUPPORT_JPEG_DPG) {
-- 
2.39.2



[PATCH 2/3] drm/amdgpu: fix uninitialized variable warning for amdgpu_xgmi

2024-05-05 Thread Tim Huang
Clear warning that using uninitialized variable current_node.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
index dd2ec48cf5c2..4a14f9c1bfe8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
@@ -434,6 +434,9 @@ static ssize_t amdgpu_xgmi_show_connected_port_num(struct 
device *dev,
}
}
 
+   if (i == top->num_nodes)
+   return -EINVAL;
+
for (i = 0; i < top->num_nodes; i++) {
for (j = 0; j < top->nodes[i].num_links; j++)
/* node id in sysfs starts from 1 rather than 0 so +1 
here */
-- 
2.39.2



[PATCH 1/3] drm/amdgpu: fix uninitialized variable warning for sdma_v7

2024-05-05 Thread Tim Huang
Clear warning that using uninitialized variable index.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
index 35d99a4afe83..0b5af1c50461 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c
@@ -876,7 +876,8 @@ static int sdma_v7_0_ring_test_ring(struct amdgpu_ring 
*ring)
r = amdgpu_ring_alloc(ring, 5);
if (r) {
DRM_ERROR("amdgpu: dma failed to lock ring %d (%d).\n", 
ring->idx, r);
-   amdgpu_device_wb_free(adev, index);
+   if (!ring->is_mes_queue)
+   amdgpu_device_wb_free(adev, index);
return r;
}
 
-- 
2.39.2



[PATCH] drm/amd/pm: fix uninitialized variable warning for smu_v13

2024-04-29 Thread Tim Huang
Clear warning that using uninitialized variable when the dpm is
not enabled and reuse the code for SMU13 to get the boot frequency.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  |  4 ++
 .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c| 55 +--
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c  | 28 +-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c  | 28 +-
 .../drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c  | 28 +-
 5 files changed, 51 insertions(+), 92 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
index d9700a3f28d2..e58220a7ee2f 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
@@ -298,5 +298,9 @@ int smu_v13_0_enable_uclk_shadow(struct smu_context *smu, 
bool enable);
 
 int smu_v13_0_set_wbrf_exclusion_ranges(struct smu_context *smu,
 struct freq_band_range 
*exclusion_ranges);
+
+int smu_v13_0_get_boot_freq_by_index(struct smu_context *smu,
+enum smu_clk_type clk_type,
+uint32_t *value);
 #endif
 #endif
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
index a8d34adc7d3f..ed5a7a83c9e2 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
@@ -1559,22 +1559,9 @@ int smu_v13_0_get_dpm_ultimate_freq(struct smu_context 
*smu, enum smu_clk_type c
uint32_t clock_limit;
 
if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type)) {
-   switch (clk_type) {
-   case SMU_MCLK:
-   case SMU_UCLK:
-   clock_limit = smu->smu_table.boot_values.uclk;
-   break;
-   case SMU_GFXCLK:
-   case SMU_SCLK:
-   clock_limit = smu->smu_table.boot_values.gfxclk;
-   break;
-   case SMU_SOCCLK:
-   clock_limit = smu->smu_table.boot_values.socclk;
-   break;
-   default:
-   clock_limit = 0;
-   break;
-   }
+   ret = smu_v13_0_get_boot_freq_by_index(smu, clk_type, 
&clock_limit);
+   if (ret)
+   return ret;
 
/* clock in Mhz unit */
if (min)
@@ -1894,6 +1881,40 @@ int smu_v13_0_set_power_source(struct smu_context *smu,
   NULL);
 }
 
+int smu_v13_0_get_boot_freq_by_index(struct smu_context *smu,
+enum smu_clk_type clk_type,
+uint32_t *value)
+{
+   int ret = 0;
+
+   switch (clk_type) {
+   case SMU_MCLK:
+   case SMU_UCLK:
+   *value = smu->smu_table.boot_values.uclk;
+   break;
+   case SMU_FCLK:
+   *value = smu->smu_table.boot_values.fclk;
+   break;
+   case SMU_GFXCLK:
+   case SMU_SCLK:
+   *value = smu->smu_table.boot_values.gfxclk;
+   break;
+   case SMU_SOCCLK:
+   *value = smu->smu_table.boot_values.socclk;
+   break;
+   case SMU_VCLK:
+   *value = smu->smu_table.boot_values.vclk;
+   break;
+   case SMU_DCLK:
+   *value = smu->smu_table.boot_values.dclk;
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+   return ret;
+}
+
 int smu_v13_0_get_dpm_freq_by_index(struct smu_context *smu,
enum smu_clk_type clk_type, uint16_t level,
uint32_t *value)
@@ -1905,7 +1926,7 @@ int smu_v13_0_get_dpm_freq_by_index(struct smu_context 
*smu,
return -EINVAL;
 
if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
-   return 0;
+   return smu_v13_0_get_boot_freq_by_index(smu, clk_type, value);
 
clk_id = smu_cmn_to_asic_specific_index(smu,
CMN2ASIC_MAPPING_CLK,
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 88f1a0d878f3..e283b282ec27 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -756,31 +756,9 @@ static int smu_v13_0_4_get_dpm_ultimate_freq(struct 
smu_context *smu,
int ret = 0;
 
if (!smu_v13_0_4_clk_dpm_is_enabled(smu, clk_type)) {
-   switch (clk_type) {
-   case SMU_MCLK:
-   case SMU_UCLK:
-   clock_limit = smu->smu_table.boot_values.uclk;
-   br

[PATCH 2/2] drm/amd/pm: fix uninitialized variable warnings for vangogh_ppt

2024-04-28 Thread Tim Huang
1. Fix a issue that using uninitialized mask to get the ultimate frequency.
2. Check return of smu_cmn_send_smc_msg_with_param to avoid using
uninitialized variable residency.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
index 29295941aca9..b40cb4e255e9 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
@@ -976,6 +976,18 @@ static int vangogh_get_dpm_ultimate_freq(struct 
smu_context *smu,
}
}
if (min) {
+   ret = vangogh_get_profiling_clk_mask(smu,
+
AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK,
+NULL,
+NULL,
+&mclk_mask,
+&fclk_mask,
+&soc_mask);
+   if (ret)
+   goto failed;
+
+   vclk_mask = dclk_mask = 0;
+
switch (clk_type) {
case SMU_UCLK:
case SMU_MCLK:
@@ -2450,6 +2462,8 @@ static u32 vangogh_set_gfxoff_residency(struct 
smu_context *smu, bool start)
 
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_LogGfxOffResidency,
  start, &residency);
+   if (ret)
+   return ret;
 
if (!start)
adev->gfx.gfx_off_residency = residency;
-- 
2.39.2



[PATCH 1/2] drm/amd/pm: fix uninitialized variable warnings for vega10_hwmgr

2024-04-28 Thread Tim Huang
Clear warnings that using uninitialized variable when fails
to get the valid value from SMU.

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c | 46 ++-
 .../amd/pm/powerplay/smumgr/vega10_smumgr.c   |  6 ++-
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
index 9f5bd998c6bf..488ad9de4694 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c
@@ -354,13 +354,13 @@ static int vega10_odn_initial_default_setting(struct 
pp_hwmgr *hwmgr)
return 0;
 }
 
-static void vega10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
+static int vega10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
 {
struct vega10_hwmgr *data = hwmgr->backend;
-   int i;
uint32_t sub_vendor_id, hw_revision;
uint32_t top32, bottom32;
struct amdgpu_device *adev = hwmgr->adev;
+   int ret, i;
 
vega10_initialize_power_tune_defaults(hwmgr);
 
@@ -485,9 +485,12 @@ static void vega10_init_dpm_defaults(struct pp_hwmgr 
*hwmgr)
if (data->registry_data.vr0hot_enabled)
data->smu_features[GNLD_VR0HOT].supported = true;
 
-   smum_send_msg_to_smc(hwmgr,
+   ret = smum_send_msg_to_smc(hwmgr,
PPSMC_MSG_GetSmuVersion,
&hwmgr->smu_version);
+   if (ret)
+   return ret;
+
/* ACG firmware has major version 5 */
if ((hwmgr->smu_version & 0xff00) == 0x500)
data->smu_features[GNLD_ACG].supported = true;
@@ -505,10 +508,16 @@ static void vega10_init_dpm_defaults(struct pp_hwmgr 
*hwmgr)
data->smu_features[GNLD_PCC_LIMIT].supported = true;
 
/* Get the SN to turn into a Unique ID */
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32, &top32);
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32, &bottom32);
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32, &top32);
+   if (ret)
+   return ret;
+
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32, 
&bottom32);
+   if (ret)
+   return ret;
 
adev->unique_id = ((uint64_t)bottom32 << 32) | top32;
+   return 0;
 }
 
 #ifdef PPLIB_VEGA10_EVV_SUPPORT
@@ -882,7 +891,9 @@ static int vega10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
 
vega10_set_features_platform_caps(hwmgr);
 
-   vega10_init_dpm_defaults(hwmgr);
+   result = vega10_init_dpm_defaults(hwmgr);
+   if (result)
+   return result;
 
 #ifdef PPLIB_VEGA10_EVV_SUPPORT
/* Get leakage voltage based on leakage ID. */
@@ -3900,11 +3911,14 @@ static int vega10_get_gpu_power(struct pp_hwmgr *hwmgr,
uint32_t *query)
 {
uint32_t value;
+   int ret;
 
if (!query)
return -EINVAL;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrPkgPwr, &value);
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrPkgPwr, &value);
+   if (ret)
+   return ret;
 
/* SMC returning actual watts, keep consistent with legacy asics, low 8 
bit as 8 fractional bits */
*query = value << 8;
@@ -4800,14 +4814,16 @@ static int vega10_print_clock_levels(struct pp_hwmgr 
*hwmgr,
uint32_t gen_speed, lane_width, current_gen_speed, current_lane_width;
PPTable_t *pptable = &(data->smc_state_table.pp_table);
 
-   int i, now, size = 0, count = 0;
+   int i, ret, now,  size = 0, count = 0;
 
switch (type) {
case PP_SCLK:
if (data->registry_data.sclk_dpm_key_disabled)
break;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentGfxclkIndex, 
&now);
+   ret = smum_send_msg_to_smc(hwmgr, 
PPSMC_MSG_GetCurrentGfxclkIndex, &now);
+   if (ret)
+   break;
 
if (hwmgr->pp_one_vf &&
(hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK))
@@ -4823,7 +4839,9 @@ static int vega10_print_clock_levels(struct pp_hwmgr 
*hwmgr,
if (data->registry_data.mclk_dpm_key_disabled)
break;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentUclkIndex, 
&now);
+   ret = smum_send_msg_to_smc(hwmgr, 
PPSMC_MSG_GetCurrentUclkIndex, &now);
+   if (ret)
+   break;
 
for (i = 0; i < mclk_table->count; i++)
size += sprintf(buf + size, "%d: %uMhz %s\n",
@@ -4834,7 +4852,9 @@ static int vega10_print_clock_levels(struct pp_hwmgr 
*hwmgr,
if (data->registry_data.socclk_dpm_key_disabled)

[PATCH] drm/amd/pm: fix uninitialized variable warning for smu8_hwmgr

2024-04-26 Thread Tim Huang
Clear warnings that using uninitialized value level when fails
to get the value from SMU.

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c| 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c 
b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c
index b015a601b385..4e4146ce71c1 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c
@@ -584,6 +584,7 @@ static int smu8_init_uvd_limit(struct pp_hwmgr *hwmgr)

hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
unsigned long clock = 0;
uint32_t level;
+   int ret;
 
if (NULL == table || table->count <= 0)
return -EINVAL;
@@ -591,7 +592,10 @@ static int smu8_init_uvd_limit(struct pp_hwmgr *hwmgr)
data->uvd_dpm.soft_min_clk = 0;
data->uvd_dpm.hard_min_clk = 0;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxUvdLevel, &level);
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxUvdLevel, &level);
+
+   if (ret)
+   return ret;
 
if (level < table->count)
clock = table->entries[level].vclk;
@@ -611,6 +615,7 @@ static int smu8_init_vce_limit(struct pp_hwmgr *hwmgr)

hwmgr->dyn_state.vce_clock_voltage_dependency_table;
unsigned long clock = 0;
uint32_t level;
+   int ret;
 
if (NULL == table || table->count <= 0)
return -EINVAL;
@@ -618,7 +623,10 @@ static int smu8_init_vce_limit(struct pp_hwmgr *hwmgr)
data->vce_dpm.soft_min_clk = 0;
data->vce_dpm.hard_min_clk = 0;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxEclkLevel, &level);
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxEclkLevel, &level);
+
+   if (ret)
+   return ret;
 
if (level < table->count)
clock = table->entries[level].ecclk;
@@ -638,6 +646,7 @@ static int smu8_init_acp_limit(struct pp_hwmgr *hwmgr)

hwmgr->dyn_state.acp_clock_voltage_dependency_table;
unsigned long clock = 0;
uint32_t level;
+   int ret;
 
if (NULL == table || table->count <= 0)
return -EINVAL;
@@ -645,7 +654,10 @@ static int smu8_init_acp_limit(struct pp_hwmgr *hwmgr)
data->acp_dpm.soft_min_clk = 0;
data->acp_dpm.hard_min_clk = 0;
 
-   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxAclkLevel, &level);
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxAclkLevel, &level);
+
+   if (ret)
+   return ret;
 
if (level < table->count)
clock = table->entries[level].acpclk;
-- 
2.39.2



[PATCH] drm/amdgpu: fix uninitialized scalar variable warning

2024-04-25 Thread Tim Huang
Clear warning that field bp is uninitialized when
calling amdgpu_virt_ras_add_bps.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 54ab51a4ada7..a2f15edfe812 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -395,6 +395,8 @@ static void amdgpu_virt_add_bad_page(struct amdgpu_device 
*adev,
else
vram_usage_va = adev->mman.drv_vram_usage_va;
 
+   memset(&bp, 0, sizeof(struct eeprom_table_record));
+
if (bp_block_size) {
bp_cnt = bp_block_size / sizeof(uint64_t);
for (bp_idx = 0; bp_idx < bp_cnt; bp_idx++) {
-- 
2.39.2



[PATCH] drm/amdgpu: fix overflowed array index read warning

2024-04-25 Thread Tim Huang
Clear overflowed array index read warning by cast operation.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 06f0a6534a94..15c240656470 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -473,8 +473,9 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, 
char __user *buf,
size_t size, loff_t *pos)
 {
struct amdgpu_ring *ring = file_inode(f)->i_private;
-   int r, i;
uint32_t value, result, early[3];
+   loff_t i;
+   int r;
 
if (*pos & 3 || size & 3)
return -EINVAL;
-- 
2.39.2



[PATCH v2] drm/amdgpu: fix overflowed array index read warning

2024-04-25 Thread Tim Huang
From: Tim Huang 

Clear warning that cast operation might have overflowed.

v2: keep reverse xmas tree order to declare "int r;" (Christian)

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 06f0a6534a94..8cf60acb2970 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -473,8 +473,8 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, 
char __user *buf,
size_t size, loff_t *pos)
 {
struct amdgpu_ring *ring = file_inode(f)->i_private;
-   int r, i;
uint32_t value, result, early[3];
+   int r;
 
if (*pos & 3 || size & 3)
return -EINVAL;
@@ -485,7 +485,7 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, 
char __user *buf,
early[0] = amdgpu_ring_get_rptr(ring) & ring->buf_mask;
early[1] = amdgpu_ring_get_wptr(ring) & ring->buf_mask;
early[2] = ring->wptr & ring->buf_mask;
-   for (i = *pos / 4; i < 3 && size; i++) {
+   for (loff_t i = *pos / 4; i < 3 && size; i++) {
r = put_user(early[i], (uint32_t *)buf);
if (r)
return r;
-- 
2.39.2



[PATCH] drm/amdgpu: fix overflowed array index read warning

2024-04-24 Thread Tim Huang
From: Tim Huang 

Clear warning that cast operation might have overflowed.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 06f0a6534a94..6dfcd62e83ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -473,7 +473,7 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, 
char __user *buf,
size_t size, loff_t *pos)
 {
struct amdgpu_ring *ring = file_inode(f)->i_private;
-   int r, i;
+   int r;
uint32_t value, result, early[3];
 
if (*pos & 3 || size & 3)
@@ -485,7 +485,7 @@ static ssize_t amdgpu_debugfs_ring_read(struct file *f, 
char __user *buf,
early[0] = amdgpu_ring_get_rptr(ring) & ring->buf_mask;
early[1] = amdgpu_ring_get_wptr(ring) & ring->buf_mask;
early[2] = ring->wptr & ring->buf_mask;
-   for (i = *pos / 4; i < 3 && size; i++) {
+   for (loff_t i = *pos / 4; i < 3 && size; i++) {
r = put_user(early[i], (uint32_t *)buf);
if (r)
return r;
-- 
2.39.2



[PATCH] drm/amdgpu: fix potential resource leak warning

2024-04-24 Thread Tim Huang
From: Tim Huang 

Clear resource leak warning that when the prepare fails,
the allocated amdgpu job object will never be released.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index 66e8a016126b..9b748d7058b5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -102,6 +102,11 @@ static int amdgpu_vm_sdma_prepare(struct 
amdgpu_vm_update_params *p,
if (!r)
r = amdgpu_sync_push_to_job(&sync, p->job);
amdgpu_sync_free(&sync);
+
+   if (r) {
+   p->num_dw_left = 0;
+   amdgpu_job_free(p->job);
+   }
return r;
 }
 
-- 
2.39.2



[PATCH v3] drm/amdgpu: fix uninitialized scalar variable warning

2024-04-23 Thread Tim Huang
From: Tim Huang 

Clear warning that uses uninitialized value fw_size.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index d9dc5485..fb5de23fa8d8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -1205,7 +1205,8 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device 
*adev,
fw_size = le32_to_cpu(cp_hdr_v2_0->data_size_bytes);
break;
default:
-   break;
+   dev_err(adev->dev, "Invalid ucode id %u\n", ucode_id);
+   return;
}
 
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-- 
2.39.2



[PATCH v2] drm/amdgpu: fix uninitialized scalar variable warning

2024-04-23 Thread Tim Huang
From: Tim Huang 

Clear warning that uses uninitialized value fw_size.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index d9dc5485..8d5cdbb99d8d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device 
*adev,
const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;
struct amdgpu_firmware_info *info = NULL;
const struct firmware *ucode_fw;
-   unsigned int fw_size;
+   unsigned int fw_size = 0;
 
switch (ucode_id) {
case AMDGPU_UCODE_ID_CP_PFP:
@@ -1205,7 +1205,8 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device 
*adev,
fw_size = le32_to_cpu(cp_hdr_v2_0->data_size_bytes);
break;
default:
-   break;
+   dev_err(adev->dev, "Invalid ucode id %u\n", ucode_id);
+   return;
}
 
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-- 
2.39.2



[PATCH] drm/amdgpu: fix uninitialized scalar variable warning

2024-04-22 Thread Tim Huang
Clear warning that uses uninitialized value fw_size.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index d9dc5485..6b8a58f501d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -1084,7 +1084,7 @@ void amdgpu_gfx_cp_init_microcode(struct amdgpu_device 
*adev,
const struct gfx_firmware_header_v2_0 *cp_hdr_v2_0;
struct amdgpu_firmware_info *info = NULL;
const struct firmware *ucode_fw;
-   unsigned int fw_size;
+   unsigned int fw_size = 0;
 
switch (ucode_id) {
case AMDGPU_UCODE_ID_CP_PFP:
-- 
2.39.2



[PATCH] drm/amdgpu: fix incorrect number of active RBs for gfx11

2024-04-03 Thread Tim Huang
From: Tim Huang 

The RB bitmap should be global active RB bitmap &
active RB bitmap based on active SA.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 7a906318e451..07cdeef9d44a 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -1635,7 +1635,7 @@ static void gfx_v11_0_setup_rb(struct amdgpu_device *adev)
active_rb_bitmap |= (0x3 << (i * 
rb_bitmap_width_per_sa));
}
 
-   active_rb_bitmap |= global_active_rb_bitmap;
+   active_rb_bitmap &= global_active_rb_bitmap;
adev->gfx.config.backend_enable_mask = active_rb_bitmap;
adev->gfx.config.num_rbs = hweight32(active_rb_bitmap);
 }
-- 
2.39.2



[PATCH] drm/amd/pm: fixes a random hang in S4 for SMU v13.0.4/11

2024-03-27 Thread Tim Huang
From: Tim Huang 

While doing multiple S4 stress tests, GC/RLC/PMFW get into
an invalid state resulting into hard hangs.

Adding a GFX reset as workaround just before sending the
MP1_UNLOAD message avoids this failure.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index e8119918ef6b..88f1a0d878f3 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -226,8 +226,18 @@ static int smu_v13_0_4_system_features_control(struct 
smu_context *smu, bool en)
struct amdgpu_device *adev = smu->adev;
int ret = 0;
 
-   if (!en && !adev->in_s0ix)
+   if (!en && !adev->in_s0ix) {
+   /* Adds a GFX reset as workaround just before sending the
+* MP1_UNLOAD message to prevent GC/RLC/PMFW from entering
+* an invalid state.
+*/
+   ret = smu_cmn_send_smc_msg_with_param(smu, 
SMU_MSG_GfxDeviceDriverReset,
+ SMU_RESET_MODE_2, NULL);
+   if (ret)
+   return ret;
+
ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PrepareMp1ForUnload, 
NULL);
+   }
 
return ret;
 }
-- 
2.39.2



[PATCH] drm/amdgpu: reserve more memory for MES runtime DRAM

2024-02-22 Thread Tim Huang
This patch fixes a MES firmware boot failure issue
when backdoor loading the MES firmware.

MES firmware runtime DRAM size is changed to 512k,
the driver needs to reserve this amount of memory in
FB, otherwise adjacent memory will be overwritten by
the MES firmware startup code.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index 26d71a22395d..36127e204dfe 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -56,6 +56,7 @@ static int mes_v11_0_kiq_hw_init(struct amdgpu_device *adev);
 static int mes_v11_0_kiq_hw_fini(struct amdgpu_device *adev);
 
 #define MES_EOP_SIZE   2048
+#define GFX_MES_DRAM_SIZE  0x8
 
 static void mes_v11_0_ring_set_wptr(struct amdgpu_ring *ring)
 {
@@ -475,7 +476,13 @@ static int mes_v11_0_allocate_ucode_data_buffer(struct 
amdgpu_device *adev,
   le32_to_cpu(mes_hdr->mes_ucode_data_offset_bytes));
fw_size = le32_to_cpu(mes_hdr->mes_ucode_data_size_bytes);
 
-   r = amdgpu_bo_create_reserved(adev, fw_size,
+   if (fw_size > GFX_MES_DRAM_SIZE) {
+   dev_err(adev->dev, "PIPE%d ucode data fw size (%d) is greater 
than dram size (%d)\n",
+   pipe, fw_size, GFX_MES_DRAM_SIZE);
+   return -EINVAL;
+   }
+
+   r = amdgpu_bo_create_reserved(adev, GFX_MES_DRAM_SIZE,
  64 * 1024,
  AMDGPU_GEM_DOMAIN_VRAM |
  AMDGPU_GEM_DOMAIN_GTT,
@@ -611,8 +618,8 @@ static int mes_v11_0_load_microcode(struct amdgpu_device 
*adev,
WREG32_SOC15(GC, 0, regCP_MES_MDBASE_HI,
 upper_32_bits(adev->mes.data_fw_gpu_addr[pipe]));
 
-   /* Set 0x3 (256K-1) to CP_MES_MDBOUND_LO */
-   WREG32_SOC15(GC, 0, regCP_MES_MDBOUND_LO, 0x3);
+   /* Set 0x7 (512K-1) to CP_MES_MDBOUND_LO */
+   WREG32_SOC15(GC, 0, regCP_MES_MDBOUND_LO, 0x7);
 
if (prime_icache) {
/* invalidate ICACHE */
-- 
2.39.2



[PATCH v2] drm/amdgpu: fix memory overflow in the IB test

2023-11-21 Thread Tim Huang
Fix a memory overflow issue in the gfx IB test
for some ASICs. At least 20 bytes are needed for
the IB test packet.

v2: correct code indentation errors. (Christian)

Signed-off-by: Tim Huang 
Reviewed-by: Yifan Zhang 
Reviewed-by: Christian König 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 0c6133cc5e57..f281eecaeeec 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -419,7 +419,7 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, 
long timeout)
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
cpu_ptr = &adev->wb.wb[index];
 
-   r = amdgpu_ib_get(adev, NULL, 16, AMDGPU_IB_POOL_DIRECT, &ib);
+   r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
if (r) {
DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
goto err1;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 885ebd703260..1943beb135c4 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -883,8 +883,8 @@ static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, 
long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
-   AMDGPU_IB_POOL_DIRECT, &ib);
+
+   r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index e3ff6e46f3f7..69c500910746 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -1039,8 +1039,8 @@ static int gfx_v9_0_ring_test_ib(struct amdgpu_ring 
*ring, long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
-   AMDGPU_IB_POOL_DIRECT, &ib);
+
+   r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index 40d06d32bb74..4a09cc0d8ce0 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -297,8 +297,8 @@ static int gfx_v9_4_3_ring_test_ib(struct amdgpu_ring 
*ring, long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
- AMDGPU_IB_POOL_DIRECT, &ib);
+
+   r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
 
-- 
2.39.2



[PATCH] drm/amdgpu: fix memory overflow in the IB test

2023-11-20 Thread Tim Huang
Fix a memory overflow issue in the gfx IB test
for some ASICs. At least 20 bytes are needed for
the IB test packet.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 0c6133cc5e57..f281eecaeeec 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -419,7 +419,7 @@ static int gfx_v11_0_ring_test_ib(struct amdgpu_ring *ring, 
long timeout)
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
cpu_ptr = &adev->wb.wb[index];
 
-   r = amdgpu_ib_get(adev, NULL, 16, AMDGPU_IB_POOL_DIRECT, &ib);
+   r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
if (r) {
DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
goto err1;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 885ebd703260..4b0eda46405f 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -883,7 +883,7 @@ static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, 
long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
+   r = amdgpu_ib_get(adev, NULL, 20,
AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index e3ff6e46f3f7..a55710bf6e01 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -1039,7 +1039,7 @@ static int gfx_v9_0_ring_test_ib(struct amdgpu_ring 
*ring, long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
+   r = amdgpu_ib_get(adev, NULL, 20,
AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index 40d06d32bb74..603988e49cd5 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -297,7 +297,7 @@ static int gfx_v9_4_3_ring_test_ib(struct amdgpu_ring 
*ring, long timeout)
gpu_addr = adev->wb.gpu_addr + (index * 4);
adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
memset(&ib, 0, sizeof(ib));
-   r = amdgpu_ib_get(adev, NULL, 16,
+   r = amdgpu_ib_get(adev, NULL, 20,
  AMDGPU_IB_POOL_DIRECT, &ib);
if (r)
goto err1;
-- 
2.39.2



[PATCH v2] drm/amdgpu: fix GRBM read timeout when do mes_self_test

2023-11-01 Thread Tim Huang
Use a proper MEID to make sure the CP_HQD_* and CP_GFX_HQD_* registers
can be touched when initialize the compute and gfx mqd in mes_self_test.
Otherwise, we expect no response from CP and an GRBM eventual timeout.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
index 70fe3b39c004..45280fb0e00c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
@@ -556,8 +556,20 @@ static void amdgpu_mes_queue_init_mqd(struct amdgpu_device 
*adev,
mqd_prop.hqd_queue_priority = p->hqd_queue_priority;
mqd_prop.hqd_active = false;
 
+   if (p->queue_type == AMDGPU_RING_TYPE_GFX ||
+   p->queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+   mutex_lock(&adev->srbm_mutex);
+   amdgpu_gfx_select_me_pipe_q(adev, p->ring->me, p->ring->pipe, 
0, 0, 0);
+   }
+
mqd_mgr->init_mqd(adev, q->mqd_cpu_ptr, &mqd_prop);
 
+   if (p->queue_type == AMDGPU_RING_TYPE_GFX ||
+   p->queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+   amdgpu_gfx_select_me_pipe_q(adev, 0, 0, 0, 0, 0);
+   mutex_unlock(&adev->srbm_mutex);
+   }
+
amdgpu_bo_unreserve(q->mqd_obj);
 }
 
@@ -993,9 +1005,13 @@ int amdgpu_mes_add_ring(struct amdgpu_device *adev, int 
gang_id,
switch (queue_type) {
case AMDGPU_RING_TYPE_GFX:
ring->funcs = adev->gfx.gfx_ring[0].funcs;
+   ring->me = adev->gfx.gfx_ring[0].me;
+   ring->pipe = adev->gfx.gfx_ring[0].pipe;
break;
case AMDGPU_RING_TYPE_COMPUTE:
ring->funcs = adev->gfx.compute_ring[0].funcs;
+   ring->me = adev->gfx.compute_ring[0].me;
+   ring->pipe = adev->gfx.compute_ring[0].pipe;
break;
case AMDGPU_RING_TYPE_SDMA:
ring->funcs = adev->sdma.instance[0].ring.funcs;
-- 
2.39.2



[PATCH] drm/amdgpu: fix GRBM read timeout when do mes_self_test

2023-11-01 Thread Tim Huang
Use a proper MEID to make sure the CP_HQD_* and CP_GFX_HQD_* registers
can be touched when initialize the compute and gfx mqd in mes_self_test.
Otherwise, we expect no response from CP and an GRBM eventual timeout.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
index 70fe3b39c004..5ff76163ea27 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
@@ -556,8 +556,20 @@ static void amdgpu_mes_queue_init_mqd(struct amdgpu_device 
*adev,
mqd_prop.hqd_queue_priority = p->hqd_queue_priority;
mqd_prop.hqd_active = false;
 
+   if (p->queue_type == AMDGPU_RING_TYPE_GFX ||
+   p->queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+   mutex_lock(&adev->srbm_mutex);
+   amdgpu_gfx_select_me_pipe_q(adev, p->ring->me, p->ring->pipe, 
0, 0, 0);
+   }
+
mqd_mgr->init_mqd(adev, q->mqd_cpu_ptr, &mqd_prop);
 
+   if (p->queue_type == AMDGPU_RING_TYPE_GFX ||
+   p->queue_type == AMDGPU_RING_TYPE_COMPUTE) {
+   mutex_unlock(&adev->srbm_mutex);
+   amdgpu_gfx_select_me_pipe_q(adev, 0, 0, 0, 0, 0);
+   }
+
amdgpu_bo_unreserve(q->mqd_obj);
 }
 
@@ -993,9 +1005,13 @@ int amdgpu_mes_add_ring(struct amdgpu_device *adev, int 
gang_id,
switch (queue_type) {
case AMDGPU_RING_TYPE_GFX:
ring->funcs = adev->gfx.gfx_ring[0].funcs;
+   ring->me = adev->gfx.gfx_ring[0].me;
+   ring->pipe = adev->gfx.gfx_ring[0].pipe;
break;
case AMDGPU_RING_TYPE_COMPUTE:
ring->funcs = adev->gfx.compute_ring[0].funcs;
+   ring->me = adev->gfx.compute_ring[0].me;
+   ring->pipe = adev->gfx.compute_ring[0].pipe;
break;
case AMDGPU_RING_TYPE_SDMA:
ring->funcs = adev->sdma.instance[0].ring.funcs;
-- 
2.39.2



[PATCH 2/2] drm/amdgpu: move kfd_resume before the ip late init

2023-10-30 Thread Tim Huang
The kfd_resume needs to touch GC registers to enable the interrupts,
it needs to be done before GFXOFF is enabled to ensure that the GFX is
not off and GC registers can be touched. So move kfd_resume before the
amdgpu_device_ip_late_init which enables the CGPG/GFXOFF.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 21b8a8f2b622..ad98be349100 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4478,19 +4478,18 @@ int amdgpu_device_resume(struct drm_device *dev, bool 
fbcon)
}
amdgpu_fence_driver_hw_init(adev);
 
-   r = amdgpu_device_ip_late_init(adev);
-   if (r)
-   goto exit;
-
-   queue_delayed_work(system_wq, &adev->delayed_init_work,
-  msecs_to_jiffies(AMDGPU_RESUME_MS));
-
if (!adev->in_s0ix) {
r = amdgpu_amdkfd_resume(adev, adev->in_runpm);
if (r)
goto exit;
}
 
+   r = amdgpu_device_ip_late_init(adev);
+   if (r)
+   goto exit;
+
+   queue_delayed_work(system_wq, &adev->delayed_init_work,
+  msecs_to_jiffies(AMDGPU_RESUME_MS));
 exit:
if (amdgpu_sriov_vf(adev)) {
amdgpu_virt_init_data_exchange(adev);
-- 
2.39.2



[PATCH 1/2] drm/amd/pm: not stop rlc for IMU enabled APUs when suspend

2023-10-30 Thread Tim Huang
For IMU enabled APUs, after sending the PrepareMp1ForUnload message
to SMU in system_features_control, the RLC registers can't be touched.
The driver to stop the rlc in suspending is no longer required.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index 23b00eddc1af..5fb1c49e7e2d 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1711,6 +1711,7 @@ static int smu_disable_dpms(struct smu_context *smu)
}
 
if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(9, 4, 2) &&
+   !((adev->flags & AMD_IS_APU) && adev->gfx.imu.funcs) &&
!amdgpu_sriov_vf(adev) && adev->gfx.rlc.funcs->stop)
adev->gfx.rlc.funcs->stop(adev);
 
-- 
2.39.2



[PATCH] drm/amd/pm: wait for completion of the EnableGfxImu command

2023-10-09 Thread Tim Huang
Wait for completion of sending the EnableGfxImu message
when using the PSP FW loading.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
index 8dc683c02a7d..bcb7ab9d2221 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c
@@ -82,6 +82,8 @@ MODULE_FIRMWARE("amdgpu/smu_13_0_10.bin");
 #define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK 0xC000
 #define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT 0xE
 
+#define ENABLE_IMU_ARG_GFXOFF_ENABLE   1
+
 static const int link_width[] = {0, 1, 2, 4, 8, 12, 16};
 
 const int pmfw_decoded_link_speed[5] = {1, 2, 3, 4, 5};
@@ -2301,11 +2303,17 @@ int smu_v13_0_baco_exit(struct smu_context *smu)
 int smu_v13_0_set_gfx_power_up_by_imu(struct smu_context *smu)
 {
uint16_t index;
+   struct amdgpu_device *adev = smu->adev;
+
+   if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+   return smu_cmn_send_smc_msg_with_param(smu, 
SMU_MSG_EnableGfxImu,
+  
ENABLE_IMU_ARG_GFXOFF_ENABLE, NULL);
+   }
 
index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
   SMU_MSG_EnableGfxImu);
-   /* Param 1 to tell PMFW to enable GFXOFF feature */
-   return smu_cmn_send_msg_without_waiting(smu, index, 1);
+   return smu_cmn_send_msg_without_waiting(smu, index,
+   ENABLE_IMU_ARG_GFXOFF_ENABLE);
 }
 
 int smu_v13_0_od_edit_dpm_table(struct smu_context *smu,
-- 
2.39.2



[PATCH 2/2] drm/amd: flush any delayed gfxoff on suspend entry

2023-08-14 Thread Tim Huang
From: Mario Limonciello 

DCN 3.1.4 is reported to hang on s2idle entry if graphics activity
is happening during entry.  This is because GFXOFF was scheduled as
delayed but RLC gets disabled in s2idle entry sequence which will
hang GFX IP if not already in GFXOFF.

To help this problem, flush any delayed work for GFXOFF early in
s2idle entry sequence to ensure that it's off when RLC is changed.

commit 3964b0c2e843 ("drm/amdgpu: complete gfxoff allow signal during
suspend without delay") modified power gating flow so that if called
in s0ix that it ensured that GFXOFF wasn't put in work queue but
instead processed immediately.

This is dead code due to commit 5d70a549d00d ("drm/amdgpu: skip
CG/PG for gfx during S0ix") because GFXOFF will now not be explicitly
called as part of the suspend entry code.  Remove that dead code.

Signed-off-by: Mario Limonciello 
Signed-off-by: Tim Huang 
Reviewed-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c| 9 +
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 1b3bd77d82da..e77f048c99d8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4160,6 +4160,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool 
fbcon)

drm_fb_helper_set_suspend_unlocked(adev_to_drm(adev)->fb_helper, true);
 
cancel_delayed_work_sync(&adev->delayed_init_work);
+   flush_delayed_work(&adev->gfx.gfx_off_delay_work);
 
amdgpu_ras_suspend(adev);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index c76b6bfc4dab..2382921710ec 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -700,15 +700,8 @@ void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, bool 
enable)
 
if (adev->gfx.gfx_off_req_count == 0 &&
!adev->gfx.gfx_off_state) {
-   /* If going to s2idle, no need to wait */
-   if (adev->in_s0ix) {
-   if (!amdgpu_dpm_set_powergating_by_smu(adev,
-   AMD_IP_BLOCK_TYPE_GFX, true))
-   adev->gfx.gfx_off_state = true;
-   } else {
-   
schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
+   schedule_delayed_work(&adev->gfx.gfx_off_delay_work,
  delay);
-   }
}
} else {
if (adev->gfx.gfx_off_req_count == 0) {
-- 
2.34.1



[PATCH 1/2] drm/amdgpu: skip fence GFX interrupts disable/enable for S0ix

2023-08-14 Thread Tim Huang
GFX v11.0.1 reported fence fallback timer expired issue on
SDMA and GFX rings after S0ix resume. This is generated by
EOP interrupts are disabled when S0ix suspend but fails to
re-enable when resume because of the GFX is in GFXOFF.

[  203.349571] [drm] Fence fallback timer expired on ring sdma0
[  203.349572] [drm] Fence fallback timer expired on ring gfx_0.0.0
[  203.861635] [drm] Fence fallback timer expired on ring gfx_0.0.0

For S0ix, GFX is in GFXOFF state, avoid to touch the GFX registers
to configure the fence driver interrupts for rings that belong to GFX.
The interrupts configuration will be restored by GFXOFF exit.

Signed-off-by: Tim Huang 
Reviewed-by: Mario Limonciello 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 41 +--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index c694b41f6461..7537f5aa76f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -551,6 +551,41 @@ int amdgpu_fence_driver_sw_init(struct amdgpu_device *adev)
return 0;
 }
 
+/**
+ * amdgpu_fence_need_ring_interrupt_restore - helper function to check whether
+ * fence driver interrupts need to be restored.
+ *
+ * @ring: ring that to be checked
+ *
+ * Interrupts for rings that belong to GFX IP don't need to be restored
+ * when the target power state is s0ix.
+ *
+ * Return true if need to restore interrupts, false otherwise.
+ */
+static bool amdgpu_fence_need_ring_interrupt_restore(struct amdgpu_ring *ring)
+{
+   struct amdgpu_device *adev = ring->adev;
+   bool is_gfx_power_domain = false;
+
+   switch (ring->funcs->type) {
+   case AMDGPU_RING_TYPE_SDMA:
+   /* SDMA 5.x+ is part of GFX power domain so it's covered by GFXOFF */
+   if (adev->ip_versions[SDMA0_HWIP][0] >= IP_VERSION(5, 0, 0))
+   is_gfx_power_domain = true;
+   break;
+   case AMDGPU_RING_TYPE_GFX:
+   case AMDGPU_RING_TYPE_COMPUTE:
+   case AMDGPU_RING_TYPE_KIQ:
+   case AMDGPU_RING_TYPE_MES:
+   is_gfx_power_domain = true;
+   break;
+   default:
+   break;
+   }
+
+   return !(adev->in_s0ix && is_gfx_power_domain);
+}
+
 /**
  * amdgpu_fence_driver_hw_fini - tear down the fence driver
  * for all possible rings.
@@ -579,7 +614,8 @@ void amdgpu_fence_driver_hw_fini(struct amdgpu_device *adev)
amdgpu_fence_driver_force_completion(ring);
 
if (!drm_dev_is_unplugged(adev_to_drm(adev)) &&
-   ring->fence_drv.irq_src)
+   ring->fence_drv.irq_src &&
+   amdgpu_fence_need_ring_interrupt_restore(ring))
amdgpu_irq_put(adev, ring->fence_drv.irq_src,
   ring->fence_drv.irq_type);
 
@@ -655,7 +691,8 @@ void amdgpu_fence_driver_hw_init(struct amdgpu_device *adev)
continue;
 
/* enable the interrupt */
-   if (ring->fence_drv.irq_src)
+   if (ring->fence_drv.irq_src &&
+   amdgpu_fence_need_ring_interrupt_restore(ring))
amdgpu_irq_get(adev, ring->fence_drv.irq_src,
   ring->fence_drv.irq_type);
}
-- 
2.34.1



[PATCH] drm/amd/pm: bump SMU v13.0.5 driver_if header version

2023-08-10 Thread Tim Huang
Align the SMU driver interface version with PMFW to
suppress the version mismatch message on driver loading.

Signed-off-by: Tim Huang 
---
 .../gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_5.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_5.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_5.h
index 7589faa0232d..779c2524806c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_5.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_5.h
@@ -23,7 +23,7 @@
 #ifndef __SMU13_DRIVER_IF_V13_0_5_H__
 #define __SMU13_DRIVER_IF_V13_0_5_H__
 
-#define SMU13_0_5_DRIVER_IF_VERSION 4
+#define SMU13_0_5_DRIVER_IF_VERSION 5
 
 // Throttler Status Bitmask
 #define THROTTLER_STATUS_BIT_SPL0
@@ -103,7 +103,6 @@ typedef struct {
   uint16_t ThrottlerStatus;
 
   uint16_t CurrentSocketPower;  //[mW]
-  uint16_t spare1;
 } SmuMetrics_t;
 
 //Freq in MHz
-- 
2.34.1



[PATCH] drm/amd/pm: skip the RLC stop when S0i3 suspend for SMU v13.0.4/11

2023-07-27 Thread Tim Huang
From: Tim Huang 

For SMU v13.0.4/11, driver does not need to stop RLC for S0i3,
the firmwares will handle that properly.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index ce41a8309582..222af2fae745 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1581,9 +1581,9 @@ static int smu_disable_dpms(struct smu_context *smu)
 
/*
 * For SMU 13.0.4/11, PMFW will handle the features disablement properly
-* for gpu reset case. Driver involvement is unnecessary.
+* for gpu reset and S0i3 cases. Driver involvement is unnecessary.
 */
-   if (amdgpu_in_reset(adev)) {
+   if (amdgpu_in_reset(adev) || adev->in_s0ix) {
switch (adev->ip_versions[MP1_HWIP][0]) {
case IP_VERSION(13, 0, 4):
case IP_VERSION(13, 0, 11):
-- 
2.34.1



[PATCH 3/3] drm/amd/pm: enable more Pstates profile levels for SMU v13.0.5

2023-06-09 Thread Tim Huang
This patch enables following UMD stable Pstates profile
levels for power_dpm_force_performance_level interface.

- profile_peak
- profile_min_sclk
- profile_standard

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c  | 40 ++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.h  |  2 +-
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
index 53c508acf895..42f110602eb1 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
@@ -978,6 +978,38 @@ static int smu_v13_0_5_force_clk_levels(struct smu_context 
*smu,
return ret;
 }
 
+static int smu_v13_0_5_get_dpm_profile_freq(struct smu_context *smu,
+   enum amd_dpm_forced_level level,
+   enum smu_clk_type clk_type,
+   uint32_t *min_clk,
+   uint32_t *max_clk)
+{
+   int ret = 0;
+   uint32_t clk_limit = 0;
+
+   switch (clk_type) {
+   case SMU_GFXCLK:
+   case SMU_SCLK:
+   clk_limit = SMU_13_0_5_UMD_PSTATE_GFXCLK;
+   if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, 
&clk_limit);
+   else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_SCLK, 
&clk_limit, NULL);
+   break;
+   case SMU_VCLK:
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_VCLK, NULL, 
&clk_limit);
+   break;
+   case SMU_DCLK:
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_DCLK, NULL, 
&clk_limit);
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+   *min_clk = *max_clk = clk_limit;
+   return ret;
+}
+
 static int smu_v13_0_5_set_performance_level(struct smu_context *smu,
enum amd_dpm_forced_level level)
 {
@@ -1011,10 +1043,14 @@ static int smu_v13_0_5_set_performance_level(struct 
smu_context *smu,
break;
case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
-   case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
-   /* Temporarily do nothing since the optimal clocks haven't been 
provided yet */
+   smu_v13_0_5_get_dpm_profile_freq(smu, level, SMU_SCLK, 
&sclk_min, &sclk_max);
+   smu_v13_0_5_get_dpm_profile_freq(smu, level, SMU_VCLK, 
&vclk_min, &vclk_max);
+   smu_v13_0_5_get_dpm_profile_freq(smu, level, SMU_DCLK, 
&dclk_min, &dclk_max);
break;
+   case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
+   dev_err(adev->dev, "The performance level profile_min_mclk is 
not supported.");
+   return -EOPNOTSUPP;
case AMD_DPM_FORCED_LEVEL_MANUAL:
case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
return 0;
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.h 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.h
index 40bc0f8e6d61..263cd651855e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.h
@@ -24,6 +24,6 @@
 #define __SMU_V13_0_5_PPT_H__
 
 extern void smu_v13_0_5_set_ppt_funcs(struct smu_context *smu);
-#define SMU_13_0_5_UMD_PSTATE_GFXCLK   1100
+#define SMU_13_0_5_UMD_PSTATE_GFXCLK   700
 
 #endif
-- 
2.34.1



[PATCH 2/3] drm/amd/pm: enable vclk and dclk Pstates for SMU v13.0.5

2023-06-09 Thread Tim Huang
Add the ability to control the vclk and dclk frequency by
power_dpm_force_performance_level interface.

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c  | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
index 725c791ad3fc..53c508acf895 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
@@ -983,19 +983,31 @@ static int smu_v13_0_5_set_performance_level(struct 
smu_context *smu,
 {
struct amdgpu_device *adev = smu->adev;
uint32_t sclk_min = 0, sclk_max = 0;
+   uint32_t vclk_min = 0, vclk_max = 0;
+   uint32_t dclk_min = 0, dclk_max = 0;
int ret = 0;
 
switch (level) {
case AMD_DPM_FORCED_LEVEL_HIGH:
smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, 
&sclk_max);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_VCLK, NULL, 
&vclk_max);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_DCLK, NULL, 
&dclk_max);
sclk_min = sclk_max;
+   vclk_min = vclk_max;
+   dclk_min = dclk_max;
break;
case AMD_DPM_FORCED_LEVEL_LOW:
smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, 
NULL);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_VCLK, &vclk_min, 
NULL);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_DCLK, &dclk_min, 
NULL);
sclk_max = sclk_min;
+   vclk_max = vclk_min;
+   dclk_max = dclk_min;
break;
case AMD_DPM_FORCED_LEVEL_AUTO:
smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, 
&sclk_max);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_VCLK, &vclk_min, 
&vclk_max);
+   smu_v13_0_5_get_dpm_ultimate_freq(smu, SMU_DCLK, &dclk_min, 
&dclk_max);
break;
case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
@@ -1023,6 +1035,23 @@ static int smu_v13_0_5_set_performance_level(struct 
smu_context *smu,
smu->gfx_actual_soft_max_freq = sclk_max;
}
 
+   if (vclk_min && vclk_max) {
+   ret = smu_v13_0_5_set_soft_freq_limited_range(smu,
+ SMU_VCLK,
+ vclk_min,
+ vclk_max);
+   if (ret)
+   return ret;
+   }
+
+   if (dclk_min && dclk_max) {
+   ret = smu_v13_0_5_set_soft_freq_limited_range(smu,
+ SMU_DCLK,
+ dclk_min,
+ dclk_max);
+   if (ret)
+   return ret;
+   }
return ret;
 }
 
-- 
2.34.1



[PATCH 1/3] drm/amd/pm: fix vclk setting failed for SMU v13.0.5

2023-06-09 Thread Tim Huang
PMFW use the left-shifted 16 bits argument to set the VCLK
DPM frequency for SMU v13.0.5.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
index 7c3ac535f68a..725c791ad3fc 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
@@ -831,6 +831,8 @@ static int smu_v13_0_5_set_soft_freq_limited_range(struct 
smu_context *smu,
uint32_t max)
 {
enum smu_message_type msg_set_min, msg_set_max;
+   uint32_t min_clk = min;
+   uint32_t max_clk = max;
int ret = 0;
 
if (!smu_v13_0_5_clk_dpm_is_enabled(smu, clk_type))
@@ -851,11 +853,16 @@ static int smu_v13_0_5_set_soft_freq_limited_range(struct 
smu_context *smu,
return -EINVAL;
}
 
-   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_min, min, NULL);
+   if (clk_type == SMU_VCLK) {
+   min_clk = min << SMU_13_VCLK_SHIFT;
+   max_clk = max << SMU_13_VCLK_SHIFT;
+   }
+
+   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_min, min_clk, NULL);
if (ret)
goto out;
 
-   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_max, max, NULL);
+   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_max, max_clk, NULL);
if (ret)
goto out;
 
-- 
2.34.1



[PATCH 2/3] drm/amd/pm: enable vclk and dclk Pstates for SMU v13.0.4

2023-06-07 Thread Tim Huang
Add the ability to control the vclk and dclk frequency by
power_dpm_force_performance_level interface.

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c  | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 999b07db862e..315a6d8bde2e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -915,6 +915,8 @@ static int smu_v13_0_4_set_performance_level(struct 
smu_context *smu,
uint32_t sclk_min = 0, sclk_max = 0;
uint32_t fclk_min = 0, fclk_max = 0;
uint32_t socclk_min = 0, socclk_max = 0;
+   uint32_t vclk_min = 0, vclk_max = 0;
+   uint32_t dclk_min = 0, dclk_max = 0;
int ret = 0;
 
switch (level) {
@@ -922,22 +924,32 @@ static int smu_v13_0_4_set_performance_level(struct 
smu_context *smu,
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, 
&sclk_max);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, NULL, 
&fclk_max);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, NULL, 
&socclk_max);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_VCLK, NULL, 
&vclk_max);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_DCLK, NULL, 
&dclk_max);
sclk_min = sclk_max;
fclk_min = fclk_max;
socclk_min = socclk_max;
+   vclk_min = vclk_max;
+   dclk_min = dclk_max;
break;
case AMD_DPM_FORCED_LEVEL_LOW:
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, 
NULL);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, &fclk_min, 
NULL);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, &socclk_min, 
NULL);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_VCLK, &vclk_min, 
NULL);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_DCLK, &dclk_min, 
NULL);
sclk_max = sclk_min;
fclk_max = fclk_min;
socclk_max = socclk_min;
+   vclk_max = vclk_min;
+   dclk_max = dclk_min;
break;
case AMD_DPM_FORCED_LEVEL_AUTO:
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, 
&sclk_max);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, &fclk_min, 
&fclk_max);
smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, &socclk_min, 
&socclk_max);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_VCLK, &vclk_min, 
&vclk_max);
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_DCLK, &dclk_min, 
&dclk_max);
break;
case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
@@ -983,6 +995,23 @@ static int smu_v13_0_4_set_performance_level(struct 
smu_context *smu,
return ret;
}
 
+   if (vclk_min && vclk_max) {
+   ret = smu_v13_0_4_set_soft_freq_limited_range(smu,
+ SMU_VCLK,
+ vclk_min,
+ vclk_max);
+   if (ret)
+   return ret;
+   }
+
+   if (dclk_min && dclk_max) {
+   ret = smu_v13_0_4_set_soft_freq_limited_range(smu,
+ SMU_DCLK,
+ dclk_min,
+ dclk_max);
+   if (ret)
+   return ret;
+   }
return ret;
 }
 
-- 
2.34.1



[PATCH 3/3] drm/amd/pm: enable more Pstates profile levels for SMU v13.0.4

2023-06-07 Thread Tim Huang
This patch enables following UMD stable Pstates profile
levels for power_dpm_force_performance_level interface.

- profile_peak
- profile_min_mclk
- profile_min_sclk
- profile_standard

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c  | 54 ++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 315a6d8bde2e..ef37dda9908f 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -54,6 +54,10 @@
 
 #define FEATURE_MASK(feature) (1ULL << feature)
 
+#define SMU_13_0_4_UMD_PSTATE_GFXCLK   938
+#define SMU_13_0_4_UMD_PSTATE_SOCCLK   938
+#define SMU_13_0_4_UMD_PSTATE_FCLK 1875
+
 #define SMC_DPM_FEATURE ( \
FEATURE_MASK(FEATURE_CCLK_DPM_BIT) | \
FEATURE_MASK(FEATURE_VCN_DPM_BIT)| \
@@ -908,6 +912,50 @@ static int smu_v13_0_4_force_clk_levels(struct smu_context 
*smu,
return ret;
 }
 
+static int smu_v13_0_4_get_dpm_profile_freq(struct smu_context *smu,
+   enum amd_dpm_forced_level level,
+   enum smu_clk_type clk_type,
+   uint32_t *min_clk,
+   uint32_t *max_clk)
+{
+   int ret = 0;
+   uint32_t clk_limit = 0;
+
+   switch (clk_type) {
+   case SMU_GFXCLK:
+   case SMU_SCLK:
+   clk_limit = SMU_13_0_4_UMD_PSTATE_GFXCLK;
+   if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, 
&clk_limit);
+   else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK)
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, 
&clk_limit, NULL);
+   break;
+   case SMU_SOCCLK:
+   clk_limit = SMU_13_0_4_UMD_PSTATE_SOCCLK;
+   if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, 
NULL, &clk_limit);
+   break;
+   case SMU_FCLK:
+   clk_limit = SMU_13_0_4_UMD_PSTATE_FCLK;
+   if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, NULL, 
&clk_limit);
+   else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK)
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, 
&clk_limit, NULL);
+   break;
+   case SMU_VCLK:
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_VCLK, NULL, 
&clk_limit);
+   break;
+   case SMU_DCLK:
+   smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_DCLK, NULL, 
&clk_limit);
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+   *min_clk = *max_clk = clk_limit;
+   return ret;
+}
+
 static int smu_v13_0_4_set_performance_level(struct smu_context *smu,
 enum amd_dpm_forced_level level)
 {
@@ -955,7 +1003,11 @@ static int smu_v13_0_4_set_performance_level(struct 
smu_context *smu,
case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
-   /* Temporarily do nothing since the optimal clocks haven't been 
provided yet */
+   smu_v13_0_4_get_dpm_profile_freq(smu, level, SMU_SCLK, 
&sclk_min, &sclk_max);
+   smu_v13_0_4_get_dpm_profile_freq(smu, level, SMU_FCLK, 
&fclk_min, &fclk_max);
+   smu_v13_0_4_get_dpm_profile_freq(smu, level, SMU_SOCCLK, 
&socclk_min, &socclk_max);
+   smu_v13_0_4_get_dpm_profile_freq(smu, level, SMU_VCLK, 
&vclk_min, &vclk_max);
+   smu_v13_0_4_get_dpm_profile_freq(smu, level, SMU_DCLK, 
&dclk_min, &dclk_max);
break;
case AMD_DPM_FORCED_LEVEL_MANUAL:
case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
-- 
2.34.1



[PATCH 1/3] drm/amd/pm: fix vclk setting failed for SMU v13.0.4

2023-06-07 Thread Tim Huang
PMFW use the left-shifted 16 bits argument to set the VCLK
DPM frequency for SMU v13.0.4.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h |  2 ++
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c | 11 +--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
index 5a99a091965e..6a0ac0bbaace 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
@@ -51,6 +51,8 @@
 #define CTF_OFFSET_HOTSPOT 5
 #define CTF_OFFSET_MEM 5
 
+#define SMU_13_VCLK_SHIFT  16
+
 extern const int pmfw_decoded_link_speed[5];
 extern const int pmfw_decoded_link_width[7];
 
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 46a8a366f287..999b07db862e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -831,6 +831,8 @@ static int smu_v13_0_4_set_soft_freq_limited_range(struct 
smu_context *smu,
   uint32_t max)
 {
enum smu_message_type msg_set_min, msg_set_max;
+   uint32_t min_clk = min;
+   uint32_t max_clk = max;
int ret = 0;
 
if (!smu_v13_0_4_clk_dpm_is_enabled(smu, clk_type))
@@ -859,12 +861,17 @@ static int smu_v13_0_4_set_soft_freq_limited_range(struct 
smu_context *smu,
return -EINVAL;
}
 
-   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_min, min, NULL);
+   if (clk_type == SMU_VCLK) {
+   min_clk = min << SMU_13_VCLK_SHIFT;
+   max_clk = max << SMU_13_VCLK_SHIFT;
+   }
+
+   ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_min, min_clk, NULL);
if (ret)
return ret;
 
return smu_cmn_send_smc_msg_with_param(smu, msg_set_max,
-  max, NULL);
+  max_clk, NULL);
 }
 
 static int smu_v13_0_4_force_clk_levels(struct smu_context *smu,
-- 
2.34.1



[PATCH] drm/amd/pm: reverse mclk and fclk clocks levels for renoir

2023-05-22 Thread Tim Huang
This patch reverses the DPM clocks levels output of pp_dpm_mclk
and pp_dpm_fclk for renoir.

On dGPUs and older APUs we expose the levels from lowest clocks
to highest clocks. But for some APUs, the clocks levels are
given the reversed orders by PMFW. Like the memory DPM clocks
that are exposed by pp_dpm_mclk.

It's not intuitive that they are reversed on these APUs. All tools
and software that talks to the driver then has to know different ways
to interpret the data depending on the asic.

So we need to reverse them to expose the clocks levels from the
driver consistently.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c
index 5cdc07165480..8a8ba25c9ad7 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c
@@ -494,7 +494,7 @@ static int renoir_set_fine_grain_gfx_freq_parameters(struct 
smu_context *smu)
 static int renoir_print_clk_levels(struct smu_context *smu,
enum smu_clk_type clk_type, char *buf)
 {
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0, min = 0, max = 0;
SmuMetrics_t metrics;
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
@@ -594,7 +594,8 @@ static int renoir_print_clk_levels(struct smu_context *smu,
case SMU_VCLK:
case SMU_DCLK:
for (i = 0; i < count; i++) {
-   ret = renoir_get_dpm_clk_limited(smu, clk_type, i, 
&value);
+   idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? 
(count - i - 1) : i;
+   ret = renoir_get_dpm_clk_limited(smu, clk_type, idx, 
&value);
if (ret)
return ret;
if (!value)
-- 
2.34.1



[PATCH 3/4] amd/pm/swsmu: reverse mclk and fclk clocks levels for yellow carp

2023-05-22 Thread Tim Huang
This patch reverses the DPM clocks levels output of pp_dpm_mclk
and pp_dpm_fclk.

On dGPUs and older APUs we expose the levels from lowest clocks
to highest clocks. But for some APUs, the clocks levels that from
the DFPstateTable are given the reversed orders by PMFW. Like the
memory DPM clocks that are exposed by pp_dpm_mclk.

It's not intuitive that they are reversed on these APUs. All tools
and software that talks to the driver then has to know different ways
to interpret the data depending on the asic.

So we need to reverse them to expose the clocks levels from the
driver consistently.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c
index ac5fcca0e47f..a92da336ecec 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c
@@ -1000,7 +1000,7 @@ static int yellow_carp_set_soft_freq_limited_range(struct 
smu_context *smu,
 static int yellow_carp_print_clk_levels(struct smu_context *smu,
enum smu_clk_type clk_type, char *buf)
 {
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0;
uint32_t min, max;
 
@@ -1033,7 +1033,8 @@ static int yellow_carp_print_clk_levels(struct 
smu_context *smu,
goto print_clk_out;
 
for (i = 0; i < count; i++) {
-   ret = yellow_carp_get_dpm_freq_by_index(smu, clk_type, 
i, &value);
+   idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? 
(count - i - 1) : i;
+   ret = yellow_carp_get_dpm_freq_by_index(smu, clk_type, 
idx, &value);
if (ret)
goto print_clk_out;
 
-- 
2.34.1



[PATCH 1/4] amd/pm/swsmu: reverse mclk and fclk clocks levels for SMU v13.0.4

2023-05-22 Thread Tim Huang
This patch reverses the DPM clocks levels output of pp_dpm_mclk
and pp_dpm_fclk.

On dGPUs and older APUs we expose the levels from lowest clocks
to highest clocks. But for some APUs, the clocks levels that from
the DFPstateTable are given the reversed orders by PMFW. Like the
memory DPM clocks that are exposed by pp_dpm_mclk.

It's not intuitive that they are reversed on these APUs. All tools
and software that talks to the driver then has to know different ways
to interpret the data depending on the asic.

So we need to reverse them to expose the clocks levels from the
driver consistently.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 0a0a7debb3ae..46a8a366f287 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -478,7 +478,7 @@ static int smu_v13_0_4_get_dpm_level_count(struct 
smu_context *smu,
 static int smu_v13_0_4_print_clk_levels(struct smu_context *smu,
enum smu_clk_type clk_type, char *buf)
 {
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0;
uint32_t min, max;
 
@@ -512,7 +512,8 @@ static int smu_v13_0_4_print_clk_levels(struct smu_context 
*smu,
break;
 
for (i = 0; i < count; i++) {
-   ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type, 
i, &value);
+   idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? 
(count - i - 1) : i;
+   ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type, 
idx, &value);
if (ret)
break;
 
-- 
2.34.1



[PATCH 4/4] amd/pm/swsmu: reverse mclk and fclk clocks levels for vangogh

2023-05-22 Thread Tim Huang
This patch reverses the DPM clocks levels output of pp_dpm_mclk
and pp_dpm_fclk.

On dGPUs and older APUs we expose the levels from lowest clocks
to highest clocks. But for some APUs, the clocks levels that from
the DFPstateTable are given the reversed orders by PMFW. Like the
memory DPM clocks that are exposed by pp_dpm_mclk.

It's not intuitive that they are reversed on these APUs. All tools
and software that talks to the driver then has to know different ways
to interpret the data depending on the asic.

So we need to reverse them to expose the clocks levels from the
driver consistently.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
index 7433dcaa16e0..067b4e0b026c 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c
@@ -582,7 +582,7 @@ static int vangogh_print_legacy_clk_levels(struct 
smu_context *smu,
DpmClocks_t *clk_table = smu->smu_table.clocks_table;
SmuMetrics_legacy_t metrics;
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0;
bool cur_value_match_level = false;
 
@@ -656,7 +656,8 @@ static int vangogh_print_legacy_clk_levels(struct 
smu_context *smu,
case SMU_MCLK:
case SMU_FCLK:
for (i = 0; i < count; i++) {
-   ret = vangogh_get_dpm_clk_limited(smu, clk_type, i, 
&value);
+   idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? 
(count - i - 1) : i;
+   ret = vangogh_get_dpm_clk_limited(smu, clk_type, idx, 
&value);
if (ret)
return ret;
if (!value)
@@ -683,7 +684,7 @@ static int vangogh_print_clk_levels(struct smu_context *smu,
DpmClocks_t *clk_table = smu->smu_table.clocks_table;
SmuMetrics_t metrics;
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0;
bool cur_value_match_level = false;
uint32_t min, max;
@@ -765,7 +766,8 @@ static int vangogh_print_clk_levels(struct smu_context *smu,
case SMU_MCLK:
case SMU_FCLK:
for (i = 0; i < count; i++) {
-   ret = vangogh_get_dpm_clk_limited(smu, clk_type, i, 
&value);
+   idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? 
(count - i - 1) : i;
+   ret = vangogh_get_dpm_clk_limited(smu, clk_type, idx, 
&value);
if (ret)
return ret;
if (!value)
-- 
2.34.1



[PATCH 2/4] amd/pm/swsmu: reverse mclk clocks levels for SMU v13.0.5

2023-05-22 Thread Tim Huang
This patch reverses the DPM clocks levels output of pp_dpm_mclk.

On dGPUs and older APUs we expose the levels from lowest clocks
to highest clocks. But for some APUs, the clocks levels that from
the DFPstateTable are given the reversed orders by PMFW. Like the
memory DPM clocks that are exposed by pp_dpm_mclk.

It's not intuitive that they are reversed on these APUs. All tools
and software that talks to the driver then has to know different ways
to interpret the data depending on the asic.

So we need to reverse them to expose the clocks levels from the
driver consistently.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
index 165b2470b017..7c3ac535f68a 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_5_ppt.c
@@ -866,7 +866,7 @@ static int smu_v13_0_5_set_soft_freq_limited_range(struct 
smu_context *smu,
 static int smu_v13_0_5_print_clk_levels(struct smu_context *smu,
enum smu_clk_type clk_type, char *buf)
 {
-   int i, size = 0, ret = 0;
+   int i, idx, size = 0, ret = 0;
uint32_t cur_value = 0, value = 0, count = 0;
uint32_t min = 0, max = 0;
 
@@ -898,7 +898,8 @@ static int smu_v13_0_5_print_clk_levels(struct smu_context 
*smu,
goto print_clk_out;
 
for (i = 0; i < count; i++) {
-   ret = smu_v13_0_5_get_dpm_freq_by_index(smu, clk_type, 
i, &value);
+   idx = (clk_type == SMU_MCLK) ? (count - i - 1) : i;
+   ret = smu_v13_0_5_get_dpm_freq_by_index(smu, clk_type, 
idx, &value);
if (ret)
goto print_clk_out;
 
-- 
2.34.1



[PATCH] drm/amdgpu: allow more APUs to do mode2 reset when go to S4 (v2)

2023-03-30 Thread Tim Huang
Skip mode2 reset only for IMU enabled APUs when do S4 to
fix the possible S4 regression issues on old ASICs.

v2:
Update this commit message to add Fixes and Link tags.

Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2483
Fixes: 2bedd3f21b30 ("drm/amdgpu: skip ASIC reset for APUs when go to S4")
Signed-off-by: Tim Huang 
Tested-by: Yuan Perry 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index 0f7cd3e8e00b..edaf3ded4a04 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -981,7 +981,12 @@ static bool amdgpu_atcs_pci_probe_handle(struct pci_dev 
*pdev)
  */
 bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
 {
-   if (adev->flags & AMD_IS_APU)
+   if ((adev->flags & AMD_IS_APU) &&
+   adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled 
APUs */
+   return false;
+
+   if ((adev->flags & AMD_IS_APU) &&
+   amdgpu_acpi_is_s3_active(adev))
return false;
 
if (amdgpu_sriov_vf(adev))
-- 
2.25.1



[PATCH] drm/amdgpu: allow more APUs to do mode2 reset when go to S4

2023-03-29 Thread Tim Huang
Skip mode2 reset only for IMU enabled APUs when do S4.

This patch is to fix the regression issue
https://gitlab.freedesktop.org/drm/amd/-/issues/2483
It is generated by patch "2bedd3f21b30 drm/amdgpu: skip ASIC reset
for APUs when go to S4".

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index 0f7cd3e8e00b..edaf3ded4a04 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -981,7 +981,12 @@ static bool amdgpu_atcs_pci_probe_handle(struct pci_dev 
*pdev)
  */
 bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
 {
-   if (adev->flags & AMD_IS_APU)
+   if ((adev->flags & AMD_IS_APU) &&
+   adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled 
APUs */
+   return false;
+
+   if ((adev->flags & AMD_IS_APU) &&
+   amdgpu_acpi_is_s3_active(adev))
return false;
 
if (amdgpu_sriov_vf(adev))
-- 
2.25.1



[PATCH] drm/amd/pm: re-enable the gfx imu when smu resume

2023-03-24 Thread Tim Huang
If the gfx imu is poweroff when suspend, then
it need to be re-enabled when resume.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 40 ---
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index b5d64749990e..94fe8593444a 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -162,10 +162,15 @@ int smu_get_dpm_freq_range(struct smu_context *smu,
 
 int smu_set_gfx_power_up_by_imu(struct smu_context *smu)
 {
-   if (!smu->ppt_funcs || !smu->ppt_funcs->set_gfx_power_up_by_imu)
-   return -EOPNOTSUPP;
+   int ret = 0;
+   struct amdgpu_device *adev = smu->adev;
 
-   return smu->ppt_funcs->set_gfx_power_up_by_imu(smu);
+   if (smu->ppt_funcs->set_gfx_power_up_by_imu) {
+   ret = smu->ppt_funcs->set_gfx_power_up_by_imu(smu);
+   if (ret)
+   dev_err(adev->dev, "Failed to enable gfx imu!\n");
+   }
+   return ret;
 }
 
 static u32 smu_get_mclk(void *handle, bool low)
@@ -196,6 +201,19 @@ static u32 smu_get_sclk(void *handle, bool low)
return clk_freq * 100;
 }
 
+static int smu_set_gfx_imu_enable(struct smu_context *smu)
+{
+   struct amdgpu_device *adev = smu->adev;
+
+   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
+   return 0;
+
+   if (amdgpu_in_reset(smu->adev) || adev->in_s0ix)
+   return 0;
+
+   return smu_set_gfx_power_up_by_imu(smu);
+}
+
 static int smu_dpm_set_vcn_enable(struct smu_context *smu,
  bool enable)
 {
@@ -1396,15 +1414,9 @@ static int smu_hw_init(void *handle)
}
 
if (smu->is_apu) {
-   if ((smu->ppt_funcs->set_gfx_power_up_by_imu) &&
-   likely(adev->firmware.load_type == 
AMDGPU_FW_LOAD_PSP)) {
-   ret = smu->ppt_funcs->set_gfx_power_up_by_imu(smu);
-   if (ret) {
-   dev_err(adev->dev, "Failed to Enable gfx 
imu!\n");
-   return ret;
-   }
-   }
-
+   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);
smu_set_gfx_cgpg(smu, true);
@@ -1681,6 +1693,10 @@ static int smu_resume(void *handle)
return ret;
}
 
+   ret = smu_set_gfx_imu_enable(smu);
+   if (ret)
+   return ret;
+
smu_set_gfx_cgpg(smu, true);
 
smu->disable_uclk_switch = 0;
-- 
2.25.1



[PATCH 2/2] drm/amdgpu: skip ASIC reset for APUs when go to S4

2023-03-15 Thread Tim Huang
For GC IP v11.0.4/11, PSP TMR need to be reserved
for ASIC mode2 reset. But for S4, when psp suspend,
it will destroy the TMR that fails the ASIC reset.

[  96.006101] amdgpu :62:00.0: amdgpu: MODE2 reset
[  100.409717] amdgpu :62:00.0: amdgpu: SMU: I'm not done with your 
previous command: SMN_C2PMSG_66:0x0011 SMN_C2PMSG_82:0x0002
[  100.411593] amdgpu :62:00.0: amdgpu: Mode2 reset failed!
[  100.412470] amdgpu :62:00.0: PM: pci_pm_freeze(): 
amdgpu_pmops_freeze+0x0/0x50 [amdgpu] returns -62
[  100.414020] amdgpu :62:00.0: PM: dpm_run_callback(): 
pci_pm_freeze+0x0/0xd0 returns -62
[  100.415311] amdgpu :62:00.0: PM: pci_pm_freeze+0x0/0xd0 returned -62 
after 4623202 usecs
[  100.416608] amdgpu :62:00.0: PM: failed to freeze async: error -62

We can skip the reset on APUs, assuming we can resume them
properly. Verified on some GFX11, GFX10 and old GFX9 APUs.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 5f02c530e2cc..64214996278b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2467,7 +2467,10 @@ static int amdgpu_pmops_freeze(struct device *dev)
adev->in_s4 = false;
if (r)
return r;
-   return amdgpu_asic_reset(adev);
+
+   if (amdgpu_acpi_should_gpu_reset(adev))
+   return amdgpu_asic_reset(adev);
+   return 0;
 }
 
 static int amdgpu_pmops_thaw(struct device *dev)
-- 
2.25.1



[PATCH 1/2] drm/amdgpu: reposition the gpu reset checking for reuse

2023-03-15 Thread Tim Huang
Move the amdgpu_acpi_should_gpu_reset out of
CONFIG_SUSPEND to share it with hibernate case.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  |  4 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 40 +---
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 5c6132502f35..5bddc03332b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1392,10 +1392,12 @@ int amdgpu_acpi_smart_shift_update(struct drm_device 
*dev, enum amdgpu_ss ss_sta
 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
 
 void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps);
+bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev);
 void amdgpu_acpi_detect(void);
 #else
 static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
 static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
+static inline bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev) { 
return false; }
 static inline void amdgpu_acpi_detect(void) { }
 static inline bool amdgpu_acpi_is_power_shift_control_supported(void) { return 
false; }
 static inline int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
@@ -1406,11 +1408,9 @@ static inline int amdgpu_acpi_smart_shift_update(struct 
drm_device *dev,
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev);
-bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev);
 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev);
 #else
 static inline bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { 
return false; }
-static inline bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev) { 
return false; }
 static inline bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { 
return false; }
 #endif
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
index 25e902077caf..065944bdeee4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -971,6 +971,28 @@ static bool amdgpu_atcs_pci_probe_handle(struct pci_dev 
*pdev)
return true;
 }
 
+
+/**
+ * amdgpu_acpi_should_gpu_reset
+ *
+ * @adev: amdgpu_device_pointer
+ *
+ * returns true if should reset GPU, false if not
+ */
+bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
+{
+   if (adev->flags & AMD_IS_APU)
+   return false;
+
+   if (amdgpu_sriov_vf(adev))
+   return false;
+
+#if IS_ENABLED(CONFIG_SUSPEND)
+   return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;
+#endif /* CONFIG_SUSPEND */
+   return true;
+}
+
 /*
  * amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods
  *
@@ -1042,24 +1064,6 @@ bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
(pm_suspend_target_state == PM_SUSPEND_MEM);
 }
 
-/**
- * amdgpu_acpi_should_gpu_reset
- *
- * @adev: amdgpu_device_pointer
- *
- * returns true if should reset GPU, false if not
- */
-bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
-{
-   if (adev->flags & AMD_IS_APU)
-   return false;
-
-   if (amdgpu_sriov_vf(adev))
-   return false;
-
-   return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;
-}
-
 /**
  * amdgpu_acpi_is_s0ix_active
  *
-- 
2.25.1



[PATCH] drm/amdgpu: skip ASIC reset for GC IP v11.0.4/11 when go to S4

2023-03-13 Thread Tim Huang
[Why]
For GC IP v11.0.4/11, PSP TMR need to be reserved
for ASIC mode2 reset. But for S4, when psp suspend,
it will destroy the TMR that fails the ASIC reset.

[  96.006101] amdgpu :62:00.0: amdgpu: MODE2 reset
[  100.409717] amdgpu :62:00.0: amdgpu: SMU: I'm not done with your 
previous command: SMN_C2PMSG_66:0x0011 SMN_C2PMSG_82:0x0002
[  100.411593] amdgpu :62:00.0: amdgpu: Mode2 reset failed!
[  100.412470] amdgpu :62:00.0: PM: pci_pm_freeze(): 
amdgpu_pmops_freeze+0x0/0x50 [amdgpu] returns -62
[  100.414020] amdgpu :62:00.0: PM: dpm_run_callback(): 
pci_pm_freeze+0x0/0xd0 returns -62
[  100.415311] amdgpu :62:00.0: PM: pci_pm_freeze+0x0/0xd0 returned -62 
after 4623202 usecs
[  100.416608] amdgpu :62:00.0: PM: failed to freeze async: error -62

[How]
Skip the ASIC reset for S4, assuming we can resume properly without
reset.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
index 8fa9a36c38b6..ba02b0d9ef7e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_4_ppt.c
@@ -980,6 +980,8 @@ static int smu_v13_0_4_set_performance_level(struct 
smu_context *smu,
 
 static int smu_v13_0_4_mode2_reset(struct smu_context *smu)
 {
+   if (!amdgpu_in_reset(smu->adev)) /* Skip the reset for S4 */
+   return 0;
return smu_cmn_send_smc_msg_with_param(smu, 
SMU_MSG_GfxDeviceDriverReset,
   SMU_RESET_MODE_2, NULL);
 }
-- 
2.25.1



[PATCH] drm/amd/pm: bump SMU 13.0.4 driver_if header version

2023-03-07 Thread Tim Huang
Align the SMU driver interface version with PMFW to
suppress the version mismatch message on driver loading.

Signed-off-by: Tim Huang 
---
 .../drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h| 4 ++--
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
index f77401709d83..2162ecd1057d 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
@@ -27,7 +27,7 @@
 // *** IMPORTANT ***
 // SMU TEAM: Always increment the interface version if
 // any structure is changed in this file
-#define PMFW_DRIVER_IF_VERSION 7
+#define PMFW_DRIVER_IF_VERSION 8
 
 typedef struct {
   int32_t value;
@@ -198,7 +198,7 @@ typedef struct {
   uint16_t SkinTemp;
   uint16_t DeviceState;
   uint16_t CurTemp; //[centi-Celsius]
-  uint16_t spare2;
+  uint16_t FilterAlphaValue;
 
   uint16_t AverageGfxclkFrequency;
   uint16_t AverageFclkFrequency;
diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
index e7d8b4eb4b56..0ef37837b164 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
@@ -29,7 +29,7 @@
 #define SMU13_DRIVER_IF_VERSION_YELLOW_CARP 0x04
 #define SMU13_DRIVER_IF_VERSION_ALDE 0x08
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_0_0 0x37
-#define SMU13_DRIVER_IF_VERSION_SMU_V13_0_4 0x07
+#define SMU13_DRIVER_IF_VERSION_SMU_V13_0_4 0x08
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_5 0x04
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_0_10 0x32
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_7 0x37
-- 
2.25.1



[PATCH RESEND] drm/amd/pm: drop unneeded dpm features disablement for SMU 13.0.4/11

2023-01-27 Thread Tim Huang
PMFW will handle the features disablement properly for gpu reset case,
driver involvement may cause some unexpected issues.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index ec52830dde24..8bae3fe869cd 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1497,6 +1497,20 @@ static int smu_disable_dpms(struct smu_context *smu)
}
}
 
+   /*
+* For SMU 13.0.4/11, PMFW will handle the features disablement properly
+* for gpu reset case. Driver involvement is unnecessary.
+*/
+   if (amdgpu_in_reset(adev)) {
+   switch (adev->ip_versions[MP1_HWIP][0]) {
+   case IP_VERSION(13, 0, 4):
+   case IP_VERSION(13, 0, 11):
+   return 0;
+   default:
+   break;
+   }
+   }
+
/*
 * For gpu reset, runpm and hibernation through BACO,
 * BACO feature has to be kept enabled.
-- 
2.25.1



[PATCH v2] drm/amd/pm: drop unneeded dpm features disablement for SMU 13.0.4/11

2023-01-20 Thread Tim Huang
PMFW will handle that properly for gpu reset case. Driver involvement
may cause some unexpected issues.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index ec52830dde24..8bae3fe869cd 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1497,6 +1497,20 @@ static int smu_disable_dpms(struct smu_context *smu)
}
}
 
+   /*
+* For SMU 13.0.4/11, PMFW will handle the features disablement properly
+* for gpu reset case. Driver involvement is unnecessary.
+*/
+   if (amdgpu_in_reset(adev)) {
+   switch (adev->ip_versions[MP1_HWIP][0]) {
+   case IP_VERSION(13, 0, 4):
+   case IP_VERSION(13, 0, 11):
+   return 0;
+   default:
+   break;
+   }
+   }
+
/*
 * For gpu reset, runpm and hibernation through BACO,
 * BACO feature has to be kept enabled.
-- 
2.25.1



[PATCH RESEND] drm/amdgpu: skip psp suspend for IMU enabled ASICs mode2 reset

2023-01-20 Thread Tim Huang
The psp suspend & resume should be skipped to avoid destroy
the TMR and reload FWs again for IMU enabled APU ASICs.

Signed-off-by: Tim Huang 
Acked-by: Alex Deucher 
Reviewed-by: Mario Limonciello 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index efd4f8226120..0f9a5b12c3a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3036,6 +3036,18 @@ static int amdgpu_device_ip_suspend_phase2(struct 
amdgpu_device *adev)
(adev->ip_blocks[i].version->type == 
AMD_IP_BLOCK_TYPE_SDMA))
continue;
 
+   /* Once swPSP provides the IMU, RLC FW binaries to TOS during 
cold-boot.
+* These are in TMR, hence are expected to be reused by PSP-TOS 
to reload
+* from this location and RLC Autoload automatically also gets 
loaded
+* from here based on PMFW -> PSP message during re-init 
sequence.
+* Therefore, the psp suspend & resume should be skipped to 
avoid destroy
+* the TMR and reload FWs again for IMU enabled APU ASICs.
+*/
+   if (amdgpu_in_reset(adev) &&
+   (adev->flags & AMD_IS_APU) && adev->gfx.imu.funcs &&
+   adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)
+   continue;
+
/* XXX handle errors */
r = adev->ip_blocks[i].version->funcs->suspend(adev);
/* XXX handle errors */
-- 
2.25.1



[PATCH 1/2] drm/amdgpu: skip psp suspend for IMU enabled ASICs mode2 reset

2023-01-20 Thread Tim Huang
The psp suspend & resume should be skipped to avoid destroy
the TMR and reload FWs again for IMU enabled APU ASICs.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index efd4f8226120..0f9a5b12c3a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3036,6 +3036,18 @@ static int amdgpu_device_ip_suspend_phase2(struct 
amdgpu_device *adev)
(adev->ip_blocks[i].version->type == 
AMD_IP_BLOCK_TYPE_SDMA))
continue;
 
+   /* Once swPSP provides the IMU, RLC FW binaries to TOS during 
cold-boot.
+* These are in TMR, hence are expected to be reused by PSP-TOS 
to reload
+* from this location and RLC Autoload automatically also gets 
loaded
+* from here based on PMFW -> PSP message during re-init 
sequence.
+* Therefore, the psp suspend & resume should be skipped to 
avoid destroy
+* the TMR and reload FWs again for IMU enabled APU ASICs.
+*/
+   if (amdgpu_in_reset(adev) &&
+   (adev->flags & AMD_IS_APU) && adev->gfx.imu.funcs &&
+   adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP)
+   continue;
+
/* XXX handle errors */
r = adev->ip_blocks[i].version->funcs->suspend(adev);
/* XXX handle errors */
-- 
2.25.1



[PATCH 2/2] drm/amd/pm: drop unneeded dpm features disablement for SMU 13.0.4/11

2023-01-20 Thread Tim Huang
PMFW will handle that properly. Driver involvement may cause some
unexpected issues.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c 
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index ec52830dde24..800eb5ad1dcb 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
@@ -1448,6 +1448,8 @@ static int smu_disable_dpms(struct smu_context *smu)
case IP_VERSION(13, 0, 0):
case IP_VERSION(13, 0, 7):
case IP_VERSION(13, 0, 10):
+   case IP_VERSION(13, 0, 4):
+   case IP_VERSION(13, 0, 11):
return 0;
default:
break;
-- 
2.25.1



[PATCH v2] drm/amdgpu: skip mes self test after s0i3 resume for MES IP v11.0

2022-12-19 Thread Tim Huang
MES is part of gfxoff and MES suspend and resume are skipped for S0i3.
But the mes_self_test call path is still in the amdgpu_device_ip_late_init.
it's should also be skipped for s0ix as no hardware re-initialization
happened.

Besides, mes_self_test will free the BO that triggers a lot of warning
messages while in the suspend state.

[   81.656085] WARNING: CPU: 2 PID: 1550 at 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:425 amdgpu_bo_free_kernel+0xfc/0x110 
[amdgpu]
[   81.679435] Call Trace:
[   81.679726]  
[   81.679981]  amdgpu_mes_remove_hw_queue+0x17a/0x230 [amdgpu]
[   81.680857]  amdgpu_mes_self_test+0x390/0x430 [amdgpu]
[   81.681665]  mes_v11_0_late_init+0x37/0x50 [amdgpu]
[   81.682423]  amdgpu_device_ip_late_init+0x53/0x280 [amdgpu]
[   81.683257]  amdgpu_device_resume+0xae/0x2a0 [amdgpu]
[   81.684043]  amdgpu_pmops_resume+0x37/0x70 [amdgpu]
[   81.684818]  pci_pm_resume+0x5c/0xa0
[   81.685247]  ? pci_pm_thaw+0x90/0x90
[   81.685658]  dpm_run_callback+0x4e/0x160
[   81.686110]  device_resume+0xad/0x210
[   81.686529]  async_resume+0x1e/0x40
[   81.686931]  async_run_entry_fn+0x33/0x120
[   81.687405]  process_one_work+0x21d/0x3f0
[   81.687869]  worker_thread+0x4a/0x3c0
[   81.688293]  ? process_one_work+0x3f0/0x3f0
[   81.688777]  kthread+0xff/0x130
[   81.689157]  ? kthread_complete_and_exit+0x20/0x20
[   81.689707]  ret_from_fork+0x22/0x30
[   81.690118]  
[   81.690380] ---[ end trace  ]---

Signed-off-by: Tim Huang 

v2: make the comment clean and use adev->in_s0ix instead of
adev->suspend
---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index 5459366f49ff..970b066b37bb 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -1342,7 +1342,8 @@ static int mes_v11_0_late_init(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-   if (!amdgpu_in_reset(adev) &&
+   /* it's only intended for use in mes_self_test case, not for s0ix and 
reset */
+   if (!amdgpu_in_reset(adev) && !adev->in_s0ix &&
(adev->ip_versions[GC_HWIP][0] != IP_VERSION(11, 0, 3)))
amdgpu_mes_self_test(adev);
 
-- 
2.25.1



[PATCH] drm/amdgpu: skip mes self test after s0i3 resume for MES IP v11.0

2022-12-19 Thread Tim Huang
MES is part of gfxoff for S0i3 and does not require self-test after S0i3.
Besides, self-test will free the BO that triggers a wraning while in
the suspend state.

[   81.656085] WARNING: CPU: 2 PID: 1550 at 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:425 amdgpu_bo_free_kernel+0xfc/0x110 
[amdgpu]
[   81.679435] Call Trace:
[   81.679726]  
[   81.679981]  amdgpu_mes_remove_hw_queue+0x17a/0x230 [amdgpu]
[   81.680857]  amdgpu_mes_self_test+0x390/0x430 [amdgpu]
[   81.681665]  mes_v11_0_late_init+0x37/0x50 [amdgpu]
[   81.682423]  amdgpu_device_ip_late_init+0x53/0x280 [amdgpu]
[   81.683257]  amdgpu_device_resume+0xae/0x2a0 [amdgpu]
[   81.684043]  amdgpu_pmops_resume+0x37/0x70 [amdgpu]
[   81.684818]  pci_pm_resume+0x5c/0xa0
[   81.685247]  ? pci_pm_thaw+0x90/0x90
[   81.685658]  dpm_run_callback+0x4e/0x160
[   81.686110]  device_resume+0xad/0x210
[   81.686529]  async_resume+0x1e/0x40
[   81.686931]  async_run_entry_fn+0x33/0x120
[   81.687405]  process_one_work+0x21d/0x3f0
[   81.687869]  worker_thread+0x4a/0x3c0
[   81.688293]  ? process_one_work+0x3f0/0x3f0
[   81.688777]  kthread+0xff/0x130
[   81.689157]  ? kthread_complete_and_exit+0x20/0x20
[   81.689707]  ret_from_fork+0x22/0x30
[   81.690118]  
[   81.690380] ---[ end trace  ]---

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index 5459366f49ff..80e8cf826e71 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
@@ -1342,7 +1342,7 @@ static int mes_v11_0_late_init(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-   if (!amdgpu_in_reset(adev) &&
+   if (!amdgpu_in_reset(adev) && !adev->in_suspend &&
(adev->ip_versions[GC_HWIP][0] != IP_VERSION(11, 0, 3)))
amdgpu_mes_self_test(adev);
 
-- 
2.25.1



[PATCH 4/4] drm/amdgpu: add tmz support for GC IP v11.0.4

2022-12-05 Thread Tim Huang
Add tmz support for GC 11.0.4.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index e970e3760cec..02a4c93673ce 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -549,6 +549,7 @@ void amdgpu_gmc_tmz_set(struct amdgpu_device *adev)
/* YELLOW_CARP*/
case IP_VERSION(10, 3, 3):
case IP_VERSION(11, 0, 1):
+   case IP_VERSION(11, 0, 4):
/* Don't enable it by default yet.
 */
if (amdgpu_tmz < 1) {
-- 
2.25.1



[PATCH 3/4] drm/amdgpu: enable GFX Clock Gating control for GC IP v11.0.4

2022-12-05 Thread Tim Huang
Enable GFX IP v11.0.4 CG gate/ungate control.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index 506c285d5f49..a56c6e106d00 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -5116,6 +5116,7 @@ static int gfx_v11_0_set_clockgating_state(void *handle,
case IP_VERSION(11, 0, 1):
case IP_VERSION(11, 0, 2):
case IP_VERSION(11, 0, 3):
+   case IP_VERSION(11, 0, 4):
gfx_v11_0_update_gfx_clock_gating(adev,
state ==  AMD_CG_STATE_GATE);
break;
-- 
2.25.1



[PATCH 2/4] drm/amdgpu: enable GFX Power Gating for GC IP v11.0.4

2022-12-05 Thread Tim Huang
Enable GFX Power Gating control for GC IP v11.0.4.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index bf78440e1e70..506c285d5f49 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -5058,6 +5058,7 @@ static void gfx_v11_cntl_power_gating(struct 
amdgpu_device *adev, bool enable)
if (enable && (adev->pg_flags & AMD_PG_SUPPORT_GFX_PG)) {
switch (adev->ip_versions[GC_HWIP][0]) {
case IP_VERSION(11, 0, 1):
+   case IP_VERSION(11, 0, 4):
WREG32_SOC15(GC, 0, regRLC_PG_DELAY_3, 
RLC_PG_DELAY_3_DEFAULT_GC_11_0_1);
break;
default:
@@ -5091,6 +5092,7 @@ static int gfx_v11_0_set_powergating_state(void *handle,
amdgpu_gfx_off_ctrl(adev, enable);
break;
case IP_VERSION(11, 0, 1):
+   case IP_VERSION(11, 0, 4):
gfx_v11_cntl_pg(adev, enable);
amdgpu_gfx_off_ctrl(adev, enable);
break;
-- 
2.25.1



[PATCH 1/4] drm/amdgpu: enable GFX IP v11.0.4 CG support

2022-12-05 Thread Tim Huang
Add CG support for GFX/MC/HDP/ATHUB/IH/BIF.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/soc21.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c 
b/drivers/gpu/drm/amd/amdgpu/soc21.c
index 41b94c824717..7d5fdf450d0c 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
@@ -647,7 +647,23 @@ static int soc21_common_early_init(void *handle)
adev->external_rev_id = adev->rev_id + 0x20;
break;
case IP_VERSION(11, 0, 4):
-   adev->cg_flags = AMD_CG_SUPPORT_VCN_MGCG |
+   adev->cg_flags =
+   AMD_CG_SUPPORT_GFX_CGCG |
+   AMD_CG_SUPPORT_GFX_CGLS |
+   AMD_CG_SUPPORT_GFX_MGCG |
+   AMD_CG_SUPPORT_GFX_FGCG |
+   AMD_CG_SUPPORT_REPEATER_FGCG |
+   AMD_CG_SUPPORT_GFX_PERF_CLK |
+   AMD_CG_SUPPORT_MC_MGCG |
+   AMD_CG_SUPPORT_MC_LS |
+   AMD_CG_SUPPORT_HDP_MGCG |
+   AMD_CG_SUPPORT_HDP_LS |
+   AMD_CG_SUPPORT_ATHUB_MGCG |
+   AMD_CG_SUPPORT_ATHUB_LS |
+   AMD_CG_SUPPORT_IH_CG |
+   AMD_CG_SUPPORT_BIF_MGCG |
+   AMD_CG_SUPPORT_BIF_LS |
+   AMD_CG_SUPPORT_VCN_MGCG |
AMD_CG_SUPPORT_JPEG_MGCG;
adev->pg_flags = AMD_PG_SUPPORT_VCN |
AMD_PG_SUPPORT_GFX_PG |
-- 
2.25.1



[PATCH] drm/amd/pm: update SMU IP v13.0.4 msg interface header

2022-11-03 Thread Tim Huang
Some of the unused messages that were used earlier in development have
been freed up as spare messages, no intended functional changes.

Signed-off-by: Mario Limonciello 
Signed-off-by: Tim Huang 
---
 .../amd/pm/swsmu/inc/pmfw_if/smu_v13_0_4_ppsmc.h  | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_4_ppsmc.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_4_ppsmc.h
index d9b0cd752200..f4d6c07b56ea 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_4_ppsmc.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu_v13_0_4_ppsmc.h
@@ -54,14 +54,14 @@
 #define PPSMC_MSG_TestMessage   0x01 ///< To check if PMFW is 
alive and responding. Requirement specified by PMFW team
 #define PPSMC_MSG_GetPmfwVersion0x02 ///< Get PMFW version
 #define PPSMC_MSG_GetDriverIfVersion0x03 ///< Get PMFW_DRIVER_IF 
version
-#define PPSMC_MSG_EnableGfxOff  0x04 ///< Enable GFXOFF
-#define PPSMC_MSG_DisableGfxOff 0x05 ///< Disable GFXOFF
+#define PPSMC_MSG_SPARE00x04 ///< SPARE
+#define PPSMC_MSG_SPARE10x05 ///< SPARE
 #define PPSMC_MSG_PowerDownVcn  0x06 ///< Power down VCN
 #define PPSMC_MSG_PowerUpVcn0x07 ///< Power up VCN; VCN is 
power gated by default
 #define PPSMC_MSG_SetHardMinVcn 0x08 ///< For wireless display
 #define PPSMC_MSG_SetSoftMinGfxclk  0x09 ///< Set SoftMin for 
GFXCLK, argument is frequency in MHz
-#define PPSMC_MSG_ActiveProcessNotify   0x0A ///< Needs update
-#define PPSMC_MSG_ForcePowerDownGfx 0x0B ///< Force power down 
GFX, i.e. enter GFXOFF
+#define PPSMC_MSG_SPARE20x0A ///< SPARE
+#define PPSMC_MSG_SPARE30x0B ///< SPARE
 #define PPSMC_MSG_PrepareMp1ForUnload   0x0C ///< Prepare PMFW for GFX 
driver unload
 #define PPSMC_MSG_SetDriverDramAddrHigh 0x0D ///< Set high 32 bits of 
DRAM address for Driver table transfer
 #define PPSMC_MSG_SetDriverDramAddrLow  0x0E ///< Set low 32 bits of 
DRAM address for Driver table transfer
@@ -73,8 +73,7 @@
 #define PPSMC_MSG_SetSoftMinFclk0x14 ///< Set hard min for FCLK
 #define PPSMC_MSG_SetSoftMinVcn 0x15 ///< Set soft min for VCN 
clocks (VCLK and DCLK)
 
-
-#define PPSMC_MSG_EnableGfxImu  0x16 ///< Needs update
+#define PPSMC_MSG_EnableGfxImu  0x16 ///< Enable GFX IMU
 
 #define PPSMC_MSG_GetGfxclkFrequency0x17 ///< Get GFX clock 
frequency
 #define PPSMC_MSG_GetFclkFrequency  0x18 ///< Get FCLK frequency
@@ -102,8 +101,8 @@
 #define PPSMC_MSG_SetHardMinIspxclkByFreq   0x2C ///< Set HardMin by 
frequency for ISPXCLK
 #define PPSMC_MSG_PowerDownUmsch0x2D ///< Power down VCN.UMSCH 
(aka VSCH) scheduler
 #define PPSMC_MSG_PowerUpUmsch  0x2E ///< Power up VCN.UMSCH 
(aka VSCH) scheduler
-#define PPSMC_Message_IspStutterOn_MmhubPgDis   0x2F ///< ISP StutterOn mmHub 
PgDis
-#define PPSMC_Message_IspStutterOff_MmhubPgEn   0x30 ///< ISP StufferOff mmHub 
PgEn
+#define PPSMC_MSG_IspStutterOn_MmhubPgDis   0x2F ///< ISP StutterOn mmHub 
PgDis
+#define PPSMC_MSG_IspStutterOff_MmhubPgEn   0x30 ///< ISP StufferOff mmHub 
PgEn
 
 #define PPSMC_Message_Count 0x31 ///< Total number of 
PPSMC messages
 /** @}*/
-- 
2.25.1



[PATCH 1/2] drm/amd/pm: update SMU IP v13.0.4 driver interface version

2022-10-12 Thread Tim Huang
Update the SMU driver interface version to V7.

Signed-off-by: Tim Huang 
---
 .../swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
index ae2d337158f3..f77401709d83 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/pmfw_if/smu13_driver_if_v13_0_4.h
@@ -27,7 +27,7 @@
 // *** IMPORTANT ***
 // SMU TEAM: Always increment the interface version if
 // any structure is changed in this file
-#define PMFW_DRIVER_IF_VERSION 5
+#define PMFW_DRIVER_IF_VERSION 7
 
 typedef struct {
   int32_t value;
@@ -163,8 +163,8 @@ typedef struct {
   uint16_t DclkFrequency;   //[MHz]
   uint16_t MemclkFrequency; //[MHz]
   uint16_t spare;   //[centi]
-  uint16_t UvdActivity; //[centi]
   uint16_t GfxActivity; //[centi]
+  uint16_t UvdActivity; //[centi]
 
   uint16_t Voltage[2];  //[mV] indices: VDDCR_VDD, VDDCR_SOC
   uint16_t Current[2];  //[mA] indices: VDDCR_VDD, VDDCR_SOC
@@ -199,6 +199,19 @@ typedef struct {
   uint16_t DeviceState;
   uint16_t CurTemp; //[centi-Celsius]
   uint16_t spare2;
+
+  uint16_t AverageGfxclkFrequency;
+  uint16_t AverageFclkFrequency;
+  uint16_t AverageGfxActivity;
+  uint16_t AverageSocclkFrequency;
+  uint16_t AverageVclkFrequency;
+  uint16_t AverageVcnActivity;
+  uint16_t AverageDRAMReads;  //Filtered DF Bandwidth::DRAM Reads
+  uint16_t AverageDRAMWrites; //Filtered DF Bandwidth::DRAM Writes
+  uint16_t AverageSocketPower;//Filtered value of CurrentSocketPower
+  uint16_t AverageCorePower;  //Filtered of [sum of CorePower[8]])
+  uint16_t AverageCoreC0Residency[8]; //Filtered of [average C0 residency %  
per core]
+  uint32_t MetricsCounter;//Counts the # of metrics table 
parameter reads per update to the metrics table, i.e. if the metrics table 
update happens every 1 second, this value could be up to 1000 if the smu 
collected metrics data every cycle, or as low as 0 if the smu was asleep the 
whole time. Reset to 0 after writing.
 } SmuMetrics_t;
 
 typedef struct {
-- 
2.25.1



[PATCH 2/2] drm/amd/pm: add SMU IP v13.0.4 IF version define to V7

2022-10-12 Thread Tim Huang
The pmfw has changed the driver interface version, so keep same with the
fw.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h 
b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
index 9d62ea2af132..8f72202aea8e 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
+++ b/drivers/gpu/drm/amd/pm/swsmu/inc/smu_v13_0.h
@@ -28,7 +28,7 @@
 #define SMU13_DRIVER_IF_VERSION_INV 0x
 #define SMU13_DRIVER_IF_VERSION_YELLOW_CARP 0x04
 #define SMU13_DRIVER_IF_VERSION_ALDE 0x08
-#define SMU13_DRIVER_IF_VERSION_SMU_V13_0_4 0x05
+#define SMU13_DRIVER_IF_VERSION_SMU_V13_0_4 0x07
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_5 0x04
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_0 0x30
 #define SMU13_DRIVER_IF_VERSION_SMU_V13_0_7 0x2C
-- 
2.25.1



[PATCH] drm/amdgpu: add sdma instance check for gfx11 CGCG

2022-08-21 Thread Tim Huang
For some ASICs, like GFX IP v11.0.1, only have one SDMA instance,
so not need to configure SDMA1_RLC_CGCG_CTRL for this case.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index f45db80810fa..e8db772e068c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -5182,9 +5182,12 @@ static void 
gfx_v11_0_update_coarse_grain_clock_gating(struct amdgpu_device *ade
data = REG_SET_FIELD(data, SDMA0_RLC_CGCG_CTRL, 
CGCG_INT_ENABLE, 1);
WREG32_SOC15(GC, 0, regSDMA0_RLC_CGCG_CTRL, data);
 
-   data = RREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL);
-   data = REG_SET_FIELD(data, SDMA1_RLC_CGCG_CTRL, 
CGCG_INT_ENABLE, 1);
-   WREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL, data);
+   /* Some ASICs only have one SDMA instance, not need to 
configure SDMA1 */
+   if (adev->sdma.num_instances > 1) {
+   data = RREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL);
+   data = REG_SET_FIELD(data, SDMA1_RLC_CGCG_CTRL, 
CGCG_INT_ENABLE, 1);
+   WREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL, data);
+   }
} else {
/* Program RLC_CGCG_CGLS_CTRL */
def = data = RREG32_SOC15(GC, 0, regRLC_CGCG_CGLS_CTRL);
@@ -5213,9 +5216,12 @@ static void 
gfx_v11_0_update_coarse_grain_clock_gating(struct amdgpu_device *ade
data &= ~SDMA0_RLC_CGCG_CTRL__CGCG_INT_ENABLE_MASK;
WREG32_SOC15(GC, 0, regSDMA0_RLC_CGCG_CTRL, data);
 
-   data = RREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL);
-   data &= ~SDMA1_RLC_CGCG_CTRL__CGCG_INT_ENABLE_MASK;
-   WREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL, data);
+   /* Some ASICs only have one SDMA instance, not need to 
configure SDMA1 */
+   if (adev->sdma.num_instances > 1) {
+   data = RREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL);
+   data &= ~SDMA1_RLC_CGCG_CTRL__CGCG_INT_ENABLE_MASK;
+   WREG32_SOC15(GC, 0, regSDMA1_RLC_CGCG_CTRL, data);
+   }
}
 }
 
-- 
2.25.1



[PATCH 3/3] drm/amdgpu: enable NBIO IP v7.7.0 Clock Gating

2022-08-17 Thread Tim Huang
Enable AMD_CG_SUPPORT_BIF_MGCG and AMD_CG_SUPPORT_BIF_LS support.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/soc21.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c 
b/drivers/gpu/drm/amd/amdgpu/soc21.c
index 1ff7fc7bb340..982c12964879 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
@@ -603,6 +603,8 @@ static int soc21_common_early_init(void *handle)
AMD_CG_SUPPORT_ATHUB_MGCG |
AMD_CG_SUPPORT_ATHUB_LS |
AMD_CG_SUPPORT_IH_CG |
+   AMD_CG_SUPPORT_BIF_MGCG |
+   AMD_CG_SUPPORT_BIF_LS |
AMD_CG_SUPPORT_VCN_MGCG |
AMD_CG_SUPPORT_JPEG_MGCG;
adev->pg_flags =
@@ -702,6 +704,7 @@ static int soc21_common_set_clockgating_state(void *handle,
switch (adev->ip_versions[NBIO_HWIP][0]) {
case IP_VERSION(4, 3, 0):
case IP_VERSION(4, 3, 1):
+   case IP_VERSION(7, 7, 0):
adev->nbio.funcs->update_medium_grain_clock_gating(adev,
state == AMD_CG_STATE_GATE);
adev->nbio.funcs->update_medium_grain_light_sleep(adev,
@@ -709,10 +712,6 @@ static int soc21_common_set_clockgating_state(void *handle,
adev->hdp.funcs->update_clock_gating(adev,
state == AMD_CG_STATE_GATE);
break;
-   case IP_VERSION(7, 7, 0):
-   adev->hdp.funcs->update_clock_gating(adev,
-   state == AMD_CG_STATE_GATE);
-   break;
default:
break;
}
-- 
2.25.1



[PATCH 2/3] drm/amdgpu: add NBIO IP v7.7.0 Clock Gating support

2022-08-17 Thread Tim Huang
Add BIF Clock Gating MGCG and LS support for NBIO IP v7.7.0.

Signed-off-by: Tim Huang 
---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_7.c | 78 ++
 1 file changed, 78 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_7.c 
b/drivers/gpu/drm/amd/amdgpu/nbio_v7_7.c
index 01e8288d09a8..1dc95ef21da6 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_7.c
@@ -247,6 +247,81 @@ static void nbio_v7_7_init_registers(struct amdgpu_device 
*adev)
 
 }
 
+static void nbio_v7_7_update_medium_grain_clock_gating(struct amdgpu_device 
*adev,
+  bool enable)
+{
+   uint32_t def, data;
+
+   if (enable && !(adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG))
+   return;
+
+   def = data = RREG32_SOC15(NBIO, 0, regBIF0_CPM_CONTROL);
+   if (enable) {
+   data |= (BIF0_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
+BIF0_CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
+BIF0_CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
+BIF0_CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
+BIF0_CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
+BIF0_CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
+   } else {
+   data &= ~(BIF0_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
+ BIF0_CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
+ BIF0_CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
+ BIF0_CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
+ BIF0_CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
+ BIF0_CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
+   }
+
+   if (def != data)
+   WREG32_SOC15(NBIO, 0, regBIF0_CPM_CONTROL, data);
+}
+
+static void nbio_v7_7_update_medium_grain_light_sleep(struct amdgpu_device 
*adev,
+ bool enable)
+{
+   uint32_t def, data;
+
+   if (enable && !(adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
+   return;
+
+   def = data = RREG32_SOC15(NBIO, 0, regBIF0_PCIE_CNTL2);
+   if (enable)
+   data |= BIF0_PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
+   else
+   data &= ~BIF0_PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
+
+   if (def != data)
+   WREG32_SOC15(NBIO, 0, regBIF0_PCIE_CNTL2, data);
+
+   def = data = RREG32_SOC15(NBIO, 0, regBIF0_PCIE_TX_POWER_CTRL_1);
+   if (enable) {
+   data |= (BIF0_PCIE_TX_POWER_CTRL_1__MST_MEM_LS_EN_MASK |
+   BIF0_PCIE_TX_POWER_CTRL_1__REPLAY_MEM_LS_EN_MASK);
+   } else {
+   data &= ~(BIF0_PCIE_TX_POWER_CTRL_1__MST_MEM_LS_EN_MASK |
+   BIF0_PCIE_TX_POWER_CTRL_1__REPLAY_MEM_LS_EN_MASK);
+   }
+
+   if (def != data)
+   WREG32_SOC15(NBIO, 0, regBIF0_PCIE_TX_POWER_CTRL_1, data);
+}
+
+static void nbio_v7_7_get_clockgating_state(struct amdgpu_device *adev,
+   u64 *flags)
+{
+   uint32_t data;
+
+   /* AMD_CG_SUPPORT_BIF_MGCG */
+   data = RREG32_SOC15(NBIO, 0, regBIF0_CPM_CONTROL);
+   if (data & BIF0_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK)
+   *flags |= AMD_CG_SUPPORT_BIF_MGCG;
+
+   /* AMD_CG_SUPPORT_BIF_LS */
+   data = RREG32_SOC15(NBIO, 0, regBIF0_PCIE_CNTL2);
+   if (data & BIF0_PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
+   *flags |= AMD_CG_SUPPORT_BIF_LS;
+}
+
 const struct amdgpu_nbio_funcs nbio_v7_7_funcs = {
.get_hdp_flush_req_offset = nbio_v7_7_get_hdp_flush_req_offset,
.get_hdp_flush_done_offset = nbio_v7_7_get_hdp_flush_done_offset,
@@ -262,6 +337,9 @@ const struct amdgpu_nbio_funcs nbio_v7_7_funcs = {
.enable_doorbell_aperture = nbio_v7_7_enable_doorbell_aperture,
.enable_doorbell_selfring_aperture = 
nbio_v7_7_enable_doorbell_selfring_aperture,
.ih_doorbell_range = nbio_v7_7_ih_doorbell_range,
+   .update_medium_grain_clock_gating = 
nbio_v7_7_update_medium_grain_clock_gating,
+   .update_medium_grain_light_sleep = 
nbio_v7_7_update_medium_grain_light_sleep,
+   .get_clockgating_state = nbio_v7_7_get_clockgating_state,
.ih_control = nbio_v7_7_ih_control,
.init_registers = nbio_v7_7_init_registers,
 };
-- 
2.25.1



  1   2   >