[PATCH] drm/amd/powerplay: add Vega20 LCLK DPM level setting support

2018-12-18 Thread Evan Quan
Support manual LCLK DPM level switch on Vega20.

Change-Id: I4c6ea6356a90ef6d99f39f7a5cd5cdcb89846d32
Signed-off-by: Evan Quan 
Acked-by: Alex Deucher 
Reviewed-by: Rex Zhu 
Reviewed-by: Feifei Xu 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 43 +++
 1 file changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 15788c6486b1..fa57c678e2cf 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -49,6 +49,10 @@
 #include "soc15_common.h"
 #include "smuio/smuio_9_0_offset.h"
 #include "smuio/smuio_9_0_sh_mask.h"
+#include "nbio/nbio_7_4_sh_mask.h"
+
+#define smnPCIE_LC_SPEED_CNTL  0x11140290
+#define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
 
 static void vega20_set_default_registry_data(struct pp_hwmgr *hwmgr)
 {
@@ -2272,6 +2276,18 @@ static int vega20_force_clock_level(struct pp_hwmgr 
*hwmgr,
break;
 
case PP_PCIE:
+   soft_min_level = mask ? (ffs(mask) - 1) : 0;
+   soft_max_level = mask ? (fls(mask) - 1) : 0;
+   if (soft_min_level >= NUM_LINK_LEVELS ||
+   soft_max_level >= NUM_LINK_LEVELS)
+   return -EINVAL;
+
+   ret = smum_send_msg_to_smc_with_parameter(hwmgr,
+   PPSMC_MSG_SetMinLinkDpmByIndex, soft_min_level);
+   PP_ASSERT_WITH_CODE(!ret,
+   "Failed to set min link dpm level!",
+   return ret);
+
break;
 
default:
@@ -2748,9 +2764,14 @@ static int vega20_print_clock_levels(struct pp_hwmgr 
*hwmgr,
data->od8_settings.od8_settings_array;
OverDriveTable_t *od_table =
&(data->smc_state_table.overdrive_table);
+   struct phm_ppt_v3_information *pptable_information =
+   (struct phm_ppt_v3_information *)hwmgr->pptable;
+   PPTable_t *pptable = (PPTable_t *)pptable_information->smc_pptable;
+   struct amdgpu_device *adev = hwmgr->adev;
struct pp_clock_levels_with_latency clocks;
int i, now, size = 0;
int ret = 0;
+   uint32_t gen_speed, lane_width;
 
switch (type) {
case PP_SCLK:
@@ -2788,6 +2809,28 @@ static int vega20_print_clock_levels(struct pp_hwmgr 
*hwmgr,
break;
 
case PP_PCIE:
+   gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
+
PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
+   >> 
PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
+   lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
+ PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
+   >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
+   for (i = 0; i < NUM_LINK_LEVELS; i++)
+   size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
+   (pptable->PcieGenSpeed[i] == 0) ? 
"2.5GT/s," :
+   (pptable->PcieGenSpeed[i] == 1) ? 
"5.0GT/s," :
+   (pptable->PcieGenSpeed[i] == 2) ? 
"8.0GT/s," :
+   (pptable->PcieGenSpeed[i] == 3) ? 
"16.0GT/s," : "",
+   (pptable->PcieLaneCount[i] == 1) ? "x1" 
:
+   (pptable->PcieLaneCount[i] == 2) ? "x2" 
:
+   (pptable->PcieLaneCount[i] == 3) ? "x4" 
:
+   (pptable->PcieLaneCount[i] == 4) ? "x8" 
:
+   (pptable->PcieLaneCount[i] == 5) ? 
"x12" :
+   (pptable->PcieLaneCount[i] == 6) ? 
"x16" : "",
+   pptable->LclkFreq[i],
+   (gen_speed == pptable->PcieGenSpeed[i]) 
&&
+   (lane_width == 
pptable->PcieLaneCount[i]) ?
+   "*" : "");
break;
 
case OD_SCLK:
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: add Vega20 PSP ASD firmware loading

2018-12-20 Thread Evan Quan
Add PSP ASD firmware loading on Vega20. Not sure why
this was missing before.

Change-Id: I047bee28323b5b3bf54b4eec6f7089406b2e07e1
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c | 40 --
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c
index 138d552bb022..0c6e7f9b143f 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c
@@ -34,6 +34,7 @@
 #include "nbio/nbio_7_4_offset.h"
 
 MODULE_FIRMWARE("amdgpu/vega20_sos.bin");
+MODULE_FIRMWARE("amdgpu/vega20_asd.bin");
 MODULE_FIRMWARE("amdgpu/vega20_ta.bin");
 
 /* address block */
@@ -100,6 +101,7 @@ static int psp_v11_0_init_microcode(struct psp_context *psp)
char fw_name[30];
int err = 0;
const struct psp_firmware_header_v1_0 *sos_hdr;
+   const struct psp_firmware_header_v1_0 *asd_hdr;
const struct ta_firmware_header_v1_0 *ta_hdr;
 
DRM_DEBUG("\n");
@@ -132,14 +134,30 @@ static int psp_v11_0_init_microcode(struct psp_context 
*psp)
adev->psp.sos_start_addr = (uint8_t *)adev->psp.sys_start_addr +
le32_to_cpu(sos_hdr->sos_offset_bytes);
 
+   snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_asd.bin", chip_name);
+   err = request_firmware(&adev->psp.asd_fw, fw_name, adev->dev);
+   if (err)
+   goto out1;
+
+   err = amdgpu_ucode_validate(adev->psp.asd_fw);
+   if (err)
+   goto out1;
+
+   asd_hdr = (const struct psp_firmware_header_v1_0 
*)adev->psp.asd_fw->data;
+   adev->psp.asd_fw_version = le32_to_cpu(asd_hdr->header.ucode_version);
+   adev->psp.asd_feature_version = 
le32_to_cpu(asd_hdr->ucode_feature_version);
+   adev->psp.asd_ucode_size = 
le32_to_cpu(asd_hdr->header.ucode_size_bytes);
+   adev->psp.asd_start_addr = (uint8_t *)asd_hdr +
+   
le32_to_cpu(asd_hdr->header.ucode_array_offset_bytes);
+
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ta.bin", chip_name);
err = request_firmware(&adev->psp.ta_fw, fw_name, adev->dev);
if (err)
-   goto out;
+   goto out2;
 
err = amdgpu_ucode_validate(adev->psp.ta_fw);
if (err)
-   goto out;
+   goto out2;
 
ta_hdr = (const struct ta_firmware_header_v1_0 *)adev->psp.ta_fw->data;
adev->psp.ta_xgmi_ucode_version = 
le32_to_cpu(ta_hdr->ta_xgmi_ucode_version);
@@ -148,14 +166,18 @@ static int psp_v11_0_init_microcode(struct psp_context 
*psp)
le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
 
return 0;
+
+out2:
+   release_firmware(adev->psp.ta_fw);
+   adev->psp.ta_fw = NULL;
+out1:
+   release_firmware(adev->psp.asd_fw);
+   adev->psp.asd_fw = NULL;
 out:
-   if (err) {
-   dev_err(adev->dev,
-   "psp v11.0: Failed to load firmware \"%s\"\n",
-   fw_name);
-   release_firmware(adev->psp.sos_fw);
-   adev->psp.sos_fw = NULL;
-   }
+   dev_err(adev->dev,
+   "psp v11.0: Failed to load firmware \"%s\"\n", fw_name);
+   release_firmware(adev->psp.sos_fw);
+   adev->psp.sos_fw = NULL;
 
return err;
 }
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: support BOOTUP_DEFAULT power profile mode

2018-12-26 Thread Evan Quan
This can avoid unexpected profile mode change after running
compute workload.

Change-Id: I138e8747e4f588a6fb38b9c68f765bb653556dc0
Signed-off-by: Evan Quan 
---
 .../gpu/drm/amd/include/kgd_pp_interface.h| 13 +-
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c   | 24 ++-
 .../gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c  |  8 ---
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.c| 12 ++
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 10 +---
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h |  2 +-
 6 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 1479ea1dc3e7..789c4f288485 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -127,12 +127,13 @@ enum amd_pp_task {
 };
 
 enum PP_SMC_POWER_PROFILE {
-   PP_SMC_POWER_PROFILE_FULLSCREEN3D = 0x0,
-   PP_SMC_POWER_PROFILE_POWERSAVING  = 0x1,
-   PP_SMC_POWER_PROFILE_VIDEO= 0x2,
-   PP_SMC_POWER_PROFILE_VR   = 0x3,
-   PP_SMC_POWER_PROFILE_COMPUTE  = 0x4,
-   PP_SMC_POWER_PROFILE_CUSTOM   = 0x5,
+   PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT = 0x0,
+   PP_SMC_POWER_PROFILE_FULLSCREEN3D = 0x1,
+   PP_SMC_POWER_PROFILE_POWERSAVING  = 0x2,
+   PP_SMC_POWER_PROFILE_VIDEO= 0x3,
+   PP_SMC_POWER_PROFILE_VR   = 0x4,
+   PP_SMC_POWER_PROFILE_COMPUTE  = 0x5,
+   PP_SMC_POWER_PROFILE_CUSTOM   = 0x6,
 };
 
 enum {
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
index 0173d0480024..310b102a9292 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
@@ -64,17 +64,19 @@ static int ci_set_asic_special_caps(struct pp_hwmgr *hwmgr);
 
 static void hwmgr_init_workload_prority(struct pp_hwmgr *hwmgr)
 {
-   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D] = 2;
-   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_POWERSAVING] = 0;
-   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_VIDEO] = 1;
-   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_VR] = 3;
-   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_COMPUTE] = 4;
-
-   hwmgr->workload_setting[0] = PP_SMC_POWER_PROFILE_POWERSAVING;
-   hwmgr->workload_setting[1] = PP_SMC_POWER_PROFILE_VIDEO;
-   hwmgr->workload_setting[2] = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
-   hwmgr->workload_setting[3] = PP_SMC_POWER_PROFILE_VR;
-   hwmgr->workload_setting[4] = PP_SMC_POWER_PROFILE_COMPUTE;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT] = 0;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D] = 1;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_POWERSAVING] = 2;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_VIDEO] = 3;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_VR] = 4;
+   hwmgr->workload_prority[PP_SMC_POWER_PROFILE_COMPUTE] = 5;
+
+   hwmgr->workload_setting[0] = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
+   hwmgr->workload_setting[1] = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
+   hwmgr->workload_setting[2] = PP_SMC_POWER_PROFILE_POWERSAVING;
+   hwmgr->workload_setting[3] = PP_SMC_POWER_PROFILE_VIDEO;
+   hwmgr->workload_setting[4] = PP_SMC_POWER_PROFILE_VR;
+   hwmgr->workload_setting[5] = PP_SMC_POWER_PROFILE_COMPUTE;
 }
 
 int hwmgr_early_init(struct pp_hwmgr *hwmgr)
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index d91390459326..c8f5c00dd1e7 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -77,8 +77,9 @@
 #define PCIE_BUS_CLK1
 #define TCLK(PCIE_BUS_CLK / 10)
 
-static const struct profile_mode_setting smu7_profiling[6] =
-   {{1, 0, 100, 30, 1, 0, 100, 10},
+static const struct profile_mode_setting smu7_profiling[7] =
+   {{0, 0, 0, 0, 0, 0, 0, 0},
+{1, 0, 100, 30, 1, 0, 100, 10},
 {1, 10, 0, 30, 0, 0, 0, 0},
 {0, 0, 0, 0, 1, 10, 16, 31},
 {1, 0, 11, 50, 1, 0, 100, 10},
@@ -4889,7 +4890,8 @@ static int smu7_get_power_profile_mode(struct pp_hwmgr 
*hwmgr, char *buf)
uint32_t i, size = 0;
uint32_t len;
 
-   static const char *profile_name[6] = {"3D_FULL_SCREEN",
+   static const char *profile_name[7] = {"BOOTUP_DEFAULT",
+   "3D_FULL_SCREEN",
"POWER_SAVING",
 

[PATCH 9/9] drm/amdgpu: move psp_funcs related to a more proper place

2019-01-02 Thread Evan Quan
As there is no need to expose these through amdgpu_psp.h.
So, it's better to make them PSP internal used only.

Change-Id: I571be7aae8807f11a6d594be7762306b56403f82
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 96 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 73 +++---
 drivers/gpu/drm/amd/amdgpu/psp_cmn.h| 43 +++
 drivers/gpu/drm/amd/amdgpu/psp_funcs.h  | 98 +
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   |  2 +-
 7 files changed, 197 insertions(+), 119 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_funcs.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index ecfbf618652a..3b46334fa849 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -32,57 +32,8 @@
 #include "psp_v3_1.h"
 #include "psp_v10_0.h"
 #include "psp_v11_0.h"
-
-#define psp_ring_init(psp, type) \
-   (psp)->funcs->ring_init((psp), (type))
-#define psp_ring_create(psp, type) \
-   (psp)->funcs->ring_create((psp), (type))
-#define psp_ring_stop(psp, type) \
-   (psp)->funcs->ring_stop((psp), (type))
-#define psp_ring_destroy(psp, type) \
-   ((psp)->funcs->ring_destroy((psp), (type)))
-#define psp_prep_cmd_buf(ucode, cmd) \
-   (psp)->funcs->prep_cmd_buf((ucode), (cmd))
-#define psp_submit_cmd_buf(psp, ucode, cmd, fence_mc) \
-   (psp)->funcs->submit_cmd_buf((psp), (ucode), (cmd), (fence_mc))
-#define psp_support_vmr_ring(psp) \
-   ((psp)->funcs->support_vmr_ring ? 
(psp)->funcs->support_vmr_ring((psp)) : false)
-#define psp_init_asd(psp) \
-   ((psp)->funcs->asd_init ? (psp)->funcs->asd_init((psp)) : 0)
-#define psp_load_asd(psp) \
-   ((psp)->funcs->asd_load ? (psp)->funcs->asd_load((psp)) : 0)
-#define psp_unload_asd(psp) \
-   ((psp)->funcs->asd_unload ? (psp)->funcs->asd_unload((psp)) : 0)
-#define psp_destory_asd(psp) \
-   ((psp)->funcs->asd_destory ? (psp)->funcs->asd_destory((psp)) : 
0)
-#define psp_init_tmr(psp) \
-   ((psp)->funcs->tmr_init ? (psp)->funcs->tmr_init((psp)) : 0)
-#define psp_load_tmr(psp) \
-   ((psp)->funcs->tmr_load ? (psp)->funcs->tmr_load((psp)) : 0)
-#define psp_unload_tmr(psp) \
-   ((psp)->funcs->tmr_unload ? (psp)->funcs->tmr_unload((psp)) : 0)
-#define psp_destory_tmr(psp) \
-   ((psp)->funcs->tmr_destory ? (psp)->funcs->tmr_destory((psp)) : 
0)
-#define psp_init_xgmi(psp) \
-   ((psp)->funcs->xgmi_init ? (psp)->funcs->xgmi_init((psp)) : 0)
-#define psp_load_xgmi(psp) \
-   ((psp)->funcs->xgmi_load ? (psp)->funcs->xgmi_load((psp)) : 0)
-#define psp_unload_xgmi(psp) \
-   ((psp)->funcs->xgmi_unload ? (psp)->funcs->xgmi_unload((psp)) : 
0)
-#define psp_destory_xgmi(psp) \
-   ((psp)->funcs->xgmi_destory ? (psp)->funcs->xgmi_destory((psp)) 
: 0)
-#define psp_compare_sram_data(psp, ucode, type) \
-   (psp)->funcs->compare_sram_data((psp), (ucode), (type))
-#define psp_init_microcode(psp) \
-   ((psp)->funcs->init_microcode ? 
(psp)->funcs->init_microcode((psp)) : 0)
-#define psp_bootloader_load_sysdrv(psp) \
-   ((psp)->funcs->bootloader_load_sysdrv ? 
(psp)->funcs->bootloader_load_sysdrv((psp)) : 0)
-#define psp_bootloader_load_sos(psp) \
-   ((psp)->funcs->bootloader_load_sos ? 
(psp)->funcs->bootloader_load_sos((psp)) : 0)
-#define psp_smu_reload_quirk(psp) \
-   ((psp)->funcs->smu_reload_quirk ? 
(psp)->funcs->smu_reload_quirk((psp)) : false)
-#define psp_mode1_reset(psp) \
-   ((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : 
false)
+#include "psp_cmn.h"
+#include "psp_funcs.h"
 
 static int psp_sw_init(void *handle)
 {
@@ -417,7 +368,6 @@ int psp_gpu_reset(struct amdgpu_device *adev)
return psp_mode1_reset(&adev->psp);
 }
 
-
 static int psp_set_clockgating_state(void *handle,
 enum amd_clockgating_state state)
 {
@@ -430,6 +380,48 @@ static int psp_set_powergating_state(void *handle,
return 0;
 }
 
+int psp_xgmi_get_topology_info(struct psp_context *psp,
+   int number_devices, struct psp_xgmi_topology_info *topology)
+{
+   const struct psp_funcs *funcs = (const struct psp_funcs *)(psp->priv);
+
+   if (!funcs->xgmi_get_topology_info)
+   return -EINVAL;
+
+   return f

[PATCH 6/9] drm/amdgpu: drop useless PSP APIs and structures

2019-01-02 Thread Evan Quan
Drop those useless APIs and structures.

Change-Id: I1350c0e7ec0b990a1178a0ce92f61e56dc8851b5
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 66 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  5 --
 2 files changed, 22 insertions(+), 49 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 2528fbcad275..f1ffe04b8c0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -62,19 +62,6 @@
((psp)->funcs->smu_reload_quirk ? 
(psp)->funcs->smu_reload_quirk((psp)) : false)
 #define psp_mode1_reset(psp) \
((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : 
false)
-#define amdgpu_psp_check_fw_loading_status(adev, i) \
-   (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
-
-static void psp_set_funcs(struct amdgpu_device *adev);
-
-static int psp_early_init(void *handle)
-{
-   struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-
-   psp_set_funcs(adev);
-
-   return 0;
-}
 
 static int psp_sw_init(void *handle)
 {
@@ -166,6 +153,26 @@ static int psp_hw_start(struct psp_context *psp)
return 0;
 }
 
+static bool psp_check_fw_loading_status(struct amdgpu_device *adev,
+   enum AMDGPU_UCODE_ID ucode_type)
+{
+   struct amdgpu_firmware_info *ucode = NULL;
+
+   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
+   DRM_INFO("firmware is not loaded by PSP\n");
+   return true;
+   }
+
+   if (!adev->firmware.fw_size)
+   return false;
+
+   ucode = &adev->firmware.ucode[ucode_type];
+   if (!ucode->fw || !ucode->ucode_size)
+   return false;
+
+   return psp_compare_sram_data(&adev->psp, ucode, ucode_type);
+}
+
 static int psp_np_fw_load(struct psp_context *psp)
 {
int i, ret;
@@ -198,7 +205,7 @@ static int psp_np_fw_load(struct psp_context *psp)
 
 #if 0
/* check if firmware loaded sucessfully */
-   if (!amdgpu_psp_check_fw_loading_status(adev, i))
+   if (!psp_check_fw_loading_status(adev, i))
return -EINVAL;
 #endif
}
@@ -413,25 +420,6 @@ int psp_gpu_reset(struct amdgpu_device *adev)
return psp_mode1_reset(&adev->psp);
 }
 
-static bool psp_check_fw_loading_status(struct amdgpu_device *adev,
-   enum AMDGPU_UCODE_ID ucode_type)
-{
-   struct amdgpu_firmware_info *ucode = NULL;
-
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
-   DRM_INFO("firmware is not loaded by PSP\n");
-   return true;
-   }
-
-   if (!adev->firmware.fw_size)
-   return false;
-
-   ucode = &adev->firmware.ucode[ucode_type];
-   if (!ucode->fw || !ucode->ucode_size)
-   return false;
-
-   return psp_compare_sram_data(&adev->psp, ucode, ucode_type);
-}
 
 static int psp_set_clockgating_state(void *handle,
 enum amd_clockgating_state state)
@@ -447,7 +435,7 @@ static int psp_set_powergating_state(void *handle,
 
 const struct amd_ip_funcs psp_ip_funcs = {
.name = "psp",
-   .early_init = psp_early_init,
+   .early_init = NULL,
.late_init = NULL,
.sw_init = psp_sw_init,
.sw_fini = psp_sw_fini,
@@ -463,16 +451,6 @@ const struct amd_ip_funcs psp_ip_funcs = {
.set_powergating_state = psp_set_powergating_state,
 };
 
-static const struct amdgpu_psp_funcs psp_funcs = {
-   .check_fw_loading_status = psp_check_fw_loading_status,
-};
-
-static void psp_set_funcs(struct amdgpu_device *adev)
-{
-   if (NULL == adev->firmware.funcs)
-   adev->firmware.funcs = &psp_funcs;
-}
-
 const struct amdgpu_ip_block_version psp_v3_1_ip_block =
 {
.type = AMD_IP_BLOCK_TYPE_PSP,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index d65691b988fa..16900d4c8034 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -157,11 +157,6 @@ struct psp_context
struct psp_xgmi_context xgmi_context;
 };
 
-struct amdgpu_psp_funcs {
-   bool (*check_fw_loading_status)(struct amdgpu_device *adev,
-   enum AMDGPU_UCODE_ID);
-};
-
 #define AMDGPU_XGMI_MAX_CONNECTED_NODES64
 struct psp_xgmi_node_info {
uint64_tnode_id;
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 7/9] drm/amdgpu: check PSP support before adding the ip block

2019-01-02 Thread Evan Quan
So that we do not need to check this in every internal function.

Change-Id: I5f2665cf60a57b6ae8d04a645f633daf377ae28c
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 24 
 drivers/gpu/drm/amd/amdgpu/soc15.c  | 13 -
 2 files changed, 8 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index f1ffe04b8c0f..bf51686bdd0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -86,9 +86,6 @@ static int psp_sw_init(void *handle)
 
psp->adev = adev;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
ret = psp_init_microcode(psp);
if (ret) {
DRM_ERROR("Failed to load psp firmware!\n");
@@ -102,9 +99,6 @@ static int psp_sw_fini(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
release_firmware(adev->psp.sos_fw);
adev->psp.sos_fw = NULL;
release_firmware(adev->psp.asd_fw);
@@ -158,11 +152,6 @@ static bool psp_check_fw_loading_status(struct 
amdgpu_device *adev,
 {
struct amdgpu_firmware_info *ucode = NULL;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
-   DRM_INFO("firmware is not loaded by PSP\n");
-   return true;
-   }
-
if (!adev->firmware.fw_size)
return false;
 
@@ -296,10 +285,6 @@ static int psp_hw_init(void *handle)
int ret;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
mutex_lock(&adev->firmware.mutex);
/*
 * This sequence is just used on hw_init only once, no need on
@@ -329,9 +314,6 @@ static int psp_hw_fini(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1)
 psp_xgmi_terminate(psp);
@@ -360,9 +342,6 @@ static int psp_suspend(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1) {
ret = psp_xgmi_terminate(psp);
@@ -387,9 +366,6 @@ static int psp_resume(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
DRM_INFO("PSP is resuming...\n");
 
mutex_lock(&adev->firmware.mutex);
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index d5b3f821b8f0..9f162a8a7d9b 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -535,10 +535,12 @@ int soc15_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
-   if (adev->asic_type == CHIP_VEGA20)
-   amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
-   else
-   amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
+   if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
+   if (adev->asic_type == CHIP_VEGA20)
+   amdgpu_device_ip_block_add(adev, 
&psp_v11_0_ip_block);
+   else
+   amdgpu_device_ip_block_add(adev, 
&psp_v3_1_ip_block);
+   }
amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
if (!amdgpu_sriov_vf(adev))
@@ -560,7 +562,8 @@ int soc15_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
-   amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
+   if (likely(adev->firmware.load_type == AMDGPU_FW_LOA

[PATCH 8/9] drm/amdgpu: make PSP sub modules(ASD/XGMI/TMR) support configurable

2019-01-02 Thread Evan Quan
As not every generation can support all these PSP sub modules.

Change-Id: I866884e6453a37ff844427eb2d6fd56a91058ebe
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 41 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 14 -
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c  |  6 
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  |  8 +
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   |  6 
 5 files changed, 64 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index bf51686bdd0f..ecfbf618652a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -32,9 +32,6 @@
 #include "psp_v3_1.h"
 #include "psp_v10_0.h"
 #include "psp_v11_0.h"
-#include "psp_xgmi.h"
-#include "psp_tmr.h"
-#include "psp_asd.h"
 
 #define psp_ring_init(psp, type) \
(psp)->funcs->ring_init((psp), (type))
@@ -50,6 +47,30 @@
(psp)->funcs->submit_cmd_buf((psp), (ucode), (cmd), (fence_mc))
 #define psp_support_vmr_ring(psp) \
((psp)->funcs->support_vmr_ring ? 
(psp)->funcs->support_vmr_ring((psp)) : false)
+#define psp_init_asd(psp) \
+   ((psp)->funcs->asd_init ? (psp)->funcs->asd_init((psp)) : 0)
+#define psp_load_asd(psp) \
+   ((psp)->funcs->asd_load ? (psp)->funcs->asd_load((psp)) : 0)
+#define psp_unload_asd(psp) \
+   ((psp)->funcs->asd_unload ? (psp)->funcs->asd_unload((psp)) : 0)
+#define psp_destory_asd(psp) \
+   ((psp)->funcs->asd_destory ? (psp)->funcs->asd_destory((psp)) : 
0)
+#define psp_init_tmr(psp) \
+   ((psp)->funcs->tmr_init ? (psp)->funcs->tmr_init((psp)) : 0)
+#define psp_load_tmr(psp) \
+   ((psp)->funcs->tmr_load ? (psp)->funcs->tmr_load((psp)) : 0)
+#define psp_unload_tmr(psp) \
+   ((psp)->funcs->tmr_unload ? (psp)->funcs->tmr_unload((psp)) : 0)
+#define psp_destory_tmr(psp) \
+   ((psp)->funcs->tmr_destory ? (psp)->funcs->tmr_destory((psp)) : 
0)
+#define psp_init_xgmi(psp) \
+   ((psp)->funcs->xgmi_init ? (psp)->funcs->xgmi_init((psp)) : 0)
+#define psp_load_xgmi(psp) \
+   ((psp)->funcs->xgmi_load ? (psp)->funcs->xgmi_load((psp)) : 0)
+#define psp_unload_xgmi(psp) \
+   ((psp)->funcs->xgmi_unload ? (psp)->funcs->xgmi_unload((psp)) : 
0)
+#define psp_destory_xgmi(psp) \
+   ((psp)->funcs->xgmi_destory ? (psp)->funcs->xgmi_destory((psp)) 
: 0)
 #define psp_compare_sram_data(psp, ucode, type) \
(psp)->funcs->compare_sram_data((psp), (ucode), (type))
 #define psp_init_microcode(psp) \
@@ -127,16 +148,16 @@ static int psp_hw_start(struct psp_context *psp)
if (ret)
return ret;
 
-   ret = psp_tmr_load(psp);
+   ret = psp_load_tmr(psp);
if (ret)
return ret;
 
-   ret = psp_asd_load(psp);
+   ret = psp_load_asd(psp);
if (ret)
return ret;
 
if (adev->gmc.xgmi.num_physical_nodes > 1) {
-   ret = psp_xgmi_initialize(psp);
+   ret = psp_init_xgmi(psp);
/* Warning the XGMI seesion initialize failure
 * Instead of stop driver initialization
 */
@@ -245,11 +266,11 @@ static int psp_load_fw(struct amdgpu_device *adev)
if (ret)
goto failed_mem;
 
-   ret = psp_tmr_init(psp);
+   ret = psp_init_tmr(psp);
if (ret)
goto failed_mem;
 
-   ret = psp_asd_init(psp);
+   ret = psp_init_asd(psp);
if (ret)
goto failed_mem;
 
@@ -316,7 +337,7 @@ static int psp_hw_fini(void *handle)
 
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1)
-psp_xgmi_terminate(psp);
+psp_destory_xgmi(psp);
 
psp_ring_destroy(psp, PSP_RING_TYPE__KM);
 
@@ -344,7 +365,7 @@ static int psp_suspend(void *handle)
 
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1) {
-   ret = psp_xgmi_terminate(psp);
+   ret = psp_destory_xgmi(psp);
if (ret) {
DRM_ERROR("Failed to terminate xgmi ta\n");
return ret;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index 16900d4c8034..4cc7fd3224f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -77,6 +77,19 @@ struct psp_funcs
int (*submit_cmd_buf)(struct psp_context *psp,
   struc

[PATCH 1/9] drm/amdgpu: separate the PSP ring related APIs

2019-01-02 Thread Evan Quan
So that they can be shared among different PSP generations.
And there is no need to have one copy for each PSP generation.

Change-Id: I7a97f410ef5993b25f0ec3cfac4a293073d697c3
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c |  71 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  16 +-
 drivers/gpu/drm/amd/amdgpu/psp_ring.c   | 353 
 drivers/gpu/drm/amd/amdgpu/psp_ring.h   |  43 +++
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c  | 247 +
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 278 +--
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 231 +---
 8 files changed, 444 insertions(+), 798 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_ring.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_ring.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 007478905c7b..bdcf0d4338f8 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -90,7 +90,8 @@ amdgpu-y += \
amdgpu_psp.o \
psp_v3_1.o \
psp_v10_0.o \
-   psp_v11_0.o
+   psp_v11_0.o \
+   psp_ring.o
 
 # add SMC block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 8189a90637f7..38398f0c10c9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -33,6 +33,21 @@
 #include "psp_v10_0.h"
 #include "psp_v11_0.h"
 
+#define psp_ring_init(psp, type) \
+   (psp)->funcs->ring_init((psp), (type))
+#define psp_ring_create(psp, type) \
+   (psp)->funcs->ring_create((psp), (type))
+#define psp_ring_stop(psp, type) \
+   (psp)->funcs->ring_stop((psp), (type))
+#define psp_ring_destroy(psp, type) \
+   ((psp)->funcs->ring_destroy((psp), (type)))
+#define psp_prep_cmd_buf(ucode, cmd) \
+   (psp)->funcs->prep_cmd_buf((ucode), (cmd))
+#define psp_submit_cmd_buf(psp, ucode, cmd, fence_mc) \
+   (psp)->funcs->submit_cmd_buf((psp), (ucode), (cmd), (fence_mc))
+#define psp_support_vmr_ring(psp) \
+   ((psp)->funcs->support_vmr_ring ? 
(psp)->funcs->support_vmr_ring((psp)) : false)
+
 static void psp_set_funcs(struct amdgpu_device *adev);
 
 static int psp_early_init(void *handle)
@@ -117,50 +132,6 @@ int psp_wait_for(struct psp_context *psp, uint32_t 
reg_index,
return -ETIME;
 }
 
-static int
-psp_cmd_submit_buf(struct psp_context *psp,
-  struct amdgpu_firmware_info *ucode,
-  struct psp_gfx_cmd_resp *cmd, uint64_t fence_mc_addr)
-{
-   int ret;
-   int index;
-
-   memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
-
-   memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
-
-   index = atomic_inc_return(&psp->fence_value);
-   ret = psp_cmd_submit(psp, ucode, psp->cmd_buf_mc_addr,
-fence_mc_addr, index);
-   if (ret) {
-   atomic_dec(&psp->fence_value);
-   return ret;
-   }
-
-   while (*((unsigned int *)psp->fence_buf) != index)
-   msleep(1);
-
-   /* the status field must be 0 after psp command completion */
-   if (psp->cmd_buf_mem->resp.status) {
-   if (ucode)
-   DRM_ERROR("failed to load ucode id (%d) ",
- ucode->ucode_id);
-   DRM_ERROR("psp command failed and response status is (%d)\n",
- psp->cmd_buf_mem->resp.status);
-   return -EINVAL;
-   }
-
-   /* get xGMI session id from response buffer */
-   cmd->resp.session_id = psp->cmd_buf_mem->resp.session_id;
-
-   if (ucode) {
-   ucode->tmr_mc_addr_lo = psp->cmd_buf_mem->resp.fw_addr_lo;
-   ucode->tmr_mc_addr_hi = psp->cmd_buf_mem->resp.fw_addr_hi;
-   }
-
-   return ret;
-}
-
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
 uint64_t tmr_mc, uint32_t size)
@@ -206,7 +177,7 @@ static int psp_tmr_load(struct psp_context *psp)
DRM_INFO("reserve 0x%x from 0x%llx for PSP TMR SIZE\n",
PSP_TMR_SIZE, psp->tmr_mc_addr);
 
-   ret = psp_cmd_submit_buf(psp, NULL, cmd,
+   ret = psp_submit_cmd_buf(psp, NULL, cmd,
 psp->fence_buf_mc_addr);
if (ret)
goto failed;
@@ -273,7 +244,7 @@ static int psp_asd_load(struct psp_context *psp)
psp_prep_asd_cmd_buf(cmd, psp->fw_pri_mc_addr, psp->asd_shared_mc_addr,
 psp->asd_ucode_size, PSP_ASD_SHARED_MEM_SIZ

[PATCH 2/9] drm/amdgpu: separate commonly used PSP APIs

2019-01-02 Thread Evan Quan
So that they can be shared in PSP widely.

Change-Id: Icec5d23db2c1f8241f6bdff371e6cde65ffdb101
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c |  36 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  16 --
 drivers/gpu/drm/amd/amdgpu/psp_cmn.c| 289 
 drivers/gpu/drm/amd/amdgpu/psp_cmn.h|  41 
 drivers/gpu/drm/amd/amdgpu/psp_ring.c   |   9 +-
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c  | 126 +--
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 250 +---
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 243 +---
 9 files changed, 366 insertions(+), 647 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_cmn.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_cmn.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index bdcf0d4338f8..fe27d6038da9 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -91,7 +91,8 @@ amdgpu-y += \
psp_v3_1.o \
psp_v10_0.o \
psp_v11_0.o \
-   psp_ring.o
+   psp_ring.o \
+   psp_cmn.o
 
 # add SMC block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 38398f0c10c9..d1ccc6ea7607 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -47,6 +47,20 @@
(psp)->funcs->submit_cmd_buf((psp), (ucode), (cmd), (fence_mc))
 #define psp_support_vmr_ring(psp) \
((psp)->funcs->support_vmr_ring ? 
(psp)->funcs->support_vmr_ring((psp)) : false)
+#define psp_compare_sram_data(psp, ucode, type) \
+   (psp)->funcs->compare_sram_data((psp), (ucode), (type))
+#define psp_init_microcode(psp) \
+   ((psp)->funcs->init_microcode ? 
(psp)->funcs->init_microcode((psp)) : 0)
+#define psp_bootloader_load_sysdrv(psp) \
+   ((psp)->funcs->bootloader_load_sysdrv ? 
(psp)->funcs->bootloader_load_sysdrv((psp)) : 0)
+#define psp_bootloader_load_sos(psp) \
+   ((psp)->funcs->bootloader_load_sos ? 
(psp)->funcs->bootloader_load_sos((psp)) : 0)
+#define psp_smu_reload_quirk(psp) \
+   ((psp)->funcs->smu_reload_quirk ? 
(psp)->funcs->smu_reload_quirk((psp)) : false)
+#define psp_mode1_reset(psp) \
+   ((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : 
false)
+#define amdgpu_psp_check_fw_loading_status(adev, i) \
+   (adev)->firmware.funcs->check_fw_loading_status((adev), (i))
 
 static void psp_set_funcs(struct amdgpu_device *adev);
 
@@ -110,28 +124,6 @@ static int psp_sw_fini(void *handle)
return 0;
 }
 
-int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
-uint32_t reg_val, uint32_t mask, bool check_changed)
-{
-   uint32_t val;
-   int i;
-   struct amdgpu_device *adev = psp->adev;
-
-   for (i = 0; i < adev->usec_timeout; i++) {
-   val = RREG32(reg_index);
-   if (check_changed) {
-   if (val != reg_val)
-   return 0;
-   } else {
-   if ((val & mask) == reg_val)
-   return 0;
-   }
-   udelay(1);
-   }
-
-   return -ETIME;
-}
-
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
 uint64_t tmr_mc, uint32_t size)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index c94fa444f8b7..f4438a5077b6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -175,18 +175,6 @@ struct psp_xgmi_topology_info {
struct psp_xgmi_node_info   nodes[AMDGPU_XGMI_MAX_CONNECTED_NODES];
 };
 
-#define psp_compare_sram_data(psp, ucode, type) \
-   (psp)->funcs->compare_sram_data((psp), (ucode), (type))
-#define psp_init_microcode(psp) \
-   ((psp)->funcs->init_microcode ? 
(psp)->funcs->init_microcode((psp)) : 0)
-#define psp_bootloader_load_sysdrv(psp) \
-   ((psp)->funcs->bootloader_load_sysdrv ? 
(psp)->funcs->bootloader_load_sysdrv((psp)) : 0)
-#define psp_bootloader_load_sos(psp) \
-   ((psp)->funcs->bootloader_load_sos ? 
(psp)->funcs->bootloader_load_sos((psp)) : 0)
-#define psp_smu_reload_quirk(psp) \
-   ((psp)->funcs->smu_reload_quirk ? 
(psp)->funcs->smu_reload_quirk((psp)) : false)
-#define psp_mode1_reset(psp) \
-   ((psp)->funcs->mode1_reset ? (psp)->funcs->mode1_reset((psp)) : 
false)
 #define psp_xgmi_get_node_id(psp, node_id) \
((psp)->funcs->x

[PATCH 3/9] drm/amdgpu: separate the xgmi related APIs

2019-01-02 Thread Evan Quan
As they are logic independently from other APIs of amdgpu_psp.c.

Change-Id: Idb9d81e15ad4d37e93b95682a07194a94c4849d6
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |   3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 182 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |   1 -
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  |   1 +
 drivers/gpu/drm/amd/amdgpu/psp_xgmi.c   | 207 
 drivers/gpu/drm/amd/amdgpu/psp_xgmi.h   |  33 
 6 files changed, 244 insertions(+), 183 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_xgmi.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_xgmi.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index fe27d6038da9..30a705db0ef5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -92,7 +92,8 @@ amdgpu-y += \
psp_v10_0.o \
psp_v11_0.o \
psp_ring.o \
-   psp_cmn.o
+   psp_cmn.o \
+   psp_xgmi.o
 
 # add SMC block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d1ccc6ea7607..c33ced8371c3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -32,6 +32,7 @@
 #include "psp_v3_1.h"
 #include "psp_v10_0.h"
 #include "psp_v11_0.h"
+#include "psp_xgmi.h"
 
 #define psp_ring_init(psp, type) \
(psp)->funcs->ring_init((psp), (type))
@@ -244,187 +245,6 @@ static int psp_asd_load(struct psp_context *psp)
return ret;
 }
 
-static void psp_prep_xgmi_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
- uint64_t xgmi_ta_mc, uint64_t 
xgmi_mc_shared,
- uint32_t xgmi_ta_size, uint32_t 
shared_size)
-{
-cmd->cmd_id = GFX_CMD_ID_LOAD_TA;
-cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(xgmi_ta_mc);
-cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(xgmi_ta_mc);
-cmd->cmd.cmd_load_ta.app_len = xgmi_ta_size;
-
-cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = 
lower_32_bits(xgmi_mc_shared);
-cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = 
upper_32_bits(xgmi_mc_shared);
-cmd->cmd.cmd_load_ta.cmd_buf_len = shared_size;
-}
-
-static int psp_xgmi_init_shared_buf(struct psp_context *psp)
-{
-   int ret;
-
-   /*
-* Allocate 16k memory aligned to 4k from Frame Buffer (local
-* physical) for xgmi ta <-> Driver
-*/
-   ret = amdgpu_bo_create_kernel(psp->adev, PSP_XGMI_SHARED_MEM_SIZE,
- PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
- &psp->xgmi_context.xgmi_shared_bo,
- &psp->xgmi_context.xgmi_shared_mc_addr,
- &psp->xgmi_context.xgmi_shared_buf);
-
-   return ret;
-}
-
-static int psp_xgmi_load(struct psp_context *psp)
-{
-   int ret;
-   struct psp_gfx_cmd_resp *cmd;
-
-   /*
-* TODO: bypass the loading in sriov for now
-*/
-   if (amdgpu_sriov_vf(psp->adev))
-   return 0;
-
-   cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
-   if (!cmd)
-   return -ENOMEM;
-
-   memset(psp->fw_pri_buf, 0, PSP_1_MEG);
-   memcpy(psp->fw_pri_buf, psp->ta_xgmi_start_addr, 
psp->ta_xgmi_ucode_size);
-
-   psp_prep_xgmi_ta_load_cmd_buf(cmd, psp->fw_pri_mc_addr,
- psp->xgmi_context.xgmi_shared_mc_addr,
- psp->ta_xgmi_ucode_size, 
PSP_XGMI_SHARED_MEM_SIZE);
-
-   ret = psp_submit_cmd_buf(psp, NULL, cmd,
-psp->fence_buf_mc_addr);
-
-   if (!ret) {
-   psp->xgmi_context.initialized = 1;
-   psp->xgmi_context.session_id = cmd->resp.session_id;
-   }
-
-   kfree(cmd);
-
-   return ret;
-}
-
-static void psp_prep_xgmi_ta_unload_cmd_buf(struct psp_gfx_cmd_resp *cmd,
-   uint32_t xgmi_session_id)
-{
-   cmd->cmd_id = GFX_CMD_ID_UNLOAD_TA;
-   cmd->cmd.cmd_unload_ta.session_id = xgmi_session_id;
-}
-
-static int psp_xgmi_unload(struct psp_context *psp)
-{
-   int ret;
-   struct psp_gfx_cmd_resp *cmd;
-
-   /*
-* TODO: bypass the unloading in sriov for now
-*/
-   if (amdgpu_sriov_vf(psp->adev))
-   return 0;
-
-   cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
-   if (!cmd)
-   return -ENOMEM;
-
-   psp_prep_xgmi_ta_unload_cmd_buf(cmd, psp->xgmi_context.session_id);
-
-   ret = psp_submit_cmd_buf(psp, NULL, cmd,
-psp->fence_buf_mc_addr);
-
-   kfree(cmd);
-
-   

[PATCH 5/9] drm/amdgpu: separate the asd related APIs

2019-01-02 Thread Evan Quan
As they are logic independently from other APIs of amdgpu_psp.c.

Change-Id: If10aa695214f8df0744a67ee9eb0524d2c5a1ec1
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 62 +-
 drivers/gpu/drm/amd/amdgpu/psp_asd.c| 86 +
 drivers/gpu/drm/amd/amdgpu/psp_asd.h| 32 +
 4 files changed, 121 insertions(+), 62 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_asd.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_asd.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 99895c6fcd95..ebef9d2cdd61 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -94,7 +94,8 @@ amdgpu-y += \
psp_ring.o \
psp_cmn.o \
psp_xgmi.o \
-   psp_tmr.o
+   psp_tmr.o \
+   psp_asd.o
 
 # add SMC block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 2007e8948cbc..2528fbcad275 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -34,6 +34,7 @@
 #include "psp_v11_0.h"
 #include "psp_xgmi.h"
 #include "psp_tmr.h"
+#include "psp_asd.h"
 
 #define psp_ring_init(psp, type) \
(psp)->funcs->ring_init((psp), (type))
@@ -126,67 +127,6 @@ static int psp_sw_fini(void *handle)
return 0;
 }
 
-static void psp_prep_asd_cmd_buf(struct psp_gfx_cmd_resp *cmd,
-uint64_t asd_mc, uint64_t asd_mc_shared,
-uint32_t size, uint32_t shared_size)
-{
-   cmd->cmd_id = GFX_CMD_ID_LOAD_ASD;
-   cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(asd_mc);
-   cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(asd_mc);
-   cmd->cmd.cmd_load_ta.app_len = size;
-
-   cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = lower_32_bits(asd_mc_shared);
-   cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = upper_32_bits(asd_mc_shared);
-   cmd->cmd.cmd_load_ta.cmd_buf_len = shared_size;
-}
-
-static int psp_asd_init(struct psp_context *psp)
-{
-   int ret;
-
-   /*
-* Allocate 16k memory aligned to 4k from Frame Buffer (local
-* physical) for shared ASD <-> Driver
-*/
-   ret = amdgpu_bo_create_kernel(psp->adev, PSP_ASD_SHARED_MEM_SIZE,
- PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
- &psp->asd_shared_bo,
- &psp->asd_shared_mc_addr,
- &psp->asd_shared_buf);
-
-   return ret;
-}
-
-static int psp_asd_load(struct psp_context *psp)
-{
-   int ret;
-   struct psp_gfx_cmd_resp *cmd;
-
-   /* If PSP version doesn't match ASD version, asd loading will be failed.
-* add workaround to bypass it for sriov now.
-* TODO: add version check to make it common
-*/
-   if (amdgpu_sriov_vf(psp->adev))
-   return 0;
-
-   cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
-   if (!cmd)
-   return -ENOMEM;
-
-   memset(psp->fw_pri_buf, 0, PSP_1_MEG);
-   memcpy(psp->fw_pri_buf, psp->asd_start_addr, psp->asd_ucode_size);
-
-   psp_prep_asd_cmd_buf(cmd, psp->fw_pri_mc_addr, psp->asd_shared_mc_addr,
-psp->asd_ucode_size, PSP_ASD_SHARED_MEM_SIZE);
-
-   ret = psp_submit_cmd_buf(psp, NULL, cmd,
-psp->fence_buf_mc_addr);
-
-   kfree(cmd);
-
-   return ret;
-}
-
 static int psp_hw_start(struct psp_context *psp)
 {
struct amdgpu_device *adev = psp->adev;
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_asd.c 
b/drivers/gpu/drm/amd/amdgpu/psp_asd.c
new file mode 100644
index ..16263b901a2b
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/psp_asd.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHA

[PATCH 4/9] drm/amdgpu: separate the tmr related APIs

2019-01-02 Thread Evan Quan
As they are logic independently from other APIs of amdgpu_psp.c.

Change-Id: I3c8014caca8250bef6439e857bea1b64b6c1930a
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 60 +-
 drivers/gpu/drm/amd/amdgpu/psp_tmr.c| 84 +
 drivers/gpu/drm/amd/amdgpu/psp_tmr.h| 32 ++
 4 files changed, 119 insertions(+), 60 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_tmr.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_tmr.h

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 30a705db0ef5..99895c6fcd95 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -93,7 +93,8 @@ amdgpu-y += \
psp_v11_0.o \
psp_ring.o \
psp_cmn.o \
-   psp_xgmi.o
+   psp_xgmi.o \
+   psp_tmr.o
 
 # add SMC block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c33ced8371c3..2007e8948cbc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -33,6 +33,7 @@
 #include "psp_v10_0.h"
 #include "psp_v11_0.h"
 #include "psp_xgmi.h"
+#include "psp_tmr.h"
 
 #define psp_ring_init(psp, type) \
(psp)->funcs->ring_init((psp), (type))
@@ -125,65 +126,6 @@ static int psp_sw_fini(void *handle)
return 0;
 }
 
-static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
-struct psp_gfx_cmd_resp *cmd,
-uint64_t tmr_mc, uint32_t size)
-{
-   if (psp_support_vmr_ring(psp))
-   cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
-   else
-   cmd->cmd_id = GFX_CMD_ID_SETUP_TMR;
-   cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
-   cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
-   cmd->cmd.cmd_setup_tmr.buf_size = size;
-}
-
-/* Set up Trusted Memory Region */
-static int psp_tmr_init(struct psp_context *psp)
-{
-   int ret;
-
-   /*
-* Allocate 3M memory aligned to 1M from Frame Buffer (local
-* physical).
-*
-* Note: this memory need be reserved till the driver
-* uninitializes.
-*/
-   ret = amdgpu_bo_create_kernel(psp->adev, PSP_TMR_SIZE, 0x10,
- AMDGPU_GEM_DOMAIN_VRAM,
- &psp->tmr_bo, &psp->tmr_mc_addr, 
&psp->tmr_buf);
-
-   return ret;
-}
-
-static int psp_tmr_load(struct psp_context *psp)
-{
-   int ret;
-   struct psp_gfx_cmd_resp *cmd;
-
-   cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
-   if (!cmd)
-   return -ENOMEM;
-
-   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, PSP_TMR_SIZE);
-   DRM_INFO("reserve 0x%x from 0x%llx for PSP TMR SIZE\n",
-   PSP_TMR_SIZE, psp->tmr_mc_addr);
-
-   ret = psp_submit_cmd_buf(psp, NULL, cmd,
-psp->fence_buf_mc_addr);
-   if (ret)
-   goto failed;
-
-   kfree(cmd);
-
-   return 0;
-
-failed:
-   kfree(cmd);
-   return ret;
-}
-
 static void psp_prep_asd_cmd_buf(struct psp_gfx_cmd_resp *cmd,
 uint64_t asd_mc, uint64_t asd_mc_shared,
 uint32_t size, uint32_t shared_size)
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_tmr.c 
b/drivers/gpu/drm/amd/amdgpu/psp_tmr.c
new file mode 100644
index ..fd5fa167a56d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/psp_tmr.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2018 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "psp_t

[PATCH 0/9] PSP cleanup

2019-01-02 Thread Evan Quan
*** BLURB HERE ***

Evan Quan (9):
  drm/amdgpu: separate the PSP ring related APIs
  drm/amdgpu: separate commonly used PSP APIs
  drm/amdgpu: separate the xgmi related APIs
  drm/amdgpu: separate the tmr related APIs
  drm/amdgpu: separate the asd related APIs
  drm/amdgpu: drop useless PSP APIs and structures
  drm/amdgpu: check PSP support before adding the ip block
  drm/amdgpu: make PSP sub modules(ASD/XGMI/TMR) support configurable
  drm/amdgpu: move psp_funcs related to a more proper place

 drivers/gpu/drm/amd/amdgpu/Makefile |   7 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 504 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  93 +---
 drivers/gpu/drm/amd/amdgpu/psp_asd.c|  86 
 drivers/gpu/drm/amd/amdgpu/psp_asd.h|  32 ++
 drivers/gpu/drm/amd/amdgpu/psp_cmn.c| 289 +
 drivers/gpu/drm/amd/amdgpu/psp_cmn.h|  84 
 drivers/gpu/drm/amd/amdgpu/psp_funcs.h  |  98 +
 drivers/gpu/drm/amd/amdgpu/psp_ring.c   | 354 
 drivers/gpu/drm/amd/amdgpu/psp_ring.h   |  43 ++
 drivers/gpu/drm/amd/amdgpu/psp_tmr.c|  84 
 drivers/gpu/drm/amd/amdgpu/psp_tmr.h|  32 ++
 drivers/gpu/drm/amd/amdgpu/psp_v10_0.c  | 381 +
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 539 +---
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 480 +
 drivers/gpu/drm/amd/amdgpu/psp_xgmi.c   | 207 +
 drivers/gpu/drm/amd/amdgpu/psp_xgmi.h   |  33 ++
 drivers/gpu/drm/amd/amdgpu/soc15.c  |  13 +-
 18 files changed, 1493 insertions(+), 1866 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_asd.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_asd.h
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_cmn.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_cmn.h
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_funcs.h
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_ring.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_ring.h
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_tmr.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_tmr.h
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_xgmi.c
 create mode 100644 drivers/gpu/drm/amd/amdgpu/psp_xgmi.h

-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: hint and error out when prerequisite not meet

2019-01-02 Thread Evan Quan
Do not ignore the error silently. Otherwise user may thought it
was executed successfully.

Change-Id: I4ac0cff5918d53d1d737f1c2fb1a4f81917dbf56
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c| 14 ++
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c |  4 +++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 5e071917594f..e0a9f02d68d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -756,8 +756,11 @@ static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
if (ret)
return ret;
 
-   if (adev->powerplay.pp_funcs->force_clock_level)
-   amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
+   if (adev->powerplay.pp_funcs->force_clock_level) {
+   ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
+   if (ret)
+   return ret;
+   }
 
return count;
 }
@@ -789,8 +792,11 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
if (ret)
return ret;
 
-   if (adev->powerplay.pp_funcs->force_clock_level)
-   amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
+   if (adev->powerplay.pp_funcs->force_clock_level) {
+   ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
+   if (ret)
+   return ret;
+   }
 
return count;
 }
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c 
b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 27215e4b488b..285375b96ea4 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -727,8 +727,10 @@ static int pp_dpm_force_clock_level(void *handle,
mutex_lock(&hwmgr->smu_lock);
if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)
ret = hwmgr->hwmgr_func->force_clock_level(hwmgr, type, mask);
-   else
+   else {
+   pr_info_ratelimited("Force clock level setting is for manual 
dpm mode only.\n");
ret = -EINVAL;
+   }
mutex_unlock(&hwmgr->smu_lock);
return ret;
 }
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amd/powerplay: update OD support flag for SKU with no OD capabilities

2019-01-07 Thread Evan Quan
For those ASICs with no overdrive capabilities, the OD support flag
will be reset.

Change-Id: I8b75ad27ec0035b80de555840ba496bc273fee08
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 25b8742f51c5..ea0939ad3316 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -980,6 +980,9 @@ static int vega20_od8_set_feature_capabilities(
pp_table->FanZeroRpmEnable)
od_settings->overdrive8_capabilities |= 
OD8_FAN_ZERO_RPM_CONTROL;
 
+   if (!od_settings->overdrive8_capabilities)
+   hwmgr->od_enabled = false;
+
return 0;
 }
 
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: create pp_od_clk_voltage device file under OD support

2019-01-07 Thread Evan Quan
Since pp_od_clk_voltage device file is for OD related sysfs operations.

Change-Id: I13e95b4bd2ffb93b1cd5d272dd27171ab38dbe57
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 22 ++
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 32aa4d09e12d..d8f3f006f5c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -2061,6 +2061,7 @@ void amdgpu_pm_print_power_states(struct amdgpu_device 
*adev)
 
 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
 {
+   struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
int ret;
 
if (adev->pm.sysfs_initialized)
@@ -2144,12 +2145,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
"pp_power_profile_mode\n");
return ret;
}
-   ret = device_create_file(adev->dev,
-   &dev_attr_pp_od_clk_voltage);
-   if (ret) {
-   DRM_ERROR("failed to create device file "
-   "pp_od_clk_voltage\n");
-   return ret;
+   if (hwmgr->od_enabled) {
+   ret = device_create_file(adev->dev,
+   &dev_attr_pp_od_clk_voltage);
+   if (ret) {
+   DRM_ERROR("failed to create device file "
+   "pp_od_clk_voltage\n");
+   return ret;
+   }
}
ret = device_create_file(adev->dev,
&dev_attr_gpu_busy_percent);
@@ -2171,6 +2174,8 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
 
 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
 {
+   struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
+
if (adev->pm.dpm_enabled == 0)
return;
 
@@ -2191,8 +2196,9 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
device_remove_file(adev->dev,
&dev_attr_pp_power_profile_mode);
-   device_remove_file(adev->dev,
-   &dev_attr_pp_od_clk_voltage);
+   if (hwmgr->od_enabled)
+   device_remove_file(adev->dev,
+   &dev_attr_pp_od_clk_voltage);
device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
 }
 
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: avoid possible buffer overflow

2019-01-07 Thread Evan Quan
Make sure the clock level enforced is within the allowed
ranges.

Change-Id: If69a8512121c0c94818ab698595502e17569d4c7
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 8f6097c6a02b..c2061d351d04 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -2251,6 +2251,13 @@ static int vega20_force_clock_level(struct pp_hwmgr 
*hwmgr,
soft_min_level = mask ? (ffs(mask) - 1) : 0;
soft_max_level = mask ? (fls(mask) - 1) : 0;
 
+   if (soft_max_level >= data->dpm_table.gfx_table.count) {
+   pr_err("Clock level specified %d is over max allowed 
%d\n",
+   soft_max_level,
+   data->dpm_table.gfx_table.count - 1);
+   return -EINVAL;
+   }
+
data->dpm_table.gfx_table.dpm_state.soft_min_level =

data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
data->dpm_table.gfx_table.dpm_state.soft_max_level =
@@ -2271,6 +2278,13 @@ static int vega20_force_clock_level(struct pp_hwmgr 
*hwmgr,
soft_min_level = mask ? (ffs(mask) - 1) : 0;
soft_max_level = mask ? (fls(mask) - 1) : 0;
 
+   if (soft_max_level >= data->dpm_table.mem_table.count) {
+   pr_err("Clock level specified %d is over max allowed 
%d\n",
+   soft_max_level,
+   data->dpm_table.mem_table.count - 1);
+   return -EINVAL;
+   }
+
data->dpm_table.mem_table.dpm_state.soft_min_level =

data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
data->dpm_table.mem_table.dpm_state.soft_max_level =
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: drop the unnecessary uclk hard min setting

2019-01-07 Thread Evan Quan
Since soft min setting is enough. Hard min setting is redundant.

Change-Id: I758386085f227bad94148ec0b38776312b6f5b25
Reported-by: Likun Gao 
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index c2061d351d04..82935a3bd950 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -1692,13 +1692,6 @@ static int vega20_upload_dpm_min_level(struct pp_hwmgr 
*hwmgr, uint32_t feature_
(PPCLK_UCLK << 16) | (min_freq & 
0x))),
"Failed to set soft min memclk !",
return ret);
-
-   min_freq = data->dpm_table.mem_table.dpm_state.hard_min_level;
-   PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
-   hwmgr, PPSMC_MSG_SetHardMinByFreq,
-   (PPCLK_UCLK << 16) | (min_freq & 
0x))),
-   "Failed to set hard min memclk !",
-   return ret);
}
 
if (data->smu_features[GNLD_DPM_UVD].enabled &&
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 3/4] drm/amd/powerplay: support retrieving and adjusting fclock power levels

2019-01-14 Thread Evan Quan
User can use "pp_dpm_fclk" to retrieve and adjust fclock power
levels.

Change-Id: Ib5325a9533b5fe8c125738a2f26e7b976d3ec991
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c| 49 +-
 .../gpu/drm/amd/include/kgd_pp_interface.h|  1 +
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 64 +++
 3 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index f735118a6070..f6646a522c06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -731,11 +731,11 @@ static ssize_t amdgpu_get_ppfeature_status(struct device 
*dev,
 }
 
 /**
- * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_pcie
+ * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_pcie
  *
  * The amdgpu driver provides a sysfs API for adjusting what power levels
  * are enabled for a given power state.  The files pp_dpm_sclk, pp_dpm_mclk,
- * pp_dpm_socclk and pp_dpm_pcie are used for this.
+ * pp_dpm_socclk, pp_dpm_fclk and pp_dpm_pcie are used for this.
  *
  * Reading back the files will show you the available power levels within
  * the power state and the clock information for those levels.
@@ -891,6 +891,42 @@ static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
return count;
 }
 
+static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+
+   if (adev->powerplay.pp_funcs->print_clock_levels)
+   return amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
+   else
+   return snprintf(buf, PAGE_SIZE, "\n");
+}
+
+static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf,
+   size_t count)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+   int ret;
+   uint32_t mask = 0;
+
+   ret = amdgpu_read_mask(buf, count, &mask);
+   if (ret)
+   return ret;
+
+   if (adev->powerplay.pp_funcs->force_clock_level)
+   ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
+
+   if (ret)
+   return -EINVAL;
+
+   return count;
+}
+
 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1177,6 +1213,9 @@ static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(pp_dpm_socclk, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_socclk,
amdgpu_set_pp_dpm_socclk);
+static DEVICE_ATTR(pp_dpm_fclk, S_IRUGO | S_IWUSR,
+   amdgpu_get_pp_dpm_fclk,
+   amdgpu_set_pp_dpm_fclk);
 static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_pcie,
amdgpu_set_pp_dpm_pcie);
@@ -2343,6 +2382,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
DRM_ERROR("failed to create device file pp_dpm_socclk\n");
return ret;
}
+   ret = device_create_file(adev->dev, &dev_attr_pp_dpm_fclk);
+   if (ret) {
+   DRM_ERROR("failed to create device file pp_dpm_fclk\n");
+   return ret;
+   }
ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
if (ret) {
DRM_ERROR("failed to create device file pp_dpm_pcie\n");
@@ -2429,6 +2473,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
device_remove_file(adev->dev, &dev_attr_pp_dpm_socclk);
device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
+   device_remove_file(adev->dev, &dev_attr_pp_dpm_fclk);
device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
device_remove_file(adev->dev,
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index f5ec25a6ab54..f82de14f6560 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -93,6 +93,7 @@ enum pp_clock_type {
PP_MCLK,
PP_PCIE,
PP_SOCCLK,
+   PP_FCLK,
OD_SCLK,
OD_MCLK,
OD_VDDC_CURVE,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 61583d6fc20e..1832dcb965b1 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -1735,6 +1735,17 @@ static int vega20_upload_dpm_min

[PATCH 1/4] drm/amd/powerplay: support enabled ppfeatures retrieving and setting

2019-01-14 Thread Evan Quan
User can use "ppfeatures" sysfs interface to retrieve and set enabled
powerplay features.

Change-Id: I00d5b4931ab426b506e1c187f81a279b00afbb66
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h   |   8 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c|  66 +++
 .../gpu/drm/amd/include/kgd_pp_interface.h|   2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c |  42 +++
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 104 ++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h |   2 +
 6 files changed, 224 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..2f61e9edb1c1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,14 @@ enum amdgpu_pcie_gen {
((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
(adev)->powerplay.pp_handle))
 
+#define amdgpu_dpm_get_ppfeature_status(adev, buf) \
+   ((adev)->powerplay.pp_funcs->get_ppfeature_status(\
+   (adev)->powerplay.pp_handle, (buf)))
+
+#define amdgpu_dpm_set_ppfeature_status(adev, ppfeatures) \
+   ((adev)->powerplay.pp_funcs->set_ppfeature_status(\
+   (adev)->powerplay.pp_handle, (ppfeatures)))
+
 struct amdgpu_dpm {
struct amdgpu_ps*ps;
/* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 30ab304eb8b6..db490587464c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -676,6 +676,60 @@ static ssize_t amdgpu_get_pp_od_clk_voltage(struct device 
*dev,
 
 }
 
+/**
+ * DOC: ppfeatures
+ *
+ * The amdgpu driver provides a sysfs API for adjusting what powerplay
+ * features to be enabled. The file ppfeatures is used for this.
+ *
+ * Reading back the file will show you the followings:
+ * - Current ppfeature masks
+ * - List of the all supported powerplay features with their naming,
+ *   bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
+ *
+ * To manually enable or disable a specific feature, just set or clear
+ * the corresponding bit from original ppfeature masks and input the
+ * new ppfeature masks.
+ */
+static ssize_t amdgpu_set_ppfeature_status(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf,
+   size_t count)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+   uint64_t featuremask;
+   int ret;
+
+   ret = kstrtou64(buf, 0, &featuremask);
+   if (ret)
+   return -EINVAL;
+
+   pr_debug("featuremask = 0x%llx\n", featuremask);
+
+   if (adev->powerplay.pp_funcs->set_ppfeature_status) {
+   ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
+   if (ret)
+   return -EINVAL;
+   }
+
+   return count;
+}
+
+static ssize_t amdgpu_get_ppfeature_status(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+   uint32_t size = 0;
+
+   if (adev->powerplay.pp_funcs->get_ppfeature_status)
+   return amdgpu_dpm_get_ppfeature_status(adev, buf);
+
+   return snprintf(buf, PAGE_SIZE, "\n");
+}
+
 /**
  * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_pcie
  *
@@ -1102,6 +1156,9 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,
amdgpu_get_busy_percent, NULL);
 static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL);
+static DEVICE_ATTR(ppfeatures, S_IRUGO | S_IWUSR,
+   amdgpu_get_ppfeature_status,
+   amdgpu_set_ppfeature_status);
 
 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
  struct device_attribute *attr,
@@ -2294,6 +2351,14 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
return ret;
}
 
+   ret = device_create_file(adev->dev,
+   &dev_attr_ppfeatures);
+   if (ret) {
+   DRM_ERROR("failed to create device file "
+   "ppfeatures\n");
+   return ret;
+   }
+
adev->pm.sysfs_initialized = true;
 
return 0;
@@ -2329,6 +2394,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
if (adev->flags & !AMD_IS_APU)
device_remove_file(adev->dev, &dev_attr_pcie_bw);
+   device_remove_file(ad

[PATCH 2/4] drm/amd/powerplay: support retrieving and adjusting SOC clock power levels

2019-01-14 Thread Evan Quan
User can use "pp_dpm_socclk" to retrieve and adjust SOC clock power
levels.

Change-Id: I24d2f1df2dcf6b8dfa188f82767b36624610406f
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c| 49 ++-
 .../gpu/drm/amd/include/kgd_pp_interface.h|  1 +
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 45 +
 3 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index db490587464c..f735118a6070 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -731,11 +731,11 @@ static ssize_t amdgpu_get_ppfeature_status(struct device 
*dev,
 }
 
 /**
- * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_pcie
+ * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_pcie
  *
  * The amdgpu driver provides a sysfs API for adjusting what power levels
  * are enabled for a given power state.  The files pp_dpm_sclk, pp_dpm_mclk,
- * and pp_dpm_pcie are used for this.
+ * pp_dpm_socclk and pp_dpm_pcie are used for this.
  *
  * Reading back the files will show you the available power levels within
  * the power state and the clock information for those levels.
@@ -855,6 +855,42 @@ static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
return count;
 }
 
+static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+
+   if (adev->powerplay.pp_funcs->print_clock_levels)
+   return amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
+   else
+   return snprintf(buf, PAGE_SIZE, "\n");
+}
+
+static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf,
+   size_t count)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+   int ret;
+   uint32_t mask = 0;
+
+   ret = amdgpu_read_mask(buf, count, &mask);
+   if (ret)
+   return ret;
+
+   if (adev->powerplay.pp_funcs->force_clock_level)
+   ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
+
+   if (ret)
+   return -EINVAL;
+
+   return count;
+}
+
 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1138,6 +1174,9 @@ static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_mclk,
amdgpu_set_pp_dpm_mclk);
+static DEVICE_ATTR(pp_dpm_socclk, S_IRUGO | S_IWUSR,
+   amdgpu_get_pp_dpm_socclk,
+   amdgpu_set_pp_dpm_socclk);
 static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_pcie,
amdgpu_set_pp_dpm_pcie);
@@ -2299,6 +2338,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
DRM_ERROR("failed to create device file pp_dpm_mclk\n");
return ret;
}
+   ret = device_create_file(adev->dev, &dev_attr_pp_dpm_socclk);
+   if (ret) {
+   DRM_ERROR("failed to create device file pp_dpm_socclk\n");
+   return ret;
+   }
ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
if (ret) {
DRM_ERROR("failed to create device file pp_dpm_pcie\n");
@@ -2383,6 +2427,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
 
device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
+   device_remove_file(adev->dev, &dev_attr_pp_dpm_socclk);
device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 1130f293c4ee..f5ec25a6ab54 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -92,6 +92,7 @@ enum pp_clock_type {
PP_SCLK,
PP_MCLK,
PP_PCIE,
+   PP_SOCCLK,
OD_SCLK,
OD_MCLK,
OD_VDDC_CURVE,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 58b63f864227..61583d6fc20e 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -2295,6 +2295,34 @@ static int vega20_force_clock_level(struct pp_hwmgr 
*hwmgr,
 
break;
 
+   case PP_

[PATCH 4/4] drm/amd/powerplay: support retrieving and adjusting dcefclock power levels

2019-01-14 Thread Evan Quan
User can use "pp_dpm_dcefclk" to retrieve and adjust dcefclock power
levels.

Change-Id: Ia3f61558ca96104c88d129ba5194103b2fe702ec
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c| 53 ++-
 .../gpu/drm/amd/include/kgd_pp_interface.h|  1 +
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 52 +-
 3 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index f6646a522c06..b7b70f590236 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -731,11 +731,13 @@ static ssize_t amdgpu_get_ppfeature_status(struct device 
*dev,
 }
 
 /**
- * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_pcie
+ * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk
+ * pp_dpm_pcie
  *
  * The amdgpu driver provides a sysfs API for adjusting what power levels
  * are enabled for a given power state.  The files pp_dpm_sclk, pp_dpm_mclk,
- * pp_dpm_socclk, pp_dpm_fclk and pp_dpm_pcie are used for this.
+ * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
+ * this.
  *
  * Reading back the files will show you the available power levels within
  * the power state and the clock information for those levels.
@@ -745,6 +747,8 @@ static ssize_t amdgpu_get_ppfeature_status(struct device 
*dev,
  * Secondly,Enter a new value for each level by inputing a string that
  * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
  * E.g., echo 4 5 6 to > pp_dpm_sclk will enable sclk levels 4, 5, and 6.
+ *
+ * NOTE: change to the dcefclk max dpm level is not supported now
  */
 
 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
@@ -927,6 +931,42 @@ static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
return count;
 }
 
+static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+
+   if (adev->powerplay.pp_funcs->print_clock_levels)
+   return amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
+   else
+   return snprintf(buf, PAGE_SIZE, "\n");
+}
+
+static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf,
+   size_t count)
+{
+   struct drm_device *ddev = dev_get_drvdata(dev);
+   struct amdgpu_device *adev = ddev->dev_private;
+   int ret;
+   uint32_t mask = 0;
+
+   ret = amdgpu_read_mask(buf, count, &mask);
+   if (ret)
+   return ret;
+
+   if (adev->powerplay.pp_funcs->force_clock_level)
+   ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
+
+   if (ret)
+   return -EINVAL;
+
+   return count;
+}
+
 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1216,6 +1256,9 @@ static DEVICE_ATTR(pp_dpm_socclk, S_IRUGO | S_IWUSR,
 static DEVICE_ATTR(pp_dpm_fclk, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_fclk,
amdgpu_set_pp_dpm_fclk);
+static DEVICE_ATTR(pp_dpm_dcefclk, S_IRUGO | S_IWUSR,
+   amdgpu_get_pp_dpm_dcefclk,
+   amdgpu_set_pp_dpm_dcefclk);
 static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
amdgpu_get_pp_dpm_pcie,
amdgpu_set_pp_dpm_pcie);
@@ -2387,6 +2430,11 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
DRM_ERROR("failed to create device file pp_dpm_fclk\n");
return ret;
}
+   ret = device_create_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
+   if (ret) {
+   DRM_ERROR("failed to create device file pp_dpm_dcefclk\n");
+   return ret;
+   }
ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
if (ret) {
DRM_ERROR("failed to create device file pp_dpm_pcie\n");
@@ -2474,6 +2522,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
device_remove_file(adev->dev, &dev_attr_pp_dpm_socclk);
device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
device_remove_file(adev->dev, &dev_attr_pp_dpm_fclk);
+   device_remove_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
device_remove_file(adev->dev,
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index f82de14f6560..2b579ba9b685 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interfac

[PATCH 2/2] drm/amdgpu: fix wrong APU judgement

2019-01-15 Thread Evan Quan
Fix the APU judgement to make it really work as expected.

Change-Id: Iedc7d280e2bb68dd1b3732adb3b36ff9b05d84af
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 42078607168f..931cfd947958 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -2483,7 +2483,7 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
return ret;
}
/* PCIe Perf counters won't work on APU nodes */
-   if (adev->flags & !AMD_IS_APU) {
+   if (!(adev->flags & AMD_IS_APU)) {
ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
if (ret) {
DRM_ERROR("failed to create device file pcie_bw\n");
@@ -2546,7 +2546,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
device_remove_file(adev->dev,
&dev_attr_pp_od_clk_voltage);
device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
-   if (adev->flags & !AMD_IS_APU)
+   if (!(adev->flags & AMD_IS_APU))
device_remove_file(adev->dev, &dev_attr_pcie_bw);
if ((adev->asic_type >= CHIP_VEGA10) &&
!(adev->flags & AMD_IS_APU))
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amdgpu: check PSP support before adding the ip block

2019-01-15 Thread Evan Quan
So that we do not need to check this in every internal function.

Change-Id: Id986ad97ffddc769e4f7cc7e41d1780b93dba9b9
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 24 
 drivers/gpu/drm/amd/amdgpu/soc15.c  | 13 -
 2 files changed, 8 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index f26d8faa7507..d87f165e3a23 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -67,9 +67,6 @@ static int psp_sw_init(void *handle)
 
psp->adev = adev;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
ret = psp_init_microcode(psp);
if (ret) {
DRM_ERROR("Failed to load psp firmware!\n");
@@ -83,9 +80,6 @@ static int psp_sw_fini(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
release_firmware(adev->psp.sos_fw);
adev->psp.sos_fw = NULL;
release_firmware(adev->psp.asd_fw);
@@ -721,10 +715,6 @@ static int psp_hw_init(void *handle)
int ret;
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
mutex_lock(&adev->firmware.mutex);
/*
 * This sequence is just used on hw_init only once, no need on
@@ -754,9 +744,6 @@ static int psp_hw_fini(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1)
 psp_xgmi_terminate(psp);
@@ -785,9 +772,6 @@ static int psp_suspend(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
if (adev->gmc.xgmi.num_physical_nodes > 1 &&
psp->xgmi_context.initialized == 1) {
ret = psp_xgmi_terminate(psp);
@@ -812,9 +796,6 @@ static int psp_resume(void *handle)
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
struct psp_context *psp = &adev->psp;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
-   return 0;
-
DRM_INFO("PSP is resuming...\n");
 
mutex_lock(&adev->firmware.mutex);
@@ -850,11 +831,6 @@ static bool psp_check_fw_loading_status(struct 
amdgpu_device *adev,
 {
struct amdgpu_firmware_info *ucode = NULL;
 
-   if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
-   DRM_INFO("firmware is not loaded by PSP\n");
-   return true;
-   }
-
if (!adev->firmware.fw_size)
return false;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index aee45879f60d..16b482ac9868 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -595,10 +595,12 @@ int soc15_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
-   if (adev->asic_type == CHIP_VEGA20)
-   amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
-   else
-   amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
+   if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
+   if (adev->asic_type == CHIP_VEGA20)
+   amdgpu_device_ip_block_add(adev, 
&psp_v11_0_ip_block);
+   else
+   amdgpu_device_ip_block_add(adev, 
&psp_v3_1_ip_block);
+   }
amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
if (!amdgpu_sriov_vf(adev))
@@ -620,7 +622,8 @@ int soc15_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
-   amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
+   if (likely(adev->firmware.load_type == AMDGPU_FW_LOA

[PATCH 1/2] drm/amd/powerplay: avoid unnecessary dpm level setting

2019-01-17 Thread Evan Quan
No dpm level setting is needed when the request level
is actually same as current.

Change-Id: I3ffa0b111a7b37f78a6a4dc1a36d49f0496dd6f9
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
index 56437866d120..68f3dcaa8070 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
@@ -278,7 +278,8 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, 
bool skip,
 
phm_notify_smc_display_config_after_ps_adjustment(hwmgr);
 
-   if (!phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
+   if ((hwmgr->request_dpm_level != hwmgr->dpm_level) &&
+   !phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
hwmgr->dpm_level = hwmgr->request_dpm_level;
 
if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: enforce display related settings only on needed

2019-01-17 Thread Evan Quan
No display related settings are needed on dpm level change.

Change-Id: I86b32687a3bc14521be89dd4a3c9fb7de7f06c4b
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c  | 10 +-
 drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c | 11 +--
 drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.h |  2 +-
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
index 310b102a9292..6cd6497c6fc2 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
@@ -273,7 +273,7 @@ int hwmgr_hw_fini(struct pp_hwmgr *hwmgr)
 
phm_stop_thermal_controller(hwmgr);
psm_set_boot_states(hwmgr);
-   psm_adjust_power_state_dynamic(hwmgr, false, NULL);
+   psm_adjust_power_state_dynamic(hwmgr, true, NULL);
phm_disable_dynamic_state_management(hwmgr);
phm_disable_clock_power_gatings(hwmgr);
 
@@ -295,7 +295,7 @@ int hwmgr_suspend(struct pp_hwmgr *hwmgr)
ret = psm_set_boot_states(hwmgr);
if (ret)
return ret;
-   ret = psm_adjust_power_state_dynamic(hwmgr, false, NULL);
+   ret = psm_adjust_power_state_dynamic(hwmgr, true, NULL);
if (ret)
return ret;
ret = phm_power_down_asic(hwmgr);
@@ -325,7 +325,7 @@ int hwmgr_resume(struct pp_hwmgr *hwmgr)
if (ret)
return ret;
 
-   ret = psm_adjust_power_state_dynamic(hwmgr, false, NULL);
+   ret = psm_adjust_power_state_dynamic(hwmgr, true, NULL);
 
return ret;
 }
@@ -379,12 +379,12 @@ int hwmgr_handle_task(struct pp_hwmgr *hwmgr, enum 
amd_pp_task task_id,
ret = psm_set_user_performance_state(hwmgr, requested_ui_label, 
&requested_ps);
if (ret)
return ret;
-   ret = psm_adjust_power_state_dynamic(hwmgr, false, 
requested_ps);
+   ret = psm_adjust_power_state_dynamic(hwmgr, true, requested_ps);
break;
}
case AMD_PP_TASK_COMPLETE_INIT:
case AMD_PP_TASK_READJUST_POWER_STATE:
-   ret = psm_adjust_power_state_dynamic(hwmgr, false, NULL);
+   ret = psm_adjust_power_state_dynamic(hwmgr, true, NULL);
break;
default:
break;
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
index 68f3dcaa8070..ce177d7f04cb 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
@@ -256,16 +256,14 @@ static void power_state_management(struct pp_hwmgr *hwmgr,
}
 }
 
-int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip,
+int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool 
skip_display_settings,
struct pp_power_state *new_ps)
 {
uint32_t index;
long workload;
 
-   if (skip)
-   return 0;
-
-   phm_display_configuration_changed(hwmgr);
+   if (!skip_display_settings)
+   phm_display_configuration_changed(hwmgr);
 
if (hwmgr->ps)
power_state_management(hwmgr, new_ps);
@@ -276,7 +274,8 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, 
bool skip,
 */
phm_apply_clock_adjust_rules(hwmgr);
 
-   phm_notify_smc_display_config_after_ps_adjustment(hwmgr);
+   if (!skip_display_settings)
+   phm_notify_smc_display_config_after_ps_adjustment(hwmgr);
 
if ((hwmgr->request_dpm_level != hwmgr->dpm_level) &&
!phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.h
index fa1b6825036a..b62d55f1f289 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.h
@@ -34,7 +34,7 @@ int psm_set_user_performance_state(struct pp_hwmgr *hwmgr,
enum PP_StateUILabel label_id,
struct pp_power_state **state);
 int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr,
-   bool skip,
+   bool skip_display_settings,
struct pp_power_state *new_ps);
 
 #endif
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: run btc before enabling all SMU features

2019-01-21 Thread Evan Quan
BTC is needed before enabling all SMU features.

Change-Id: Ic717226528f4d09a58264524b2d8e67150a35da7
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 60a22d8da7f0..5085b3636f8e 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -804,6 +804,11 @@ static int vega20_set_allowed_featuresmask(struct pp_hwmgr 
*hwmgr)
return 0;
 }
 
+static int vega20_run_btc(struct pp_hwmgr *hwmgr)
+{
+   return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunBtc);
+}
+
 static int vega20_run_btc_afll(struct pp_hwmgr *hwmgr)
 {
return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAfllBtc);
@@ -1565,6 +1570,11 @@ static int vega20_enable_dpm_tasks(struct pp_hwmgr 
*hwmgr)
"[EnableDPMTasks] Failed to initialize SMC table!",
return result);
 
+   result = vega20_run_btc(hwmgr);
+   PP_ASSERT_WITH_CODE(!result,
+   "[EnableDPMTasks] Failed to run btc!",
+   return result);
+
result = vega20_run_btc_afll(hwmgr);
PP_ASSERT_WITH_CODE(!result,
"[EnableDPMTasks] Failed to run btc afll!",
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amd/powerplay: fit the SOC clock also to the new performance level

2019-01-21 Thread Evan Quan
The SOC clock needs also to fit the new performance level.

Change-Id: I24c5c4cdff11a4d2e0946b970ed950a4fc530b0a
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 37 +++
 1 file changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 8c1fa985c7d4..60a22d8da7f0 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -2170,6 +2170,12 @@ static int vega20_force_dpm_highest(struct pp_hwmgr 
*hwmgr)
data->dpm_table.mem_table.dpm_state.soft_max_level =
data->dpm_table.mem_table.dpm_levels[soft_level].value;
 
+   soft_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
+
+   data->dpm_table.soc_table.dpm_state.soft_min_level =
+   data->dpm_table.soc_table.dpm_state.soft_max_level =
+   data->dpm_table.soc_table.dpm_levels[soft_level].value;
+
ret = vega20_upload_dpm_min_level(hwmgr, 0x);
PP_ASSERT_WITH_CODE(!ret,
"Failed to upload boot level to highest!",
@@ -2202,6 +2208,12 @@ static int vega20_force_dpm_lowest(struct pp_hwmgr 
*hwmgr)
data->dpm_table.mem_table.dpm_state.soft_max_level =
data->dpm_table.mem_table.dpm_levels[soft_level].value;
 
+   soft_level = vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
+
+   data->dpm_table.soc_table.dpm_state.soft_min_level =
+   data->dpm_table.soc_table.dpm_state.soft_max_level =
+   data->dpm_table.soc_table.dpm_levels[soft_level].value;
+
ret = vega20_upload_dpm_min_level(hwmgr, 0x);
PP_ASSERT_WITH_CODE(!ret,
"Failed to upload boot level to highest!",
@@ -2218,8 +2230,32 @@ static int vega20_force_dpm_lowest(struct pp_hwmgr 
*hwmgr)
 
 static int vega20_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
 {
+   struct vega20_hwmgr *data =
+   (struct vega20_hwmgr *)(hwmgr->backend);
+   uint32_t soft_min_level, soft_max_level;
int ret = 0;
 
+   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
+   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.gfx_table));
+   data->dpm_table.gfx_table.dpm_state.soft_min_level =
+   data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
+   data->dpm_table.gfx_table.dpm_state.soft_max_level =
+   data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
+
+   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.mem_table));
+   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.mem_table));
+   data->dpm_table.mem_table.dpm_state.soft_min_level =
+   data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
+   data->dpm_table.mem_table.dpm_state.soft_max_level =
+   data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
+
+   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
+   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
+   data->dpm_table.soc_table.dpm_state.soft_min_level =
+   data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
+   data->dpm_table.soc_table.dpm_state.soft_max_level =
+   data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
+
ret = vega20_upload_dpm_min_level(hwmgr, 0x);
PP_ASSERT_WITH_CODE(!ret,
"Failed to upload DPM Bootup Levels!",
@@ -2457,6 +2493,7 @@ static int vega20_dpm_force_dpm_level(struct pp_hwmgr 
*hwmgr,
return ret;
vega20_force_clock_level(hwmgr, PP_SCLK, 1 << sclk_mask);
vega20_force_clock_level(hwmgr, PP_MCLK, 1 << mclk_mask);
+   vega20_force_clock_level(hwmgr, PP_SOCCLK, 1 << soc_mask);
break;
 
case AMD_DPM_FORCED_LEVEL_MANUAL:
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/display: change the max clock level to 16

2019-01-21 Thread Evan Quan
As the gfxclk for SMU11 can have at most 16 discrete levels.

Change-Id: I0c6a8db8f40206a240286471c6f7b1fffef15ea2
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/display/dc/dm_services_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dm_services_types.h 
b/drivers/gpu/drm/amd/display/dc/dm_services_types.h
index 9afd36a031a9..77200711abbe 100644
--- a/drivers/gpu/drm/amd/display/dc/dm_services_types.h
+++ b/drivers/gpu/drm/amd/display/dc/dm_services_types.h
@@ -92,7 +92,7 @@ enum dm_pp_clock_type {
(clk_type) == DM_PP_CLOCK_TYPE_FCLK ? "F" : \
"Invalid"
 
-#define DM_PP_MAX_CLOCK_LEVELS 8
+#define DM_PP_MAX_CLOCK_LEVELS 16
 
 struct dm_pp_clock_levels {
uint32_t num_levels;
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amd/powerplay: support Vega10 fan table V3

2019-01-22 Thread Evan Quan
MGPU fan boost related parameter is added.

Change-Id: Iaa6c570373d81199a07028f275b083f459952254
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega10_pptable.h  | 24 +
 .../powerplay/hwmgr/vega10_processpptables.c  | 50 ++-
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h |  1 +
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_pptable.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_pptable.h
index b3e63003a789..c934e9612c1b 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_pptable.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_pptable.h
@@ -282,6 +282,30 @@ typedef struct _ATOM_Vega10_Fan_Table_V2 {
UCHAR   ucFanMaxRPM;
 } ATOM_Vega10_Fan_Table_V2;
 
+typedef struct _ATOM_Vega10_Fan_Table_V3 {
+   UCHAR   ucRevId;
+   USHORT  usFanOutputSensitivity;
+   USHORT  usFanAcousticLimitRpm;
+   USHORT  usThrottlingRPM;
+   USHORT  usTargetTemperature;
+   USHORT  usMinimumPWMLimit;
+   USHORT  usTargetGfxClk;
+   USHORT  usFanGainEdge;
+   USHORT  usFanGainHotspot;
+   USHORT  usFanGainLiquid;
+   USHORT  usFanGainVrVddc;
+   USHORT  usFanGainVrMvdd;
+   USHORT  usFanGainPlx;
+   USHORT  usFanGainHbm;
+   UCHAR   ucEnableZeroRPM;
+   USHORT  usFanStopTemperature;
+   USHORT  usFanStartTemperature;
+   UCHAR   ucFanParameters;
+   UCHAR   ucFanMinRPM;
+   UCHAR   ucFanMaxRPM;
+   USHORT  usMGpuThrottlingRPM;
+} ATOM_Vega10_Fan_Table_V3;
+
 typedef struct _ATOM_Vega10_Thermal_Controller {
UCHAR ucRevId;
UCHAR ucType;   /* one of ATOM_VEGA10_PP_THERMALCONTROLLER_*/
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_processpptables.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_processpptables.c
index 99d596dc0e89..b6767d74dc85 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_processpptables.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_processpptables.c
@@ -123,6 +123,7 @@ static int init_thermal_controller(
const Vega10_PPTable_Generic_SubTable_Header *header;
const ATOM_Vega10_Fan_Table *fan_table_v1;
const ATOM_Vega10_Fan_Table_V2 *fan_table_v2;
+   const ATOM_Vega10_Fan_Table_V3 *fan_table_v3;
 
thermal_controller = (ATOM_Vega10_Thermal_Controller *)
(((unsigned long)powerplay_table) +
@@ -207,7 +208,7 @@ static int init_thermal_controller(
le16_to_cpu(fan_table_v1->usFanStopTemperature);

hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStartTemperature 
=

le16_to_cpu(fan_table_v1->usFanStartTemperature);
-   } else if (header->ucRevId > 10) {
+   } else if (header->ucRevId == 0xb) {
fan_table_v2 = (ATOM_Vega10_Fan_Table_V2 *)header;
 

hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution =
@@ -251,7 +252,54 @@ static int init_thermal_controller(
le16_to_cpu(fan_table_v2->usFanStopTemperature);

hwmgr->thermal_controller.advanceFanControlParameters.usZeroRPMStartTemperature 
=

le16_to_cpu(fan_table_v2->usFanStartTemperature);
+   } else if (header->ucRevId > 0xb) {
+   fan_table_v3 = (ATOM_Vega10_Fan_Table_V3 *)header;
+
+   
hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution =
+   fan_table_v3->ucFanParameters & 
ATOM_VEGA10_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
+   hwmgr->thermal_controller.fanInfo.ulMinRPM = 
fan_table_v3->ucFanMinRPM * 100UL;
+   hwmgr->thermal_controller.fanInfo.ulMaxRPM = 
fan_table_v3->ucFanMaxRPM * 100UL;
+   phm_cap_set(hwmgr->platform_descriptor.platformCaps,
+   PHM_PlatformCaps_MicrocodeFanControl);
+   
hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
+   
le16_to_cpu(fan_table_v3->usFanOutputSensitivity);
+   
hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM =
+   fan_table_v3->ucFanMaxRPM * 100UL;
+   
hwmgr->thermal_controller.advanceFanControlParameters.usFanRPMMaxLimit =
+   le16_to_cpu(fan_table_v3->usThrottlingRPM);
+   
hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit 
=
+   
le16_to_cpu(fan_table_v3->usFanAcousticLimitRpm);
+   hwmgr->thermal_controller.advanceFanControlParameters.usTMax =
+   le16_to_cpu(fan_table_v3->usTargetTemperature);
+   hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin =
+ 

[PATCH 2/2] drm/amd/powerplay: enable MGPU fan boost feature on Vega10

2019-01-22 Thread Evan Quan
For those SKUs which support this feature only.

Change-Id: I74de00204d93f951e04073e5c4c4ce9c0d34f662
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.c|  1 +
 .../drm/amd/powerplay/hwmgr/vega10_thermal.c  | 37 +++
 .../drm/amd/powerplay/hwmgr/vega10_thermal.h  |  1 +
 3 files changed, 39 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index f0ba4254361b..1a4c6467a36d 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -5168,6 +5168,7 @@ static const struct pp_hwmgr_func vega10_hwmgr_funcs = {
.set_asic_baco_state = vega10_baco_set_state,
.get_ppfeature_status = vega10_get_ppfeature_status,
.set_ppfeature_status = vega10_set_ppfeature_status,
+   .enable_mgpu_fan_boost = vega10_enable_mgpu_fan_boost,
 };
 
 int vega10_hwmgr_init(struct pp_hwmgr *hwmgr)
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
index 3f807d6c95ce..ba8763daa380 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
@@ -556,6 +556,43 @@ int vega10_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
return ret;
 }
 
+int vega10_enable_mgpu_fan_boost(struct pp_hwmgr *hwmgr)
+{
+   struct vega10_hwmgr *data = hwmgr->backend;
+   PPTable_t *table = &(data->smc_state_table.pp_table);
+   int ret;
+
+   if (!data->smu_features[GNLD_FAN_CONTROL].supported)
+   return 0;
+
+   if (!hwmgr->thermal_controller.advanceFanControlParameters.
+   usMGpuThrottlingRPMLimit)
+   return 0;
+
+   table->FanThrottlingRpm = hwmgr->thermal_controller.
+   advanceFanControlParameters.usMGpuThrottlingRPMLimit;
+
+   ret = smum_smc_table_manager(hwmgr,
+   (uint8_t *)(&(data->smc_state_table.pp_table)),
+   PPTABLE, false);
+   if (ret) {
+   pr_info("Failed to update fan control table in pptable!");
+   return ret;
+   }
+
+   ret = vega10_disable_fan_control_feature(hwmgr);
+   if (ret) {
+   pr_info("Attempt to disable SMC fan control feature failed!");
+   return ret;
+   }
+
+   ret = vega10_enable_fan_control_feature(hwmgr);
+   if (ret)
+   pr_info("Attempt to enable SMC fan control feature failed!");
+
+   return ret;
+}
+
 /**
 * Start the fan control on the SMC.
 * @paramhwmgr  the address of the powerplay hardware manager.
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.h
index 21e7c4dfa2ca..4a0ede7c1f07 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.h
@@ -73,6 +73,7 @@ extern int vega10_thermal_disable_alert(struct pp_hwmgr 
*hwmgr);
 extern int vega10_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr);
 extern int vega10_start_thermal_controller(struct pp_hwmgr *hwmgr,
struct PP_TemperatureRange *range);
+extern int vega10_enable_mgpu_fan_boost(struct pp_hwmgr *hwmgr);
 
 
 #endif
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 4/4] drm/amd/powerplay: support Vega12 retrieving and setting ppfeatures

2019-01-23 Thread Evan Quan
Enable retrieving and setting ppfeatures on Vega12.

Change-Id: Idad5eaadbb9e7ea73edd9e9d4fe4e1a5b17fb7a6
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega12_hwmgr.c| 100 ++
 1 file changed, 100 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
index 45a45669d2ec..342f8b81ca82 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
@@ -1933,6 +1933,104 @@ static int vega12_force_clock_level(struct pp_hwmgr 
*hwmgr,
return 0;
 }
 
+static int vega12_get_ppfeature_status(struct pp_hwmgr *hwmgr, char *buf)
+{
+   static const char *ppfeature_name[] = {
+   "DPM_PREFETCHER",
+   "GFXCLK_DPM",
+   "UCLK_DPM",
+   "SOCCLK_DPM",
+   "UVD_DPM",
+   "VCE_DPM",
+   "ULV",
+   "MP0CLK_DPM",
+   "LINK_DPM",
+   "DCEFCLK_DPM",
+   "GFXCLK_DS",
+   "SOCCLK_DS",
+   "LCLK_DS",
+   "PPT",
+   "TDC",
+   "THERMAL",
+   "GFX_PER_CU_CG",
+   "RM",
+   "DCEFCLK_DS",
+   "ACDC",
+   "VR0HOT",
+   "VR1HOT",
+   "FW_CTF",
+   "LED_DISPLAY",
+   "FAN_CONTROL",
+   "DIDT",
+   "GFXOFF",
+   "CG",
+   "ACG"};
+   static const char *output_title[] = {
+   "FEATURES",
+   "BITMASK",
+   "ENABLEMENT"};
+   uint64_t features_enabled;
+   int i;
+   int ret = 0;
+   int size = 0;
+
+   ret = vega12_get_enabled_smc_features(hwmgr, &features_enabled);
+   PP_ASSERT_WITH_CODE(!ret,
+   "[EnableAllSmuFeatures] Failed to get enabled smc 
features!",
+   return ret);
+
+   size += sprintf(buf + size, "Current ppfeatures: 0x%016llx\n", 
features_enabled);
+   size += sprintf(buf + size, "%-19s %-22s %s\n",
+   output_title[0],
+   output_title[1],
+   output_title[2]);
+   for (i = 0; i < GNLD_FEATURES_MAX; i++) {
+   size += sprintf(buf + size, "%-19s 0x%016llx %6s\n",
+   ppfeature_name[i],
+   1ULL << i,
+   (features_enabled & (1ULL << i)) ? "Y" 
: "N");
+   }
+
+   return size;
+}
+
+static int vega12_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t 
new_ppfeature_masks)
+{
+   uint64_t features_enabled;
+   uint64_t features_to_enable;
+   uint64_t features_to_disable;
+   int ret = 0;
+
+   if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
+   return -EINVAL;
+
+   ret = vega12_get_enabled_smc_features(hwmgr, &features_enabled);
+   if (ret)
+   return ret;
+
+   features_to_disable =
+   (features_enabled ^ new_ppfeature_masks) & features_enabled;
+   features_to_enable =
+   (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
+
+   pr_debug("features_to_disable 0x%llx\n", features_to_disable);
+   pr_debug("features_to_enable 0x%llx\n", features_to_enable);
+
+   if (features_to_disable) {
+   ret = vega12_enable_smc_features(hwmgr, false, 
features_to_disable);
+   if (ret)
+   return ret;
+   }
+
+   if (features_to_enable) {
+   ret = vega12_enable_smc_features(hwmgr, true, 
features_to_enable);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 static int vega12_print_clock_levels(struct pp_hwmgr *hwmgr,
enum pp_clock_type type, char *buf)
 {
@@ -2528,6 +2626,8 @@ static const struct pp_hwmgr_func ve

[PATCH 1/4] drm/amd/powerplay: support Vega10 SOCclk and DCEFclk dpm level settings

2019-01-23 Thread Evan Quan
Enable SOCclk and DCEFclk dpm level retrieving and setting on Vega10.

Change-Id: I5bcd2e9984b5b7fdb991718d8384d65290672df6
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.c| 83 +++
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.h|  1 +
 2 files changed, 84 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index d1e262844619..a08e4fa3ae59 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -72,6 +72,21 @@ static const uint32_t channel_number[] = {1, 2, 0, 4, 0, 8, 
0, 16, 2};
 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 
   0x0700L
 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 
   0xF000L
 
+typedef enum {
+  CLK_SMNCLK = 0,
+  CLK_SOCCLK,
+  CLK_MP0CLK,
+  CLK_MP1CLK,
+  CLK_LCLK,
+  CLK_DCEFCLK,
+  CLK_VCLK,
+  CLK_DCLK,
+  CLK_ECLK,
+  CLK_UCLK,
+  CLK_GFXCLK,
+  CLK_COUNT,
+} CLOCK_ID_e;
+
 static const ULONG PhwVega10_Magic = (ULONG)(PHM_VIslands_Magic);
 
 struct vega10_power_state *cast_phw_vega10_power_state(
@@ -3486,6 +3501,17 @@ static int vega10_upload_dpm_bootup_level(struct 
pp_hwmgr *hwmgr)
}
}
 
+   if (!data->registry_data.socclk_dpm_key_disabled) {
+   if (data->smc_state_table.soc_boot_level !=
+   
data->dpm_table.soc_table.dpm_state.soft_min_level) {
+   smum_send_msg_to_smc_with_parameter(hwmgr,
+   PPSMC_MSG_SetSoftMinSocclkByIndex,
+   data->smc_state_table.soc_boot_level);
+   data->dpm_table.soc_table.dpm_state.soft_min_level =
+   data->smc_state_table.soc_boot_level;
+   }
+   }
+
return 0;
 }
 
@@ -3517,6 +3543,17 @@ static int vega10_upload_dpm_max_level(struct pp_hwmgr 
*hwmgr)
}
}
 
+   if (!data->registry_data.socclk_dpm_key_disabled) {
+   if (data->smc_state_table.soc_max_level !=
+   data->dpm_table.soc_table.dpm_state.soft_max_level) {
+   smum_send_msg_to_smc_with_parameter(hwmgr,
+   PPSMC_MSG_SetSoftMaxSocclkByIndex,
+   data->smc_state_table.soc_max_level);
+   data->dpm_table.soc_table.dpm_state.soft_max_level =
+   data->smc_state_table.soc_max_level;
+   }
+   }
+
return 0;
 }
 
@@ -4029,6 +4066,24 @@ static int vega10_force_clock_level(struct pp_hwmgr 
*hwmgr,
 
break;
 
+   case PP_SOCCLK:
+   data->smc_state_table.soc_boot_level = mask ? (ffs(mask) - 1) : 
0;
+   data->smc_state_table.soc_max_level = mask ? (fls(mask) - 1) : 
0;
+
+   PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
+   "Failed to upload boot level to lowest!",
+   return -EINVAL);
+
+   PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
+   "Failed to upload dpm max level to highest!",
+   return -EINVAL);
+
+   break;
+
+   case PP_DCEFCLK:
+   pr_info("Setting DCEFCLK min/max dpm level is not 
supported!\n");
+   break;
+
case PP_PCIE:
default:
break;
@@ -4274,6 +4329,8 @@ static int vega10_print_clock_levels(struct pp_hwmgr 
*hwmgr,
struct vega10_hwmgr *data = hwmgr->backend;
struct vega10_single_dpm_table *sclk_table = 
&(data->dpm_table.gfx_table);
struct vega10_single_dpm_table *mclk_table = 
&(data->dpm_table.mem_table);
+   struct vega10_single_dpm_table *soc_table = 
&(data->dpm_table.soc_table);
+   struct vega10_single_dpm_table *dcef_table = 
&(data->dpm_table.dcef_table);
struct vega10_pcie_table *pcie_table = &(data->dpm_table.pcie_table);
struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep = NULL;
 
@@ -4304,6 +4361,32 @@ static int vega10_print_clock_levels(struct pp_hwmgr 
*hwmgr,
i, mclk_table->dpm_levels[i].value / 
100,
(i == now) ? "*" : "");
break;
+   case PP_SOCCLK:
+   if (data->registry_data.socclk_dpm_key_disabled)
+   break;
+
+   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentSocclkIndex);
+   now = smum_get_argument(hwmgr);
+
+   for (i = 0; i < soc_table->count; i++)
+  

[PATCH 2/4] drm/amd/powerplay: support Vega10 retrieving and setting ppfeatures

2019-01-23 Thread Evan Quan
Enable retrieving and setting ppfeatures on Vega10.

Change-Id: I44ea8789ad3c59cfb40a367665a6190f4405610e
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.c| 101 ++
 1 file changed, 101 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index a08e4fa3ae59..f0ba4254361b 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -4323,6 +4323,105 @@ static int 
vega10_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
return result;
 }
 
+static int vega10_get_ppfeature_status(struct pp_hwmgr *hwmgr, char *buf)
+{
+   static const char *ppfeature_name[] = {
+   "DPM_PREFETCHER",
+   "GFXCLK_DPM",
+   "UCLK_DPM",
+   "SOCCLK_DPM",
+   "UVD_DPM",
+   "VCE_DPM",
+   "ULV",
+   "MP0CLK_DPM",
+   "LINK_DPM",
+   "DCEFCLK_DPM",
+   "AVFS",
+   "GFXCLK_DS",
+   "SOCCLK_DS",
+   "LCLK_DS",
+   "PPT",
+   "TDC",
+   "THERMAL",
+   "GFX_PER_CU_CG",
+   "RM",
+   "DCEFCLK_DS",
+   "ACDC",
+   "VR0HOT",
+   "VR1HOT",
+   "FW_CTF",
+   "LED_DISPLAY",
+   "FAN_CONTROL",
+   "FAST_PPT",
+   "DIDT",
+   "ACG",
+   "PCC_LIMIT"};
+   static const char *output_title[] = {
+   "FEATURES",
+   "BITMASK",
+   "ENABLEMENT"};
+   uint64_t features_enabled;
+   int i;
+   int ret = 0;
+   int size = 0;
+
+   ret = vega10_get_enabled_smc_features(hwmgr, &features_enabled);
+   PP_ASSERT_WITH_CODE(!ret,
+   "[EnableAllSmuFeatures] Failed to get enabled smc 
features!",
+   return ret);
+
+   size += sprintf(buf + size, "Current ppfeatures: 0x%016llx\n", 
features_enabled);
+   size += sprintf(buf + size, "%-19s %-22s %s\n",
+   output_title[0],
+   output_title[1],
+   output_title[2]);
+   for (i = 0; i < GNLD_FEATURES_MAX; i++) {
+   size += sprintf(buf + size, "%-19s 0x%016llx %6s\n",
+   ppfeature_name[i],
+   1ULL << i,
+   (features_enabled & (1ULL << i)) ? "Y" 
: "N");
+   }
+
+   return size;
+}
+
+static int vega10_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t 
new_ppfeature_masks)
+{
+   uint64_t features_enabled;
+   uint64_t features_to_enable;
+   uint64_t features_to_disable;
+   int ret = 0;
+
+   if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
+   return -EINVAL;
+
+   ret = vega10_get_enabled_smc_features(hwmgr, &features_enabled);
+   if (ret)
+   return ret;
+
+   features_to_disable =
+   (features_enabled ^ new_ppfeature_masks) & features_enabled;
+   features_to_enable =
+   (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
+
+   pr_debug("features_to_disable 0x%llx\n", features_to_disable);
+   pr_debug("features_to_enable 0x%llx\n", features_to_enable);
+
+   if (features_to_disable) {
+   ret = vega10_enable_smc_features(hwmgr, false, 
features_to_disable);
+   if (ret)
+   return ret;
+   }
+
+   if (features_to_enable) {
+   ret = vega10_enable_smc_features(hwmgr, true, 
features_to_enable);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 static int vega10_print_clock_levels(struct pp_hwmgr *hwmgr,
enum pp_clock

[PATCH 3/4] drm/amd/powerplay: support Vega12 SOCclk and DCEFclk dpm level settings

2019-01-23 Thread Evan Quan
Enable SOCclk and DCEFclk dpm level retrieving and setting on Vega12.

Change-Id: Ieb3e06dcdfe5dd67c3f27f6fdb9a6bb408034faf
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega12_hwmgr.c| 98 ++-
 1 file changed, 97 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
index 0c8212902275..45a45669d2ec 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
@@ -1093,6 +1093,16 @@ static int vega12_upload_dpm_min_level(struct pp_hwmgr 
*hwmgr)
return ret);
}
 
+   if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
+   min_freq = data->dpm_table.dcef_table.dpm_state.hard_min_level;
+
+   PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
+   hwmgr, PPSMC_MSG_SetHardMinByFreq,
+   (PPCLK_DCEFCLK << 16) | (min_freq & 
0x))),
+   "Failed to set hard min dcefclk!",
+   return ret);
+   }
+
return ret;
 
 }
@@ -1818,7 +1828,7 @@ static int vega12_force_clock_level(struct pp_hwmgr 
*hwmgr,
enum pp_clock_type type, uint32_t mask)
 {
struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
-   uint32_t soft_min_level, soft_max_level;
+   uint32_t soft_min_level, soft_max_level, hard_min_level;
int ret = 0;
 
switch (type) {
@@ -1863,6 +1873,56 @@ static int vega12_force_clock_level(struct pp_hwmgr 
*hwmgr,
 
break;
 
+   case PP_SOCCLK:
+   soft_min_level = mask ? (ffs(mask) - 1) : 0;
+   soft_max_level = mask ? (fls(mask) - 1) : 0;
+
+   if (soft_max_level >= data->dpm_table.soc_table.count) {
+   pr_err("Clock level specified %d is over max allowed 
%d\n",
+   soft_max_level,
+   data->dpm_table.soc_table.count - 1);
+   return -EINVAL;
+   }
+
+   data->dpm_table.soc_table.dpm_state.soft_min_level =
+   
data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
+   data->dpm_table.soc_table.dpm_state.soft_max_level =
+   
data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
+
+   ret = vega12_upload_dpm_min_level(hwmgr);
+   PP_ASSERT_WITH_CODE(!ret,
+   "Failed to upload boot level to lowest!",
+   return ret);
+
+   ret = vega12_upload_dpm_max_level(hwmgr);
+   PP_ASSERT_WITH_CODE(!ret,
+   "Failed to upload dpm max level to highest!",
+   return ret);
+
+   break;
+
+   case PP_DCEFCLK:
+   hard_min_level = mask ? (ffs(mask) - 1) : 0;
+
+   if (hard_min_level >= data->dpm_table.dcef_table.count) {
+   pr_err("Clock level specified %d is over max allowed 
%d\n",
+   hard_min_level,
+   data->dpm_table.dcef_table.count - 1);
+   return -EINVAL;
+   }
+
+   data->dpm_table.dcef_table.dpm_state.hard_min_level =
+   
data->dpm_table.dcef_table.dpm_levels[hard_min_level].value;
+
+   ret = vega12_upload_dpm_min_level(hwmgr);
+   PP_ASSERT_WITH_CODE(!ret,
+   "Failed to upload boot level to lowest!",
+   return ret);
+
+   //TODO: Setting DCEFCLK max dpm level is not supported
+
+   break;
+
case PP_PCIE:
break;
 
@@ -1912,6 +1972,42 @@ static int vega12_print_clock_levels(struct pp_hwmgr 
*hwmgr,
(clocks.data[i].clocks_in_khz / 1000 == now / 
100) ? "*" : "");
break;
 
+   case PP_SOCCLK:
+   PP_ASSERT_WITH_CODE(
+   smum_send_msg_to_smc_with_parameter(hwmgr,
+   PPSMC_MSG_GetDpmClockFreq, 
(PPCLK_SOCCLK << 16)) == 0,
+   "Attempt to get Current SOCCLK Frequency 
Failed!",
+   return -EINVAL);
+   now = smum_get_argument(hwmgr);
+
+   PP_ASSERT_WITH_CODE(
+   vega12_get_socclocks(hwmgr, &clocks) == 0,
+   "Attempt to get soc clk levels Failed!",
+   return -1);
+   for (i = 0; i &

[PATCH 1/2] drm/amd/powerplay: correct Vega20 gfxclk readout under DS

2019-01-24 Thread Evan Quan
Current implementation cannot report the correct gfxclk under DS.

Change-Id: Ief979ae1ddc6f8107535d45052c517bafde91bf5
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 5085b3636f8e..13f124125f5a 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -2013,16 +2013,20 @@ static int vega20_read_sensor(struct pp_hwmgr *hwmgr, 
int idx,
 {
struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
struct amdgpu_device *adev = hwmgr->adev;
+   SmuMetrics_t metrics_table;
uint32_t val_vid;
int ret = 0;
 
switch (idx) {
case AMDGPU_PP_SENSOR_GFX_SCLK:
-   ret = vega20_get_current_clk_freq(hwmgr,
-   PPCLK_GFXCLK,
-   (uint32_t *)value);
-   if (!ret)
-   *size = 4;
+   ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table,
+   TABLE_SMU_METRICS, true);
+   PP_ASSERT_WITH_CODE(!ret,
+   "Failed to export SMU METRICS table!",
+   return ret);
+
+   *((uint32_t *)value) = metrics_table.AverageGfxclkFrequency * 
100;
+   *size = 4;
break;
case AMDGPU_PP_SENSOR_GFX_MCLK:
ret = vega20_get_current_clk_freq(hwmgr,
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: avoid frequent metrics table export

2019-01-24 Thread Evan Quan
That's unnecessary. Also it makes more sense to show all the clocks
on one metrics table export.

Change-Id: I6350911934dbd85dc701de17ccc0e9cbddda4648
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 43 +--
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.h|  3 ++
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 13f124125f5a..7b49a9a13a4a 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -1958,16 +1958,36 @@ static uint32_t vega20_dpm_get_mclk(struct pp_hwmgr 
*hwmgr, bool low)
return (mem_clk * 100);
 }
 
+static int vega20_get_metrics_table(struct pp_hwmgr *hwmgr, SmuMetrics_t 
*metrics_table)
+{
+   struct vega20_hwmgr *data =
+   (struct vega20_hwmgr *)(hwmgr->backend);
+   int ret = 0;
+
+   if (!data->metrics_time || time_after(jiffies, data->metrics_time + HZ 
/ 2)) {
+   ret = smum_smc_table_manager(hwmgr, (uint8_t *)metrics_table,
+   TABLE_SMU_METRICS, true);
+   if (ret) {
+   pr_info("Failed to export SMU metrics table!\n");
+   return ret;
+   }
+   memcpy(&data->metrics_table, metrics_table, 
sizeof(SmuMetrics_t));
+   data->metrics_time = jiffies;
+   } else
+   memcpy(metrics_table, &data->metrics_table, 
sizeof(SmuMetrics_t));
+
+   return ret;
+}
+
 static int vega20_get_gpu_power(struct pp_hwmgr *hwmgr,
uint32_t *query)
 {
int ret = 0;
SmuMetrics_t metrics_table;
 
-   ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table, 
TABLE_SMU_METRICS, true);
-   PP_ASSERT_WITH_CODE(!ret,
-   "Failed to export SMU METRICS table!",
-   return ret);
+   ret = vega20_get_metrics_table(hwmgr, &metrics_table);
+   if (ret)
+   return ret;
 
*query = metrics_table.CurrSocketPower << 8;
 
@@ -1998,10 +2018,9 @@ static int vega20_get_current_activity_percent(struct 
pp_hwmgr *hwmgr,
int ret = 0;
SmuMetrics_t metrics_table;
 
-   ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table, 
TABLE_SMU_METRICS, true);
-   PP_ASSERT_WITH_CODE(!ret,
-   "Failed to export SMU METRICS table!",
-   return ret);
+   ret = vega20_get_metrics_table(hwmgr, &metrics_table);
+   if (ret)
+   return ret;
 
*activity_percent = metrics_table.AverageGfxActivity;
 
@@ -2019,11 +2038,9 @@ static int vega20_read_sensor(struct pp_hwmgr *hwmgr, 
int idx,
 
switch (idx) {
case AMDGPU_PP_SENSOR_GFX_SCLK:
-   ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table,
-   TABLE_SMU_METRICS, true);
-   PP_ASSERT_WITH_CODE(!ret,
-   "Failed to export SMU METRICS table!",
-   return ret);
+   ret = vega20_get_metrics_table(hwmgr, &metrics_table);
+   if (ret)
+   return ret;
 
*((uint32_t *)value) = metrics_table.AverageGfxclkFrequency * 
100;
*size = 4;
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
index 25faaa5c5b10..37f5f5e657da 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
@@ -520,6 +520,9 @@ struct vega20_hwmgr {
/*  Gfxoff  */
bool   gfxoff_allowed;
uint32_t   counter_gfxoff;
+
+   unsigned long  metrics_time;
+   SmuMetrics_t   metrics_table;
 };
 
 #define VEGA20_DPM2_NEAR_TDP_DEC  10
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: fix the confusing ppfeature mask calculations

2019-02-18 Thread Evan Quan
Simplify the ppfeature mask calculations.

Change-Id: I41dee48c2ac8ed1fd7736bc8bb1f832da22cba13
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c | 4 ++--
 drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c | 4 ++--
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
index 5479125ff4f6..6d8e9609e900 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c
@@ -4407,9 +4407,9 @@ static int vega10_set_ppfeature_status(struct pp_hwmgr 
*hwmgr, uint64_t new_ppfe
return ret;
 
features_to_disable =
-   (features_enabled ^ new_ppfeature_masks) & features_enabled;
+   features_enabled & ~new_ppfeature_masks;
features_to_enable =
-   (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
+   ~features_enabled & new_ppfeature_masks;
 
pr_debug("features_to_disable 0x%llx\n", features_to_disable);
pr_debug("features_to_enable 0x%llx\n", features_to_enable);
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
index 6c8e78611c03..bdb48e94eff6 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega12_hwmgr.c
@@ -2009,9 +2009,9 @@ static int vega12_set_ppfeature_status(struct pp_hwmgr 
*hwmgr, uint64_t new_ppfe
return ret;
 
features_to_disable =
-   (features_enabled ^ new_ppfeature_masks) & features_enabled;
+   features_enabled & ~new_ppfeature_masks;
features_to_enable =
-   (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
+   ~features_enabled & new_ppfeature_masks;
 
pr_debug("features_to_disable 0x%llx\n", features_to_disable);
pr_debug("features_to_enable 0x%llx\n", features_to_enable);
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index aad79affb081..2cf45a69faf7 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -3088,9 +3088,9 @@ static int vega20_set_ppfeature_status(struct pp_hwmgr 
*hwmgr, uint64_t new_ppfe
return ret;
 
features_to_disable =
-   (features_enabled ^ new_ppfeature_masks) & features_enabled;
+   features_enabled & ~new_ppfeature_masks;
features_to_enable =
-   (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
+   ~features_enabled & new_ppfeature_masks;
 
pr_debug("features_to_disable 0x%llx\n", features_to_disable);
pr_debug("features_to_enable 0x%llx\n", features_to_enable);
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 5/8] drm/amd/powerplay: support retrieving clock information from other sysplls

2019-02-21 Thread Evan Quan
There will be some needs to retrieve clock information from other
sysplls also except default 0.

Change-Id: I312f11679b5c146f7315d096fab1d051ce6ecc6c
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/ppatomfwctrl.c| 27 ++-
 .../drm/amd/powerplay/hwmgr/ppatomfwctrl.h|  3 ++-
 .../drm/amd/powerplay/hwmgr/vega10_hwmgr.c|  4 +--
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
index 4588bddf8b33..a28192bfb035 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
@@ -489,15 +489,16 @@ int pp_atomfwctrl_get_gpio_information(struct pp_hwmgr 
*hwmgr,
 }
 
 int pp_atomfwctrl_get_clk_information_by_clkid(struct pp_hwmgr *hwmgr,
-  uint8_t id, uint32_t *frequency)
+  uint8_t clk_id, uint8_t 
syspll_id,
+  uint32_t *frequency)
 {
struct amdgpu_device *adev = hwmgr->adev;
struct atom_get_smu_clock_info_parameters_v3_1   parameters;
struct atom_get_smu_clock_info_output_parameters_v3_1 *output;
uint32_t ix;
 
-   parameters.clk_id = id;
-   parameters.syspll_id = 0;
+   parameters.clk_id = clk_id;
+   parameters.syspll_id = syspll_id;
parameters.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
parameters.dfsdid = 0;
 
@@ -530,19 +531,19 @@ static void 
pp_atomfwctrl_copy_vbios_bootup_values_3_2(struct pp_hwmgr *hwmgr,
boot_values->ulSocClk   = 0;
boot_values->ulDCEFClk   = 0;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_SOCCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_SOCCLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulSocClk   = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_DCEFCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_DCEFCLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulDCEFClk  = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_ECLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_ECLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulEClk = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_VCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_VCLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulVClk = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_DCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_DCLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulDClk = frequency;
 }
 
@@ -563,19 +564,19 @@ static void 
pp_atomfwctrl_copy_vbios_bootup_values_3_1(struct pp_hwmgr *hwmgr,
boot_values->ulSocClk   = 0;
boot_values->ulDCEFClk   = 0;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_SOCCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_SOCCLK_ID, 0, &frequency))
boot_values->ulSocClk   = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_DCEFCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_DCEFCLK_ID, 0, &frequency))
boot_values->ulDCEFClk  = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_ECLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_ECLK_ID, 0, &frequency))
boot_values->ulEClk = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_VCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_VCLK_ID, 0, &frequency))
boot_values->ulVClk = frequency;
 
-   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_DCLK_ID, &frequency))
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU9_SYSPLL0_DCLK_ID, 0, &frequency))
boot_values->ulDClk = frequency;
 }
 
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
index fe9e8ceef50e..9bafd00324a9 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
@@ -236,7 +236,8 @@ 

[PATCH 1/8] drm/amd/powerplay: drop redundant soft min/max settings

2019-02-21 Thread Evan Quan
As these are already set during apply_clocks_adjust_rules.

Change-Id: I7eb845597ebe0527bf853dffae7e578434651091
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 24 ---
 1 file changed, 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index aad79affb081..6bde0782da7d 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -2314,32 +2314,8 @@ static int vega20_force_dpm_lowest(struct pp_hwmgr 
*hwmgr)
 
 static int vega20_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
 {
-   struct vega20_hwmgr *data =
-   (struct vega20_hwmgr *)(hwmgr->backend);
-   uint32_t soft_min_level, soft_max_level;
int ret = 0;
 
-   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
-   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.gfx_table));
-   data->dpm_table.gfx_table.dpm_state.soft_min_level =
-   data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
-   data->dpm_table.gfx_table.dpm_state.soft_max_level =
-   data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
-
-   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.mem_table));
-   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.mem_table));
-   data->dpm_table.mem_table.dpm_state.soft_min_level =
-   data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
-   data->dpm_table.mem_table.dpm_state.soft_max_level =
-   data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
-
-   soft_min_level = 
vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
-   soft_max_level = 
vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
-   data->dpm_table.soc_table.dpm_state.soft_min_level =
-   data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
-   data->dpm_table.soc_table.dpm_state.soft_max_level =
-   data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
-
ret = vega20_upload_dpm_min_level(hwmgr, 0x);
PP_ASSERT_WITH_CODE(!ret,
"Failed to upload DPM Bootup Levels!",
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 4/8] drm/amd/powerplay: overwrite ODSettingsMin for UCLK_FMAX feature

2019-02-21 Thread Evan Quan
For UCLK_FMAX OD feature, SMU overwrites the highest UCLK DPM level freq.
Therefore it can only take values that are greater than the second highest
DPM level freq.

Change-Id: I81eec21d8212ee08425c6462376b82690f4f8038
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index c594ca4ef17e..15408807e23e 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -979,6 +979,8 @@ static int vega20_od8_set_feature_capabilities(
}
 
if (data->smu_features[GNLD_DPM_UCLK].enabled) {
+   pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] =
+   
data->dpm_table.mem_table.dpm_levels[data->dpm_table.mem_table.count - 2].value;
if 
(pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_UCLK_MAX] &&
pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] 
> 0 &&
pptable_information->od_settings_max[OD8_SETTING_UCLK_FMAX] 
> 0 &&
@@ -2775,7 +2777,6 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr 
*hwmgr,
data->od8_settings.od8_settings_array;
OverDriveTable_t *od_table =
&(data->smc_state_table.overdrive_table);
-   struct pp_clock_levels_with_latency clocks;
int32_t input_index, input_clk, input_vol, i;
int od8_id;
int ret;
@@ -2834,11 +2835,6 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr 
*hwmgr,
return -EOPNOTSUPP;
}
 
-   ret = vega20_get_memclocks(hwmgr, &clocks);
-   PP_ASSERT_WITH_CODE(!ret,
-   "Attempt to get memory clk levels failed!",
-   return ret);
-
for (i = 0; i < size; i += 2) {
if (i + 2 > size) {
pr_info("invalid number of input parameters 
%d\n",
@@ -2855,11 +2851,11 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr 
*hwmgr,
return -EINVAL;
}
 
-   if (input_clk < clocks.data[0].clocks_in_khz / 1000 ||
+   if (input_clk < 
od8_settings[OD8_SETTING_UCLK_FMAX].min_value ||
input_clk > 
od8_settings[OD8_SETTING_UCLK_FMAX].max_value) {
pr_info("clock freq %d is not within allowed 
range [%d - %d]\n",
input_clk,
-   clocks.data[0].clocks_in_khz / 1000,
+   
od8_settings[OD8_SETTING_UCLK_FMAX].min_value,

od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
return -EINVAL;
}
@@ -3264,13 +3260,8 @@ static int vega20_print_clock_levels(struct pp_hwmgr 
*hwmgr,
}
 
if (od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) {
-   ret = vega20_get_memclocks(hwmgr, &clocks);
-   PP_ASSERT_WITH_CODE(!ret,
-   "Fail to get memory clk levels!",
-   return ret);
-
size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n",
-   clocks.data[0].clocks_in_khz / 1000,
+   od8_settings[OD8_SETTING_UCLK_FMAX].min_value,
od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
}
 
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 3/8] drm/amd/powerplay: force FCLK to highest also for 5K or higher displays

2019-02-21 Thread Evan Quan
This can fix possible screen freeze on high resolution displays.

Change-Id: Ia1f1708638a85d57789a61ba0937c5221bd28c31
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 38 ++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 6bde0782da7d..c594ca4ef17e 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -3332,6 +3332,31 @@ static int vega20_set_uclk_to_highest_dpm_level(struct 
pp_hwmgr *hwmgr,
return ret;
 }
 
+static int vega20_set_fclk_to_highest_dpm_level(struct pp_hwmgr *hwmgr)
+{
+   struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
+   struct vega20_single_dpm_table *dpm_table = 
&(data->dpm_table.fclk_table);
+   int ret = 0;
+
+   if (data->smu_features[GNLD_DPM_FCLK].enabled) {
+   PP_ASSERT_WITH_CODE(dpm_table->count > 0,
+   "[SetFclkToHightestDpmLevel] Dpm table has no 
entry!",
+   return -EINVAL);
+   PP_ASSERT_WITH_CODE(dpm_table->count <= NUM_FCLK_DPM_LEVELS,
+   "[SetFclkToHightestDpmLevel] Dpm table has too 
many entries!",
+   return -EINVAL);
+
+   dpm_table->dpm_state.soft_min_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   PP_ASSERT_WITH_CODE(!(ret = 
smum_send_msg_to_smc_with_parameter(hwmgr,
+   PPSMC_MSG_SetSoftMinByFreq,
+   (PPCLK_FCLK << 16 ) | 
dpm_table->dpm_state.soft_min_level)),
+   "[SetFclkToHightestDpmLevel] Set soft min fclk 
failed!",
+   return ret);
+   }
+
+   return ret;
+}
+
 static int vega20_pre_display_configuration_changed_task(struct pp_hwmgr 
*hwmgr)
 {
struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
@@ -3342,8 +3367,10 @@ static int 
vega20_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
 
ret = vega20_set_uclk_to_highest_dpm_level(hwmgr,
&data->dpm_table.mem_table);
+   if (ret)
+   return ret;
 
-   return ret;
+   return vega20_set_fclk_to_highest_dpm_level(hwmgr);
 }
 
 static int vega20_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
@@ -3502,6 +3529,15 @@ static int vega20_apply_clocks_adjust_rules(struct 
pp_hwmgr *hwmgr)
if (hwmgr->display_config->nb_pstate_switch_disable)
dpm_table->dpm_state.hard_min_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
 
+   /* fclk */
+   dpm_table = &(data->dpm_table.fclk_table);
+   dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
+   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
+   dpm_table->dpm_state.hard_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   if (hwmgr->display_config->nb_pstate_switch_disable)
+   dpm_table->dpm_state.soft_min_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+
/* vclk */
dpm_table = &(data->dpm_table.vclk_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 6/8] drm/amd/powerplay: set default fclk for no fclk dpm support case

2019-02-21 Thread Evan Quan
Set the default fclk as what we got from VBIOS.

Change-Id: If1c54dc854a5ebe0cdb439bad8fefc26e80f0511
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c | 3 +++
 drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h | 1 +
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 7 +--
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h | 1 +
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
index a28192bfb035..615cf2c09e54 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.c
@@ -545,6 +545,9 @@ static void 
pp_atomfwctrl_copy_vbios_bootup_values_3_2(struct pp_hwmgr *hwmgr,
 
if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL0_DCLK_ID, SMU11_SYSPLL0_ID, &frequency))
boot_values->ulDClk = frequency;
+
+   if (!pp_atomfwctrl_get_clk_information_by_clkid(hwmgr, 
SMU11_SYSPLL1_0_FCLK_ID, SMU11_SYSPLL1_2_ID, &frequency))
+   boot_values->ulFClk = frequency;
 }
 
 static void pp_atomfwctrl_copy_vbios_bootup_values_3_1(struct pp_hwmgr *hwmgr,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
index 9bafd00324a9..b7e2651b570b 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomfwctrl.h
@@ -139,6 +139,7 @@ struct pp_atomfwctrl_bios_boot_up_values {
uint32_t   ulEClk;
uint32_t   ulVClk;
uint32_t   ulDClk;
+   uint32_t   ulFClk;
uint16_t   usVddc;
uint16_t   usVddci;
uint16_t   usMvddc;
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 15408807e23e..1f63fb4e7610 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -711,8 +711,10 @@ static int vega20_setup_default_dpm_tables(struct pp_hwmgr 
*hwmgr)
PP_ASSERT_WITH_CODE(!ret,
"[SetupDefaultDpmTable] failed to get fclk dpm 
levels!",
return ret);
-   } else
-   dpm_table->count = 0;
+   } else {
+   dpm_table->count = 1;
+   dpm_table->dpm_levels[0].value = data->vbios_boot_state.fclock 
/ 100;
+   }
vega20_init_dpm_state(&(dpm_table->dpm_state));
 
/* save a copy of the default DPM table */
@@ -754,6 +756,7 @@ static int vega20_init_smc_table(struct pp_hwmgr *hwmgr)
data->vbios_boot_state.eclock = boot_up_values.ulEClk;
data->vbios_boot_state.vclock = boot_up_values.ulVClk;
data->vbios_boot_state.dclock = boot_up_values.ulDClk;
+   data->vbios_boot_state.fclock = boot_up_values.ulFClk;
data->vbios_boot_state.uc_cooling_id = boot_up_values.ucCoolingID;
 
smum_send_msg_to_smc_with_parameter(hwmgr,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
index 37f5f5e657da..4a4cad35dc8f 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h
@@ -219,6 +219,7 @@ struct vega20_vbios_boot_state {
uint32_teclock;
uint32_tdclock;
uint32_tvclock;
+   uint32_tfclock;
 };
 
 #define DPMTABLE_OD_UPDATE_SCLK 0x0001
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 7/8] drm/amd/powerplay: honor the OD settings

2019-02-21 Thread Evan Quan
Set the soft/hard max settings as max possible to
not violate the OD settings.

Change-Id: Ia87eb13b914cb85aac64525a30ef7af57fddf912
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 32 +--
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.h|  2 ++
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 1f63fb4e7610..740268315adf 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -463,9 +463,9 @@ static int vega20_setup_asic_task(struct pp_hwmgr *hwmgr)
 static void vega20_init_dpm_state(struct vega20_dpm_state *dpm_state)
 {
dpm_state->soft_min_level = 0x0;
-   dpm_state->soft_max_level = 0x;
+   dpm_state->soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_state->hard_min_level = 0x0;
-   dpm_state->hard_max_level = 0x;
+   dpm_state->hard_max_level = VG20_CLOCK_MAX_DEFAULT;
 }
 
 static int vega20_get_number_of_dpm_level(struct pp_hwmgr *hwmgr,
@@ -3458,9 +3458,9 @@ static int vega20_apply_clocks_adjust_rules(struct 
pp_hwmgr *hwmgr)
/* gfxclk */
dpm_table = &(data->dpm_table.gfx_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.hard_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
 
if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
if (VEGA20_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) {
@@ -3482,9 +3482,9 @@ static int vega20_apply_clocks_adjust_rules(struct 
pp_hwmgr *hwmgr)
/* memclk */
dpm_table = &(data->dpm_table.mem_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.hard_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
 
if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
if (VEGA20_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) {
@@ -3526,18 +3526,18 @@ static int vega20_apply_clocks_adjust_rules(struct 
pp_hwmgr *hwmgr)
/* fclk */
dpm_table = &(data->dpm_table.fclk_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.hard_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
if (hwmgr->display_config->nb_pstate_switch_disable)
dpm_table->dpm_state.soft_min_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
 
/* vclk */
dpm_table = &(data->dpm_table.vclk_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.hard_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.hard_max_level = VG20_CLOCK_MAX_DEFAULT;
 
if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
@@ -3554,9 +3554,9 @@ static int vega20_apply_clocks_adjust_rules(struct 
pp_hwmgr *hwmgr)
/* dclk */
dpm_table = &(data->dpm_table.dclk_table);
dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.soft_max_level = 
dpm_table->dpm_levels[dpm_table->count - 1].value;
+   dpm_table->dpm_state.soft_max_level = VG20_CLOCK_MAX_DEFAULT;
dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
-   dpm_table->dpm_state.hard_max_level = 
dpm_tab

[PATCH 2/8] drm/amd/powerplay: need to reapply the dpm level settings

2019-02-21 Thread Evan Quan
As these settings got reset during above phm_apply_clock_adjust_rules.

Change-Id: Ie3296a87ef1d1b02e2195cdf69bdfb45c0b9f453
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
index ce177d7f04cb..6bf48934fdc4 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/pp_psm.c
@@ -277,8 +277,7 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, 
bool skip_display_set
if (!skip_display_settings)
phm_notify_smc_display_config_after_ps_adjustment(hwmgr);
 
-   if ((hwmgr->request_dpm_level != hwmgr->dpm_level) &&
-   !phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
+   if (!phm_force_dpm_levels(hwmgr, hwmgr->request_dpm_level))
hwmgr->dpm_level = hwmgr->request_dpm_level;
 
if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 8/8] drm/amd/powerplay: show the right override pcie parameters

2019-02-21 Thread Evan Quan
Instead of the hard-coded ones from VBIOS.

Change-Id: Ic317e292fbea89f01badfcfe240134aabcbe84ec
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 46 ---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.h|  4 ++
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 740268315adf..800ab2702ec7 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -783,6 +783,8 @@ static int vega20_init_smc_table(struct pp_hwmgr *hwmgr)
 static int vega20_override_pcie_parameters(struct pp_hwmgr *hwmgr)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
+   struct vega20_hwmgr *data =
+   (struct vega20_hwmgr *)(hwmgr->backend);
uint32_t pcie_gen = 0, pcie_width = 0, smu_pcie_arg;
int ret;
 
@@ -819,6 +821,10 @@ static int vega20_override_pcie_parameters(struct pp_hwmgr 
*hwmgr)
"[OverridePcieParameters] Attempt to override pcie params 
failed!",
return ret);
 
+   data->pcie_parameters_override = 1;
+   data->pcie_gen_level1 = pcie_gen;
+   data->pcie_width_level1 = pcie_width;
+
return 0;
 }
 
@@ -3103,7 +3109,7 @@ static int vega20_print_clock_levels(struct pp_hwmgr 
*hwmgr,
&(data->dpm_table.fclk_table);
int i, now, size = 0;
int ret = 0;
-   uint32_t gen_speed, lane_width;
+   uint32_t gen_speed, lane_width, current_gen_speed, current_lane_width;
 
switch (type) {
case PP_SCLK:
@@ -3187,28 +3193,36 @@ static int vega20_print_clock_levels(struct pp_hwmgr 
*hwmgr,
break;
 
case PP_PCIE:
-   gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
+   current_gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
 
PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
>> 
PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
-   lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
+   current_lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
  PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
>> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
-   for (i = 0; i < NUM_LINK_LEVELS; i++)
+   for (i = 0; i < NUM_LINK_LEVELS; i++) {
+   if (i == 1 && data->pcie_parameters_override) {
+   gen_speed = data->pcie_gen_level1;
+   lane_width = data->pcie_width_level1;
+   } else {
+   gen_speed = pptable->PcieGenSpeed[i];
+   lane_width = pptable->PcieLaneCount[i];
+   }
size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
-   (pptable->PcieGenSpeed[i] == 0) ? 
"2.5GT/s," :
-   (pptable->PcieGenSpeed[i] == 1) ? 
"5.0GT/s," :
-   (pptable->PcieGenSpeed[i] == 2) ? 
"8.0GT/s," :
-   (pptable->PcieGenSpeed[i] == 3) ? 
"16.0GT/s," : "",
-   (pptable->PcieLaneCount[i] == 1) ? "x1" 
:
-   (pptable->PcieLaneCount[i] == 2) ? "x2" 
:
-   (pptable->PcieLaneCount[i] == 3) ? "x4" 
:
-   (pptable->PcieLaneCount[i] == 4) ? "x8" 
:
-   (pptable->PcieLaneCount[i] == 5) ? 
"x12" :
-   (pptable->PcieLaneCount[i] == 6) ? 
"x16" : "",
+   (gen_speed == 0) ? "2.5GT/s," :
+   (gen_speed == 1) ? "5.0GT/s," :
+   (gen_speed == 2) ? "8.0GT/s," :
+   (gen_speed == 3) ? "16.0GT/s," : "",
+   (lane_width == 1) ? "x1" :
+   (lane_width == 2) ? "x2" :
+   (lane_width == 3) ? "x4" :
+   (lane_width == 4) ? "x8" :
+   (lane_width == 5) ? "x12" :
+   (lane_width == 6) ? "x16" : ""

[PATCH] drm/amd/powerplay: set max fan target temperature as 105C

2019-02-24 Thread Evan Quan
A workaround to override the fan target temperature in SMC table.

Change-Id: I67845c2fe5f51abde1ac483a979bde43ce2f26d3
Signed-off-by: Evan Quan 
---
 .../powerplay/hwmgr/vega20_processpptables.c| 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
index 97f8a1a970c3..7a7f15d0c53a 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
@@ -32,6 +32,8 @@
 #include "cgs_common.h"
 #include "vega20_pptable.h"
 
+#define VEGA20_FAN_TARGET_TEMPERATURE_OVERRIDE 105
+
 static void set_hw_cap(struct pp_hwmgr *hwmgr, bool enable,
enum phm_platform_caps cap)
 {
@@ -798,6 +800,17 @@ static int append_vbios_pptable(struct pp_hwmgr *hwmgr, 
PPTable_t *ppsmc_pptable
return 0;
 }
 
+static int override_powerplay_table_fantargettemperature(struct pp_hwmgr 
*hwmgr)
+{
+   struct phm_ppt_v3_information *pptable_information =
+   (struct phm_ppt_v3_information *)hwmgr->pptable;
+   PPTable_t *ppsmc_pptable = (PPTable_t 
*)(pptable_information->smc_pptable);
+
+   ppsmc_pptable->FanTargetTemperature = 
VEGA20_FAN_TARGET_TEMPERATURE_OVERRIDE;
+
+   return 0;
+}
+
 #define VEGA20_ENGINECLOCK_HARDMAX 198000
 static int init_powerplay_table_information(
struct pp_hwmgr *hwmgr,
@@ -887,6 +900,10 @@ static int init_powerplay_table_information(
 
 
result = append_vbios_pptable(hwmgr, 
(pptable_information->smc_pptable));
+   if (result)
+   return result;
+
+   result = override_powerplay_table_fantargettemperature(hwmgr);
 
return result;
 }
-- 
2.20.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 1/2] drm/amd/powerplay: correct power reading on fiji

2019-02-28 Thread Evan Quan
Set sampling period as 500ms to provide a smooth power
reading output. Also, correct the register for power
reading.

Change-Id: I13935f3e7fcd026d34aa6a68cf7f683dc6785ab7
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index 48187acac59e..83d3d935f3ac 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -3491,14 +3491,14 @@ static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, 
u32 *query)
 
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogStart);
cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
-   ixSMU_PM_STATUS_94, 0);
+   ixSMU_PM_STATUS_95, 0);
 
for (i = 0; i < 10; i++) {
-   mdelay(1);
+   mdelay(500);
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_PmStatusLogSample);
tmp = cgs_read_ind_register(hwmgr->device,
CGS_IND_REG__SMC,
-   ixSMU_PM_STATUS_94);
+   ixSMU_PM_STATUS_95);
if (tmp != 0)
break;
}
-- 
2.21.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 2/2] drm/amd/powerplay: override duty cycle on Vega20

2019-02-28 Thread Evan Quan
This is needed for the new SMC firmwares only.

Change-Id: I5934e5161ec53c1dd73cb1542ef6b738ad2e620c
Signed-off-by: Evan Quan 
---
 .../gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c   | 16 
 drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h |  3 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 9aa7bec1b5fe..d35f60ab3404 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -828,6 +828,17 @@ static int vega20_override_pcie_parameters(struct pp_hwmgr 
*hwmgr)
return 0;
 }
 
+static int vega20_override_duty_cycle(struct pp_hwmgr *hwmgr)
+{
+   struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
+   int ret = 0;
+
+   if (adev->pm.fw_version >= 0x00282700)
+   ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_OverrideDutyCycle);
+
+   return ret;
+}
+
 static int vega20_set_allowed_featuresmask(struct pp_hwmgr *hwmgr)
 {
struct vega20_hwmgr *data =
@@ -1644,6 +1655,11 @@ static int vega20_enable_dpm_tasks(struct pp_hwmgr 
*hwmgr)
"[EnableDPMTasks] Failed to enable all smu features!",
return result);
 
+   result = vega20_override_duty_cycle(hwmgr);
+   PP_ASSERT_WITH_CODE(!result,
+   "[EnableDPMTasks] Failed to override duty cycle!",
+   return result);
+
result = vega20_override_pcie_parameters(hwmgr);
PP_ASSERT_WITH_CODE(!result,
"[EnableDPMTasks] Failed to override pcie parameters!",
diff --git a/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h 
b/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
index 4f63a736ea0e..4a1e01f04cf5 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
@@ -119,7 +119,8 @@
 #define PPSMC_MSG_PrepareMp1ForShutdown  0x5A
 #define PPSMC_MSG_SetMGpuFanBoostLimitRpm0x5D
 #define PPSMC_MSG_GetAVFSVoltageByDpm0x5F
-#define PPSMC_Message_Count  0x60
+#define PPSMC_MSG_OverrideDutyCycle  0x64
+#define PPSMC_Message_Count  0x65
 
 typedef uint32_t PPSMC_Result;
 typedef uint32_t PPSMC_Msg;
-- 
2.21.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH] drm/amd/powerplay: apply Vega20 BACO workaround

2019-03-06 Thread Evan Quan
Applied vdci flush workaround for Vega20 BACO.

Change-Id: Ia132ae30f826643bfba980402a92fbd0ae7a4236
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/soc15.c|  2 ++
 .../gpu/drm/amd/powerplay/hwmgr/vega20_baco.c | 12 +++
 .../gpu/drm/amd/powerplay/hwmgr/vega20_baco.h |  1 +
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c| 11 +-
 .../gpu/drm/amd/powerplay/inc/vega20_ppsmc.h  |  3 ++-
 .../drm/amd/powerplay/smumgr/vega20_smumgr.c  | 20 +++
 .../drm/amd/powerplay/smumgr/vega20_smumgr.h  |  1 +
 8 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 876486595d89..fe0f5653805b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -981,6 +981,7 @@ struct amdgpu_device {
 
int asic_reset_res;
struct work_struct  xgmi_reset_work;
+   boolin_baco_reset;
 };
 
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index cc80f050cbf6..75a408a216b9 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -452,6 +452,8 @@ static int soc15_asic_baco_reset(struct amdgpu_device *adev)
 
dev_info(adev->dev, "GPU BACO reset\n");
 
+   adev->in_baco_reset = 1;
+
return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.c
index 5e8602a79b1c..df6ff9252401 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.c
@@ -27,6 +27,7 @@
 #include "vega20_inc.h"
 #include "vega20_ppsmc.h"
 #include "vega20_baco.h"
+#include "vega20_smumgr.h"
 
 
 
@@ -101,3 +102,14 @@ int vega20_baco_set_state(struct pp_hwmgr *hwmgr, enum 
BACO_STATE state)
 
return 0;
 }
+
+int vega20_baco_apply_vdci_flush_workaround(struct pp_hwmgr *hwmgr)
+{
+   int ret = 0;
+
+   ret = vega20_set_pptable_driver_address(hwmgr);
+   if (ret)
+   return ret;
+
+   return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_BacoWorkAroundFlushVDCI);
+}
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.h 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.h
index 51c7f8392925..f06471e712dc 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_baco.h
@@ -28,5 +28,6 @@
 extern int vega20_baco_get_capability(struct pp_hwmgr *hwmgr, bool *cap);
 extern int vega20_baco_get_state(struct pp_hwmgr *hwmgr, enum BACO_STATE 
*state);
 extern int vega20_baco_set_state(struct pp_hwmgr *hwmgr, enum BACO_STATE 
state);
+extern int vega20_baco_apply_vdci_flush_workaround(struct pp_hwmgr *hwmgr);
 
 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 9aa7bec1b5fe..664544e7fcdc 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -443,6 +443,7 @@ static int vega20_init_sclk_threshold(struct pp_hwmgr 
*hwmgr)
 
 static int vega20_setup_asic_task(struct pp_hwmgr *hwmgr)
 {
+   struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
int ret = 0;
 
ret = vega20_init_sclk_threshold(hwmgr);
@@ -450,7 +451,15 @@ static int vega20_setup_asic_task(struct pp_hwmgr *hwmgr)
"Failed to init sclk threshold!",
return ret);
 
-   return 0;
+   if (adev->in_baco_reset) {
+   adev->in_baco_reset = 0;
+
+   ret = vega20_baco_apply_vdci_flush_workaround(hwmgr);
+   if (ret)
+   pr_err("Failed to apply vega20 baco workaround!\n");
+   }
+
+   return ret;
 }
 
 /*
diff --git a/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h 
b/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
index 4f63a736ea0e..a0883038f3c3 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/vega20_ppsmc.h
@@ -119,7 +119,8 @@
 #define PPSMC_MSG_PrepareMp1ForShutdown  0x5A
 #define PPSMC_MSG_SetMGpuFanBoostLimitRpm0x5D
 #define PPSMC_MSG_GetAVFSVoltageByDpm0x5F
-#define PPSMC_Message_Count  0x60
+#define PPSMC_MSG_BacoWorkAroundFlushVDCI0x60
+#define PPSMC_Message_Count  0x61
 
 typedef uint32_t PPSMC_Result;
 typedef uint32_t PPSMC_Msg;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
index ba00744c3413..f301a73f6df1 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
+++ b

[PATCH] drm/amdgpu: fix ras parameter descriptions

2019-03-06 Thread Evan Quan
The descriptions of modinfo wrongly show two parameters
for each feature(see below). This patch can fix this
incorrect outputs.

parm:   amdgpu_ras_enable:Enable RAS features on the GPU (0 = disable, 
1 = enable, -1 = auto (default))
parm:   ras_enable:int
parm:   amdgpu_ras_mask:Mask of RAS features to enable (default 
0x), only valid when ras_enable == 1
parm:   ras_mask:uint

Change-Id: I04f7e505cecca991f196802befd2006dc49b3dcf
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 38dbf6115c15..e0a7712d5d7b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -512,18 +512,18 @@ MODULE_PARM_DESC(emu_mode, "Emulation mode, (1 = enable, 
0 = disable)");
 module_param_named(emu_mode, amdgpu_emu_mode, int, 0444);
 
 /*
- * DOC: amdgpu_ras_enable (int)
+ * DOC: ras_enable (int)
  * Enable RAS features on the GPU (0 = disable, 1 = enable, -1 = auto 
(default))
  */
-MODULE_PARM_DESC(amdgpu_ras_enable, "Enable RAS features on the GPU (0 = 
disable, 1 = enable, -1 = auto (default))");
+MODULE_PARM_DESC(ras_enable, "Enable RAS features on the GPU (0 = disable, 1 = 
enable, -1 = auto (default))");
 module_param_named(ras_enable, amdgpu_ras_enable, int, 0444);
 
 /**
- * DOC: amdgpu_ras_mask (uint)
+ * DOC: ras_mask (uint)
  * Mask of RAS features to enable (default 0x), only valid when 
ras_enable == 1
  * See the flags in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
  */
-MODULE_PARM_DESC(amdgpu_ras_mask, "Mask of RAS features to enable (default 
0x), only valid when ras_enable == 1");
+MODULE_PARM_DESC(ras_mask, "Mask of RAS features to enable (default 
0x), only valid when ras_enable == 1");
 module_param_named(ras_mask, amdgpu_ras_mask, uint, 0444);
 
 
-- 
2.21.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 1/2] drm/amdgpu: unify the way to judge RAS feature readiness

2019-03-10 Thread Evan Quan
Unify the way to judge whether a specific RAS feature is
supported.

Change-Id: I14bb19db49f06e134de903376b14eb27e0e038c7
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 10 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h |  2 +-
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index bf462c59cb76..7f9cbd64cb20 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -466,12 +466,6 @@ static struct ras_manager *amdgpu_ras_find_obj(struct 
amdgpu_device *adev,
 /* obj end */
 
 /* feature ctl begin */
-static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
-   struct ras_common_if *head)
-{
-   return amdgpu_ras_enable && (amdgpu_ras_mask & BIT(head->block));
-}
-
 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
struct ras_common_if *head)
 {
@@ -490,7 +484,7 @@ static int __amdgpu_ras_feature_enable(struct amdgpu_device 
*adev,
struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
 
-   if (!amdgpu_ras_is_feature_allowed(adev, head))
+   if (!amdgpu_ras_is_supported(adev, head->block))
return 0;
if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
return 0;
@@ -539,7 +533,7 @@ int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
}
 
/* Do not enable if it is not allowed. */
-   WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
+   WARN_ON(enable && !amdgpu_ras_is_supported(adev, head->block));
/* Are we alerady in that state we are going to set? */
if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
index 02cb9a13ddc5..0ef2b91b8fcd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
@@ -163,7 +163,7 @@ struct ras_debug_if {
 
 /* check if ras is supported on block, say, sdma, gfx */
 static inline int amdgpu_ras_is_supported(struct amdgpu_device *adev,
-   unsigned int block)
+   enum amdgpu_ras_block block)
 {
struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
 
-- 
2.21.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

[PATCH 2/2] drm/amdgpu: drop unnecessary dereference

2019-03-10 Thread Evan Quan
It's unnecessary and confusing.

Change-Id: I77fe54a108b7ee2031851b3e11d63c4fb74c0d43
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  | 26 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  | 26 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 26 +-
 3 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index 3fb72bf420e0..31996d448817 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -3532,7 +3532,7 @@ static int gfx_v9_0_process_ras_data_cb(struct 
amdgpu_device *adev,
 static int gfx_v9_0_ecc_late_init(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-   struct ras_common_if **ras_if = &adev->gfx.ras_if;
+   struct ras_common_if *ras_if = adev->gfx.ras_if;
struct ras_ih_if ih_info = {
.cb = gfx_v9_0_process_ras_data_cb,
};
@@ -3553,21 +3553,21 @@ static int gfx_v9_0_ecc_late_init(void *handle)
return 0;
}
 
-   if (*ras_if)
+   if (ras_if)
goto resume;
 
-   *ras_if = kmalloc(sizeof(**ras_if), GFP_KERNEL);
-   if (!*ras_if)
+   ras_if = kmalloc(sizeof(*ras_if), GFP_KERNEL);
+   if (!ras_if)
return -ENOMEM;
 
-   **ras_if = ras_block;
+   *ras_if = ras_block;
 
-   r = amdgpu_ras_feature_enable(adev, *ras_if, 1);
+   r = amdgpu_ras_feature_enable(adev, ras_if, 1);
if (r)
goto feature;
 
-   ih_info.head = **ras_if;
-   fs_info.head = **ras_if;
+   ih_info.head = *ras_if;
+   fs_info.head = *ras_if;
 
r = amdgpu_ras_interrupt_add_handler(adev, &ih_info);
if (r)
@@ -3587,16 +3587,16 @@ static int gfx_v9_0_ecc_late_init(void *handle)
 
return 0;
 irq:
-   amdgpu_ras_sysfs_remove(adev, *ras_if);
+   amdgpu_ras_sysfs_remove(adev, ras_if);
 sysfs:
-   amdgpu_ras_debugfs_remove(adev, *ras_if);
+   amdgpu_ras_debugfs_remove(adev, ras_if);
 debugfs:
amdgpu_ras_interrupt_remove_handler(adev, &ih_info);
 interrupt:
-   amdgpu_ras_feature_enable(adev, *ras_if, 0);
+   amdgpu_ras_feature_enable(adev, ras_if, 0);
 feature:
-   kfree(*ras_if);
-   *ras_if = NULL;
+   kfree(ras_if);
+   ras_if = NULL;
return -EINVAL;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 5d1ac53f7ddb..229e614d1b76 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -714,7 +714,7 @@ static int gmc_v9_0_allocate_vm_inv_eng(struct 
amdgpu_device *adev)
 static int gmc_v9_0_ecc_late_init(void *handle)
 {
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-   struct ras_common_if **ras_if = &adev->gmc.ras_if;
+   struct ras_common_if *ras_if = adev->gmc.ras_if;
struct ras_ih_if ih_info = {
.cb = gmc_v9_0_process_ras_data_cb,
};
@@ -735,21 +735,21 @@ static int gmc_v9_0_ecc_late_init(void *handle)
return 0;
}
/* handle resume path. */
-   if (*ras_if)
+   if (ras_if)
goto resume;
 
-   *ras_if = kmalloc(sizeof(**ras_if), GFP_KERNEL);
-   if (!*ras_if)
+   ras_if = kmalloc(sizeof(*ras_if), GFP_KERNEL);
+   if (!ras_if)
return -ENOMEM;
 
-   **ras_if = ras_block;
+   *ras_if = ras_block;
 
-   r = amdgpu_ras_feature_enable(adev, *ras_if, 1);
+   r = amdgpu_ras_feature_enable(adev, ras_if, 1);
if (r)
goto feature;
 
-   ih_info.head = **ras_if;
-   fs_info.head = **ras_if;
+   ih_info.head = *ras_if;
+   fs_info.head = *ras_if;
 
r = amdgpu_ras_interrupt_add_handler(adev, &ih_info);
if (r)
@@ -769,16 +769,16 @@ static int gmc_v9_0_ecc_late_init(void *handle)
 
return 0;
 irq:
-   amdgpu_ras_sysfs_remove(adev, *ras_if);
+   amdgpu_ras_sysfs_remove(adev, ras_if);
 sysfs:
-   amdgpu_ras_debugfs_remove(adev, *ras_if);
+   amdgpu_ras_debugfs_remove(adev, ras_if);
 debugfs:
amdgpu_ras_interrupt_remove_handler(adev, &ih_info);
 interrupt:
-   amdgpu_ras_feature_enable(adev, *ras_if, 0);
+   amdgpu_ras_feature_enable(adev, ras_if, 0);
 feature:
-   kfree(*ras_if);
-   *ras_if = NULL;
+   kfree(ras_if);
+   ras_if = NULL;
return -EINVAL;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c 
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
index 3ac5abe937f4..521218053477 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
@@ -1501,7 +1501,7 @@ static int sdma_v4_0_process_ras_data_cb(struct 
amdgpu_device *adev,
 static int sdma_v4_0_late_init(void *handle)
 {
struct amdgpu_devi

[PATCH] drm/amd/powerplay: honor the BACO setting from VBIOS

2020-03-04 Thread Evan Quan
Should not enable BACO always on Vega20. That will
break the VBIOS setting.

Change-Id: I2609fc3f86dc785d385d9320574446810b5b693d
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 08b6ba39a6d7..eed4da1131d1 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -182,9 +182,6 @@ static int vega20_set_features_platform_caps(struct 
pp_hwmgr *hwmgr)
phm_cap_set(hwmgr->platform_descriptor.platformCaps,
PHM_PlatformCaps_TablelessHardwareInterface);
 
-   phm_cap_set(hwmgr->platform_descriptor.platformCaps,
-   PHM_PlatformCaps_BACO);
-
phm_cap_set(hwmgr->platform_descriptor.platformCaps,
PHM_PlatformCaps_EnableSMU7ThermalManagement);
 
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: revise the way to retrieve the board parameters

2020-03-06 Thread Evan Quan
It can support different NV1x ASIC better. And this can guard
no member got missing.

Change-Id: Id5e6608f6be1b31ef1c0a5c1d399da295524ff43
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/include/atomfirmware.h | 102 +
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c |  99 ++--
 2 files changed, 130 insertions(+), 71 deletions(-)

diff --git a/drivers/gpu/drm/amd/include/atomfirmware.h 
b/drivers/gpu/drm/amd/include/atomfirmware.h
index 70146518174c..a6f6e6bf5992 100644
--- a/drivers/gpu/drm/amd/include/atomfirmware.h
+++ b/drivers/gpu/drm/amd/include/atomfirmware.h
@@ -1876,6 +1876,108 @@ struct atom_smc_dpm_info_v4_6
   uint32_t   boardreserved[10];
 };
 
+struct atom_smc_dpm_info_v4_7
+{
+  struct   atom_common_table_header  table_header;
+// SECTION: BOARD PARAMETERS
+// I2C Control
+  struct smudpm_i2c_controller_config_v2  I2cControllers[8];
+
+  // SVI2 Board Parameters
+  uint16_t MaxVoltageStepGfx; // In mV(Q2) Max voltage step that SMU will 
request. Multiple steps are taken if voltage change exceeds this value.
+  uint16_t MaxVoltageStepSoc; // In mV(Q2) Max voltage step that SMU will 
request. Multiple steps are taken if voltage change exceeds this value.
+
+  uint8_t  VddGfxVrMapping;   // Use VR_MAPPING* bitfields
+  uint8_t  VddSocVrMapping;   // Use VR_MAPPING* bitfields
+  uint8_t  VddMem0VrMapping;  // Use VR_MAPPING* bitfields
+  uint8_t  VddMem1VrMapping;  // Use VR_MAPPING* bitfields
+
+  uint8_t  GfxUlvPhaseSheddingMask; // set this to 1 to set PSI0/1 to 1 in 
ULV mode
+  uint8_t  SocUlvPhaseSheddingMask; // set this to 1 to set PSI0/1 to 1 in 
ULV mode
+  uint8_t  ExternalSensorPresent; // External RDI connected to TMON (aka 
TEMP IN)
+  uint8_t  Padding8_V;
+
+  // Telemetry Settings
+  uint16_t GfxMaxCurrent;   // in Amps
+  uint8_t  GfxOffset;   // in Amps
+  uint8_t  Padding_TelemetryGfx;
+  uint16_t SocMaxCurrent;   // in Amps
+  uint8_t  SocOffset;   // in Amps
+  uint8_t  Padding_TelemetrySoc;
+
+  uint16_t Mem0MaxCurrent;   // in Amps
+  uint8_t  Mem0Offset;   // in Amps
+  uint8_t  Padding_TelemetryMem0;
+
+  uint16_t Mem1MaxCurrent;   // in Amps
+  uint8_t  Mem1Offset;   // in Amps
+  uint8_t  Padding_TelemetryMem1;
+
+  // GPIO Settings
+  uint8_t  AcDcGpio;// GPIO pin configured for AC/DC switching
+  uint8_t  AcDcPolarity;// GPIO polarity for AC/DC switching
+  uint8_t  VR0HotGpio;  // GPIO pin configured for VR0 HOT event
+  uint8_t  VR0HotPolarity;  // GPIO polarity for VR0 HOT event
+
+  uint8_t  VR1HotGpio;  // GPIO pin configured for VR1 HOT event
+  uint8_t  VR1HotPolarity;  // GPIO polarity for VR1 HOT event
+  uint8_t  GthrGpio;// GPIO pin configured for GTHR Event
+  uint8_t  GthrPolarity;// replace GPIO polarity for GTHR
+
+  // LED Display Settings
+  uint8_t  LedPin0; // GPIO number for LedPin[0]
+  uint8_t  LedPin1; // GPIO number for LedPin[1]
+  uint8_t  LedPin2; // GPIO number for LedPin[2]
+  uint8_t  padding8_4;
+
+  // GFXCLK PLL Spread Spectrum
+  uint8_t  PllGfxclkSpreadEnabled;   // on or off
+  uint8_t  PllGfxclkSpreadPercent;   // Q4.4
+  uint16_t PllGfxclkSpreadFreq;  // kHz
+
+  // GFXCLK DFLL Spread Spectrum
+  uint8_t  DfllGfxclkSpreadEnabled;   // on or off
+  uint8_t  DfllGfxclkSpreadPercent;   // Q4.4
+  uint16_t DfllGfxclkSpreadFreq;  // kHz
+
+  // UCLK Spread Spectrum
+  uint8_t  UclkSpreadEnabled;   // on or off
+  uint8_t  UclkSpreadPercent;   // Q4.4
+  uint16_t UclkSpreadFreq;  // kHz
+
+  // SOCCLK Spread Spectrum
+  uint8_t  SoclkSpreadEnabled;   // on or off
+  uint8_t  SocclkSpreadPercent;   // Q4.4
+  uint16_t SocclkSpreadFreq;  // kHz
+
+  // Total board power
+  uint16_t TotalBoardPower; //Only needed for TCP Estimated case, 
where TCP = TGP+Total Board Power
+  uint16_t BoardPadding;
+
+  // Mvdd Svi2 Div Ratio Setting
+  uint32_t MvddRatio; // This is used for MVDD Vid workaround. It has 16 
fractional bits (Q16.16)
+
+  // GPIO pins for I2C communications with 2nd controller for Input Telemetry 
Sequence
+  uint8_t  GpioI2cScl;  // Serial Clock
+  uint8_t  GpioI2cSda;  // Serial Data
+  uint16_t GpioPadding;
+
+  // Additional LED Display Settings
+  uint8_t  LedPin3; // GPIO number for LedPin[3] - PCIE GEN Speed
+  uint8_t  LedPin4; // GPIO number for LedPin[4] - PMFW Error 
Status
+  uint16_t LedEnableMask;
+
+  // Power Limit Scalars
+  uint8_t  PowerLimitScalar[4];//[PPT_THROTTLER_COUNT]
+
+  uint8_t  MvddUlvPhaseSheddingMask;
+  uint8_t  VddciUlvPhaseSheddingMask;
+  uint8_t  Padding8_Psi1;
+  uint8_t  Padding8_Psi2;
+
+  uint32_t BoardReserved[5

[PATCH] drm/amd/powerplay: bump the NAVI10 smu-driver if version

2020-03-06 Thread Evan Quan
To fit the latest SMC firmware 53.27 and eliminate the
warning on driver loading.

Change-Id: I3f524d03e53ec6778b7118ef72652a538eec4ace
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h 
b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
index 3dc25a14ccc3..c030feb160f7 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
@@ -28,7 +28,7 @@
 #define SMU11_DRIVER_IF_VERSION_INV 0x
 #define SMU11_DRIVER_IF_VERSION_VG20 0x13
 #define SMU11_DRIVER_IF_VERSION_ARCT 0x12
-#define SMU11_DRIVER_IF_VERSION_NV10 0x35
+#define SMU11_DRIVER_IF_VERSION_NV10 0x36
 #define SMU11_DRIVER_IF_VERSION_NV14 0x36
 
 /* MP Apertures */
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: check for the existence of RAS dir before creating

2020-03-09 Thread Evan Quan
To address the error message below:
debugfs: Directory 'ras' with parent '/' already present!

Change-Id: I2539e89fdfe4e22055c3be5a48a8c0adad315f91
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index e1e8fd4b2b89..2195f6c63b50 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -1075,7 +1075,9 @@ static void amdgpu_ras_debugfs_create_ctrl_node(struct 
amdgpu_device *adev)
struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
struct drm_minor *minor = adev->ddev->primary;
 
-   con->dir = debugfs_create_dir("ras", minor->debugfs_root);
+   con->dir = debugfs_lookup("ras", minor->debugfs_root);
+   if (!con->dir)
+   con->dir = debugfs_create_dir("ras", minor->debugfs_root);
debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, con->dir,
adev, &amdgpu_ras_debugfs_ctrl_ops);
debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, con->dir,
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: add fbdev suspend/resume on gpu reset

2020-03-11 Thread Evan Quan
This can fix the baco reset failure seen on Navi10.
And this should be a low risk fix as the same sequence
is already used for system suspend/resume.

Change-Id: Idb4d02c5fcbbd5b7817195ee04c7af34c346a053
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 572eb6ea8eab..a35c89973614 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3935,6 +3935,8 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info 
*hive,
if (r)
goto out;
 
+   amdgpu_fbdev_set_suspend(tmp_adev, 0);
+
/* must succeed. */
amdgpu_ras_resume(tmp_adev);
 
@@ -4108,6 +4110,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 */
amdgpu_unregister_gpu_instance(tmp_adev);
 
+   amdgpu_fbdev_set_suspend(adev, 1);
+
/* disable ras on ALL IPs */
if (!(in_ras_intr && !use_baco) &&
  amdgpu_device_ip_need_full_reset(tmp_adev))
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: reenable runtime pm on navi12

2020-03-11 Thread Evan Quan
The runtime pm is verified as working now
on navi12.

Change-Id: I20393633678297308c9651237bbfdc854a3cff94
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 80495652a7c1..e376dc072d42 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -174,8 +174,7 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned 
long flags)
 (adev->asic_type >= CHIP_TOPAZ) &&
 (adev->asic_type != CHIP_VEGA10) &&
 (adev->asic_type != CHIP_VEGA20) &&
-(adev->asic_type != CHIP_ARCTURUS) &&
-(adev->asic_type != CHIP_NAVI12)) /* enable runpm on VI+ */
+(adev->asic_type != CHIP_ARCTURUS)) /* enable runpm on VI+ */
adev->runpm = true;
else if (amdgpu_device_supports_baco(dev) &&
 (amdgpu_runtime_pm > 0))  /* enable runpm if runpm=1 on CI */
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: correct the bootup power source for Navi1X

2020-03-19 Thread Evan Quan
PMFW may boots those ASICs with DC mode. Need to set it back
to AC mode.

Change-Id: I56ffd0e747f778aa013da43a8693ddfb5da31e3c
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 15 +++
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  1 +
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 16 
 drivers/gpu/drm/amd/powerplay/smu_internal.h   |  3 +++
 4 files changed, 35 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 3f05921056ec..64041d90ddee 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -1144,6 +1144,21 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
}
}
}
+
+   if (adev->asic_type >= CHIP_NAVI10 &&
+   adev->asic_type <= CHIP_NAVI12) {
+   /*
+* For Navi1X, manually switch it to AC mode as PMFW
+* may boot it with DC mode.
+* TODO: should check whether we are indeed under AC
+* mode before doing this.
+*/
+   ret = smu_set_power_source(smu, SMU_POWER_SOURCE_AC);
+   if (ret) {
+   pr_err("Failed to switch to AC mode!\n");
+   return ret;
+   }
+   }
}
if (adev->asic_type != CHIP_ARCTURUS) {
ret = smu_notify_display_change(smu);
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h 
b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index 657a6f17e91f..323e7e61493b 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -570,6 +570,7 @@ struct pptable_funcs {
int (*override_pcie_parameters)(struct smu_context *smu);
uint32_t (*get_pptable_power_limit)(struct smu_context *smu);
int (*disable_umc_cdr_12gbps_workaround)(struct smu_context *smu);
+   int (*set_power_source)(struct smu_context *smu, enum 
smu_power_src_type power_src);
 };
 
 int smu_load_microcode(struct smu_context *smu);
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c 
b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
index d66dfa7410b6..45d46c38f7ca 100644
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
@@ -2275,6 +2275,21 @@ static int 
navi10_disable_umc_cdr_12gbps_workaround(struct smu_context *smu)
return navi10_dummy_pstate_control(smu, true);
 }
 
+static int navi10_set_power_source(struct smu_context *smu,
+  enum smu_power_src_type power_src)
+{
+   int pwr_source;
+
+   pwr_source = navi10_get_pwr_src_index(smu, (uint32_t)power_src);
+   if (pwr_source < 0)
+   return -EINVAL;
+
+   return smu_send_smc_msg_with_param(smu,
+   SMU_MSG_NotifyPowerSource,
+   pwr_source,
+   NULL);
+}
+
 static const struct pptable_funcs navi10_ppt_funcs = {
.tables_init = navi10_tables_init,
.alloc_dpm_context = navi10_allocate_dpm_context,
@@ -2369,6 +2384,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
.get_pptable_power_limit = navi10_get_pptable_power_limit,
.run_btc = navi10_run_btc,
.disable_umc_cdr_12gbps_workaround = 
navi10_disable_umc_cdr_12gbps_workaround,
+   .set_power_source = navi10_set_power_source,
 };
 
 void navi10_set_ppt_funcs(struct smu_context *smu)
diff --git a/drivers/gpu/drm/amd/powerplay/smu_internal.h 
b/drivers/gpu/drm/amd/powerplay/smu_internal.h
index 6900877de845..40c35bcc5a0a 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_internal.h
+++ b/drivers/gpu/drm/amd/powerplay/smu_internal.h
@@ -211,4 +211,7 @@ static inline int smu_send_smc_msg(struct smu_context *smu, 
enum smu_message_typ
 #define smu_disable_umc_cdr_12gbps_workaround(smu) \
((smu)->ppt_funcs->disable_umc_cdr_12gbps_workaround ? 
(smu)->ppt_funcs->disable_umc_cdr_12gbps_workaround((smu)) : 0)
 
+#define smu_set_power_source(smu, power_src) \
+   ((smu)->ppt_funcs->set_power_source ? 
(smu)->ppt_funcs->set_power_source((smu), (power_src)) : 0)
+
 #endif
-- 
2.25.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: unload mp1 for Arcturus RAS baco reset

2020-03-25 Thread Evan Quan
This sequence is recommended by PMFW team for the baco reset
with PMFW reloaded. And it seems able to address the random
failure seen on Arcturus.

Change-Id: Ic5a83ad46466a12533e9f704ad06348852156e78
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c 
b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index 4fd77c7cfc80..914c944d901a 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -1719,6 +1719,12 @@ int smu_v11_0_baco_set_state(struct smu_context *smu, 
enum smu_baco_state state)
if (ret)
goto out;
 
+   if (ras && ras->supported) {
+   ret = smu_send_smc_msg(smu, 
SMU_MSG_PrepareMp1ForUnload, NULL);
+   if (ret)
+   goto out;
+   }
+
bif_doorbell_intr_cntl = REG_SET_FIELD(bif_doorbell_intr_cntl,
BIF_DOORBELL_INT_CNTL,
DOORBELL_INTERRUPT_DISABLE, 0);
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/9] drm/amd/powerplay: avoid calling CI specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: If5f7615483d9967f9512fba49cc8454a1300ba6c
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
index 868e2d5f6e62..66289884c8df 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
@@ -2881,7 +2881,7 @@ static int ci_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
if (hwmgr->dpm_level & profile_mode_mask || 
!PP_CAP(PHM_PlatformCaps_UVDDPM))
break;
}
-   ci_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_MSG_UVDDPM_SetEnabledMask,
+   smum_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_MSG_UVDDPM_SetEnabledMask,

data->dpm_level_enable_mask.uvd_dpm_enable_mask);
 
return 0;
@@ -2912,7 +2912,7 @@ static int ci_update_vce_smc_table(struct pp_hwmgr *hwmgr)
if (hwmgr->dpm_level & profile_mode_mask || 
!PP_CAP(PHM_PlatformCaps_VCEDPM))
break;
}
-   ci_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_MSG_VCEDPM_SetEnabledMask,
+   smum_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_MSG_VCEDPM_SetEnabledMask,

data->dpm_level_enable_mask.vce_dpm_enable_mask);
 
return 0;
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 5/9] drm/amd/powerplay: avoid calling SMU9 specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: Id2c0504c60358e6ff2beee83058e36812962e934
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/smumgr/vega10_smumgr.c  | 24 +++---
 .../drm/amd/powerplay/smumgr/vega12_smumgr.c  | 32 +--
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vega10_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/vega10_smumgr.c
index 715564009089..1769dded4f74 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vega10_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vega10_smumgr.c
@@ -47,13 +47,13 @@ static int vega10_copy_table_from_smc(struct pp_hwmgr 
*hwmgr,
"Invalid SMU Table version!", return -EINVAL);
PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
"Invalid SMU Table Length!", return -EINVAL);
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableSmu2Dram,
priv->smu_tables.entry[table_id].table_id);
 
@@ -90,13 +90,13 @@ static int vega10_copy_table_to_smc(struct pp_hwmgr *hwmgr,
 
amdgpu_asic_flush_hdp(adev, NULL);
 
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableDram2Smu,
priv->smu_tables.entry[table_id].table_id);
 
@@ -127,8 +127,8 @@ int vega10_get_enabled_smc_features(struct pp_hwmgr *hwmgr,
if (features_enabled == NULL)
return -EINVAL;
 
-   smu9_send_msg_to_smc(hwmgr, PPSMC_MSG_GetEnabledSmuFeatures);
-   *features_enabled = smu9_get_argument(hwmgr);
+   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetEnabledSmuFeatures);
+   *features_enabled = smum_get_argument(hwmgr);
 
return 0;
 }
@@ -150,10 +150,10 @@ static int vega10_set_tools_address(struct pp_hwmgr 
*hwmgr)
struct vega10_smumgr *priv = hwmgr->smu_backend;
 
if (priv->smu_tables.entry[TOOLSTABLE].mc_addr) {
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetToolsDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[TOOLSTABLE].mc_addr));
-   smu9_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetToolsDramAddrLow,

lower_32_bits(priv->smu_tables.entry[TOOLSTABLE].mc_addr));
}
@@ -167,11 +167,11 @@ static int vega10_verify_smc_interface(struct pp_hwmgr 
*hwmgr)
uint32_t dev_id;
uint32_t rev_id;
 
-   PP_ASSERT_WITH_CODE(!smu9_send_msg_to_smc(hwmgr,
+   PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
PPSMC_MSG_GetDriverIfVersion),
"Attempt to get SMC IF Version Number Failed!",
return -EINVAL);
-   smc_driver_if_version = smu9_get_argument(hwmgr);
+   smc_driver_if_version = smum_get_argument(hwmgr);
 
dev_id = adev->pdev->device;
rev_id = adev->pdev->revision;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vega12_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/vega12_smumgr.c
index 275dbf65f1a0..34528a1285ac 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vega12_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vega12_smumgr.c
@@ -50,16 +50,16 @@ static int vega12_copy_table_from_smc(struct pp_hwmgr 
*hwmgr,
"Invalid SMU Table version!", return -EINVAL);
PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
"Invalid SMU Table Length!", return -EINVAL);
-   PP_ASSERT_WITH_CODE(smu9_send_msg_

[PATCH 4/9] drm/amd/powerplay: avoid calling SMU8 specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: Ia4a07898410a661d8603474ec253859278f00d3c
Signed-off-by: Evan Quan 
---
 .../gpu/drm/amd/powerplay/hwmgr/smu8_hwmgr.c  |  2 +-
 .../drm/amd/powerplay/smumgr/smu8_smumgr.c| 30 +--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu8_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/smu8_hwmgr.c
index 019d6a206492..2e8061eccc43 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu8_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu8_hwmgr.c
@@ -1755,7 +1755,7 @@ static int smu8_read_sensor(struct pp_hwmgr *hwmgr, int 
idx,
case AMDGPU_PP_SENSOR_GPU_LOAD:
result = smum_send_msg_to_smc(hwmgr, 
PPSMC_MSG_GetAverageGraphicsActivity);
if (0 == result) {
-   activity_percent = cgs_read_register(hwmgr->device, 
mmSMU_MP1_SRBM2P_ARG_0);
+   activity_percent = smum_get_argument(hwmgr);
activity_percent = activity_percent > 100 ? 100 : 
activity_percent;
} else {
activity_percent = 50;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
index 7dca04a89217..294e48e900dc 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu8_smumgr.c
@@ -610,18 +610,18 @@ static int smu8_download_pptable_settings(struct pp_hwmgr 
*hwmgr, void **table)
 
*table = (struct SMU8_Fusion_ClkTable 
*)smu8_smu->scratch_buffer[i].kaddr;
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetClkTableAddrHi,

upper_32_bits(smu8_smu->scratch_buffer[i].mc_addr));
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetClkTableAddrLo,

lower_32_bits(smu8_smu->scratch_buffer[i].mc_addr));
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
+   smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
smu8_smu->toc_entry_clock_table);
 
-   smu8_send_msg_to_smc(hwmgr, PPSMC_MSG_ClkTableXferToDram);
+   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ClkTableXferToDram);
 
return 0;
 }
@@ -637,18 +637,18 @@ static int smu8_upload_pptable_settings(struct pp_hwmgr 
*hwmgr)
break;
}
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetClkTableAddrHi,

upper_32_bits(smu8_smu->scratch_buffer[i].mc_addr));
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetClkTableAddrLo,

lower_32_bits(smu8_smu->scratch_buffer[i].mc_addr));
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
+   smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
smu8_smu->toc_entry_clock_table);
 
-   smu8_send_msg_to_smc(hwmgr, PPSMC_MSG_ClkTableXferToSmu);
+   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ClkTableXferToSmu);
 
return 0;
 }
@@ -671,23 +671,23 @@ static int smu8_request_smu_load_fw(struct pp_hwmgr 
*hwmgr)
 
smu8_write_smc_sram_dword(hwmgr, smc_address, 0, smc_address+4);
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_DriverDramAddrHi,

upper_32_bits(smu8_smu->toc_buffer.mc_addr));
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_DriverDramAddrLo,

lower_32_bits(smu8_smu->toc_buffer.mc_addr));
 
-   smu8_send_msg_to_smc(hwmgr, PPSMC_MSG_InitJobs);
+   smum_send_msg_to_smc(hwmgr, PPSMC_MSG_InitJobs);
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_ExecuteJob,
smu8_smu->toc_entry_aram);
-   smu8_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
+   smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_ExecuteJob,
smu8_smu->toc_entry_power_profiling_index);
 
-   smu8_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_ExecuteJob,
 

[PATCH 6/9] drm/amd/powerplay: avoid calling SMU10 specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: I05ec712b05dcb2831c948a1df26695619ba8014a
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/smumgr/smu10_smumgr.c| 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu10_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/smu10_smumgr.c
index 2319400a3fcb..d652673b244f 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu10_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu10_smumgr.c
@@ -126,13 +126,13 @@ static int smu10_copy_table_from_smc(struct pp_hwmgr 
*hwmgr,
"Invalid SMU Table version!", return -EINVAL;);
PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
"Invalid SMU Table Length!", return -EINVAL;);
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableSmu2Dram,
priv->smu_tables.entry[table_id].table_id);
 
@@ -164,13 +164,13 @@ static int smu10_copy_table_to_smc(struct pp_hwmgr *hwmgr,
 
amdgpu_asic_flush_hdp(adev, NULL);
 
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr));
-   smu10_send_msg_to_smc_with_parameter(hwmgr,
+   smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableDram2Smu,
priv->smu_tables.entry[table_id].table_id);
 
@@ -181,9 +181,9 @@ static int smu10_verify_smc_interface(struct pp_hwmgr 
*hwmgr)
 {
uint32_t smc_driver_if_version;
 
-   smu10_send_msg_to_smc(hwmgr,
+   smum_send_msg_to_smc(hwmgr,
PPSMC_MSG_GetDriverIfVersion);
-   smc_driver_if_version = smu10_read_arg_from_smc(hwmgr);
+   smc_driver_if_version = smum_get_argument(hwmgr);
 
if ((smc_driver_if_version != SMU10_DRIVER_IF_VERSION) &&
(smc_driver_if_version != SMU10_DRIVER_IF_VERSION + 1)) {
@@ -218,7 +218,7 @@ static int smu10_start_smu(struct pp_hwmgr *hwmgr)
struct amdgpu_device *adev = hwmgr->adev;
 
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetSmuVersion);
-   hwmgr->smu_version = smu10_read_arg_from_smc(hwmgr);
+   hwmgr->smu_version = smum_get_argument(hwmgr);
adev->pm.fw_version = hwmgr->smu_version >> 8;
 
if (adev->rev_id < 0x8 && adev->pdev->device != 0x15d8 &&
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 3/9] drm/amd/powerpaly: drop unused APIs

2020-03-26 Thread Evan Quan
Drop unused smu7 message APIs.

Change-Id: I8fc13b626fad04241f2b9353419282eaa14923af
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c | 14 --
 drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h |  3 ---
 2 files changed, 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
index 07460ac74ac5..627fe77a5f51 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.c
@@ -191,13 +191,6 @@ int smu7_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t 
msg)
return 0;
 }
 
-int smu7_send_msg_to_smc_without_waiting(struct pp_hwmgr *hwmgr, uint16_t msg)
-{
-   cgs_write_register(hwmgr->device, mmSMC_MESSAGE_0, msg);
-
-   return 0;
-}
-
 int smu7_send_msg_to_smc_with_parameter(struct pp_hwmgr *hwmgr, uint16_t msg, 
uint32_t parameter)
 {
PHM_WAIT_FIELD_UNEQUAL(hwmgr, SMC_RESP_0, SMC_RESP, 0);
@@ -207,13 +200,6 @@ int smu7_send_msg_to_smc_with_parameter(struct pp_hwmgr 
*hwmgr, uint16_t msg, ui
return smu7_send_msg_to_smc(hwmgr, msg);
 }
 
-int smu7_send_msg_to_smc_with_parameter_without_waiting(struct pp_hwmgr 
*hwmgr, uint16_t msg, uint32_t parameter)
-{
-   cgs_write_register(hwmgr->device, mmSMC_MSG_ARG_0, parameter);
-
-   return smu7_send_msg_to_smc_without_waiting(hwmgr, msg);
-}
-
 uint32_t smu7_get_argument(struct pp_hwmgr *hwmgr)
 {
return cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h 
b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h
index fe27f46d2f5d..e7303dc8c260 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smu7_smumgr.h
@@ -60,11 +60,8 @@ int smu7_copy_bytes_to_smc(struct pp_hwmgr *hwmgr, uint32_t 
smc_start_address,
 int smu7_program_jump_on_start(struct pp_hwmgr *hwmgr);
 bool smu7_is_smc_ram_running(struct pp_hwmgr *hwmgr);
 int smu7_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg);
-int smu7_send_msg_to_smc_without_waiting(struct pp_hwmgr *hwmgr, uint16_t msg);
 int smu7_send_msg_to_smc_with_parameter(struct pp_hwmgr *hwmgr, uint16_t msg,
uint32_t parameter);
-int smu7_send_msg_to_smc_with_parameter_without_waiting(struct pp_hwmgr *hwmgr,
-   uint16_t msg, uint32_t 
parameter);
 uint32_t smu7_get_argument(struct pp_hwmgr *hwmgr);
 int smu7_send_msg_to_smc_offset(struct pp_hwmgr *hwmgr);
 
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/9] drm/amd/powerplay: avoid calling SMU7 specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: Ie1365f350abcde4c4474e9bbdaf7742349a0534d
Signed-off-by: Evan Quan 
---
 .../gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c  | 10 +++
 .../drm/amd/powerplay/hwmgr/smu7_thermal.c|  8 +++---
 .../drm/amd/powerplay/smumgr/fiji_smumgr.c|  7 +++--
 .../drm/amd/powerplay/smumgr/iceland_smumgr.c |  1 +
 .../amd/powerplay/smumgr/polaris10_smumgr.c   |  3 ++-
 .../drm/amd/powerplay/smumgr/smu7_smumgr.c| 26 ---
 .../drm/amd/powerplay/smumgr/smu7_smumgr.h|  1 +
 .../drm/amd/powerplay/smumgr/tonga_smumgr.c   |  1 +
 .../drm/amd/powerplay/smumgr/vegam_smumgr.c   |  1 +
 9 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index 7740488999df..fc4e6dd2aa82 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -3496,7 +3496,7 @@ static int smu7_get_gpu_power(struct pp_hwmgr *hwmgr, u32 
*query)
(adev->asic_type != CHIP_FIJI) &&
(adev->asic_type != CHIP_TONGA)) {
smum_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_MSG_GetCurrPkgPwr, 0);
-   tmp = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+   tmp = smum_get_argument(hwmgr);
*query = tmp;
 
if (tmp != 0)
@@ -3535,13 +3535,13 @@ static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int 
idx,
switch (idx) {
case AMDGPU_PP_SENSOR_GFX_SCLK:
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency);
-   sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+   sclk = smum_get_argument(hwmgr);
*((uint32_t *)value) = sclk;
*size = 4;
return 0;
case AMDGPU_PP_SENSOR_GFX_MCLK:
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency);
-   mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+   mclk = smum_get_argument(hwmgr);
*((uint32_t *)value) = mclk;
*size = 4;
return 0;
@@ -4455,7 +4455,7 @@ static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
switch (type) {
case PP_SCLK:
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetSclkFrequency);
-   clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+   clock = smum_get_argument(hwmgr);
 
for (i = 0; i < sclk_table->count; i++) {
if (clock > sclk_table->dpm_levels[i].value)
@@ -4471,7 +4471,7 @@ static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
break;
case PP_MCLK:
smum_send_msg_to_smc(hwmgr, PPSMC_MSG_API_GetMclkFrequency);
-   clock = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);
+   clock = smum_get_argument(hwmgr);
 
for (i = 0; i < mclk_table->count; i++) {
if (clock > mclk_table->dpm_levels[i].value)
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c 
b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
index 5bdc0df5a9f4..dd4f450d1199 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
@@ -151,8 +151,8 @@ int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr 
*hwmgr)
int result;
 
if (PP_CAP(PHM_PlatformCaps_ODFuzzyFanControlSupport)) {
-   cgs_write_register(hwmgr->device, mmSMC_MSG_ARG_0, 
FAN_CONTROL_FUZZY);
-   result = smum_send_msg_to_smc(hwmgr, PPSMC_StartFanControl);
+   result = smum_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_StartFanControl,
+   FAN_CONTROL_FUZZY);
 
if (PP_CAP(PHM_PlatformCaps_FanSpeedInTableIsRPM))
hwmgr->hwmgr_func->set_max_fan_rpm_output(hwmgr,
@@ -164,8 +164,8 @@ int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr 
*hwmgr)

advanceFanControlParameters.usMaxFanPWM);
 
} else {
-   cgs_write_register(hwmgr->device, mmSMC_MSG_ARG_0, 
FAN_CONTROL_TABLE);
-   result = smum_send_msg_to_smc(hwmgr, PPSMC_StartFanControl);
+   result = smum_send_msg_to_smc_with_parameter(hwmgr, 
PPSMC_StartFanControl,
+   FAN_CONTROL_TABLE);
}
 
if (!result && hwmgr->thermal_controller.
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
index 32ebb383c456..ab35e4619d15 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
@@ -137,9 +1

[PATCH 9/9] drm/amd/powerplay: added mutex protection on msg issuing

2020-03-26 Thread Evan Quan
This could avoid the possible race condition.

Change-Id: I518b6f96b1a836bda4f1c7e13c00f62cd316a90c
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c |  3 +++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h |  1 +
 drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c | 16 ++--
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c 
b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index a7f4164fe8d4..9881e20c1119 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -50,6 +50,7 @@ static int amd_powerplay_create(struct amdgpu_device *adev)
hwmgr->not_vf = !amdgpu_sriov_vf(adev);
hwmgr->device = amdgpu_cgs_create_device(adev);
mutex_init(&hwmgr->smu_lock);
+   mutex_init(&hwmgr->msg_lock);
hwmgr->chip_family = adev->family;
hwmgr->chip_id = adev->asic_type;
hwmgr->feature_mask = adev->pm.pp_feature;
@@ -64,6 +65,8 @@ static void amd_powerplay_destroy(struct amdgpu_device *adev)
 {
struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
 
+   mutex_destroy(&hwmgr->msg_lock);
+
kfree(hwmgr->hardcode_pp_table);
hwmgr->hardcode_pp_table = NULL;
 
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h 
b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 34c48b6daa46..9b8fe00bd601 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -744,6 +744,7 @@ struct pp_hwmgr {
bool pm_en;
bool pp_one_vf;
struct mutex smu_lock;
+   struct mutex msg_lock;
 
uint32_t pp_table_version;
void *device;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
index 3bb0392994ec..b6fb48066841 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
@@ -136,13 +136,19 @@ int smum_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t 
msg, uint32_t *resp)
(resp && !hwmgr->smumgr_funcs->get_argument))
return -EINVAL;
 
+   mutex_lock(&hwmgr->msg_lock);
+
ret = hwmgr->smumgr_funcs->send_msg_to_smc(hwmgr, msg);
-   if (ret)
+   if (ret) {
+   mutex_unlock(&hwmgr->msg_lock);
return ret;
+   }
 
if (resp)
*resp = hwmgr->smumgr_funcs->get_argument(hwmgr);
 
+   mutex_unlock(&hwmgr->msg_lock);
+
return ret;
 }
 
@@ -158,14 +164,20 @@ int smum_send_msg_to_smc_with_parameter(struct pp_hwmgr 
*hwmgr,
(resp && !hwmgr->smumgr_funcs->get_argument))
return -EINVAL;
 
+   mutex_lock(&hwmgr->msg_lock);
+
ret = hwmgr->smumgr_funcs->send_msg_to_smc_with_parameter(
hwmgr, msg, parameter);
-   if (ret)
+   if (ret) {
+   mutex_unlock(&hwmgr->msg_lock);
return ret;
+   }
 
if (resp)
*resp = hwmgr->smumgr_funcs->get_argument(hwmgr);
 
+   mutex_unlock(&hwmgr->msg_lock);
+
return ret;
 }
 
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 7/9] drm/amd/powerplay: avoid calling Vega20 specific SMU message implemention

2020-03-26 Thread Evan Quan
Prepare for coming lock protection for SMU message issuing.

Change-Id: Ie5656cdc036cc21c6cc079bce2a43b05f3e167a8
Signed-off-by: Evan Quan 
---
 .../drm/amd/powerplay/smumgr/vega20_smumgr.c  | 48 +--
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c 
b/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
index 16aa171971d3..2a9bf78e32bd 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
@@ -175,17 +175,17 @@ static int vega20_copy_table_from_smc(struct pp_hwmgr 
*hwmgr,
PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
"Invalid SMU Table Length!", return -EINVAL);
 
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr))) == 0,
"[CopyTableFromSMC] Attempt to Set Dram Addr High 
Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr))) == 0,
"[CopyTableFromSMC] Attempt to Set Dram Addr Low 
Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableSmu2Dram, table_id)) == 0,
"[CopyTableFromSMC] Attempt to Transfer Table From SMU 
Failed!",
return ret);
@@ -224,17 +224,17 @@ static int vega20_copy_table_to_smc(struct pp_hwmgr 
*hwmgr,
 
amdgpu_asic_flush_hdp(adev, NULL);
 
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[table_id].mc_addr))) == 0,
"[CopyTableToSMC] Attempt to Set Dram Addr High 
Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[table_id].mc_addr))) == 0,
"[CopyTableToSMC] Attempt to Set Dram Addr Low Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableDram2Smu, table_id)) == 0,
"[CopyTableToSMC] Attempt to Transfer Table To SMU 
Failed!",
return ret);
@@ -255,17 +255,17 @@ int vega20_set_activity_monitor_coeff(struct pp_hwmgr 
*hwmgr,
 
amdgpu_asic_flush_hdp(adev, NULL);
 
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrHigh,

upper_32_bits(priv->smu_tables.entry[TABLE_ACTIVITY_MONITOR_COEFF].mc_addr))) 
== 0,
"[SetActivityMonitor] Attempt to Set Dram Addr High 
Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_SetDriverDramAddrLow,

lower_32_bits(priv->smu_tables.entry[TABLE_ACTIVITY_MONITOR_COEFF].mc_addr))) 
== 0,
"[SetActivityMonitor] Attempt to Set Dram Addr Low 
Failed!",
return ret);
-   PP_ASSERT_WITH_CODE((ret = vega20_send_msg_to_smc_with_parameter(hwmgr,
+   PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
PPSMC_MSG_TransferTableDram2Smu, 
TABLE_ACTIVITY_MONITOR_COEFF | (workload_type << 16))) == 0,
"[SetActivityMonitor] Attempt to Transfer Table To SMU 
Failed!",
return ret);
@@ -281,17 +281,17 @@ int vega20_get_activity_monitor_coeff(struct pp_hwmgr 
*hwmgr,
struct amdgpu_de

[PATCH] drm/amdgpu: fix non-pointer dereference for non-RAS supported

2020-03-27 Thread Evan Quan
Backtrace on gpu recover test on Navi10.

[ 1324.516681] RIP: 0010:amdgpu_ras_set_error_query_ready+0x15/0x20 [amdgpu]
[ 1324.523778] Code: 4c 89 f7 e8 cd a2 a0 d8 e9 99 fe ff ff 45 31 ff e9 91 fe 
ff ff 0f 1f 44 00 00 55 48 85 ff 48 89 e5 74 0e 48 8b 87 d8 2b 01 00 <40> 88 b0 
38 01 00 00 5d c3 66 90 0f 1f 44 00 00 55 31 c0 48 85 ff
[ 1324.543452] RSP: 0018:aa1040e4bd28 EFLAGS: 00010286
[ 1324.549025] RAX:  RBX: 911198b2 RCX: 
[ 1324.556217] RDX: 000c0a01 RSI:  RDI: 911198b2
[ 1324.563514] RBP: aa1040e4bd28 R08: 1000 R09: 91119d0028c0
[ 1324.570804] R10: 9a606b40 R11:  R12: 
[ 1324.578413] R13: aa1040e4bd70 R14: 911198b2 R15: 
[ 1324.586464] FS:  7f4441cbf540() GS:91119ed8() 
knlGS:
[ 1324.595434] CS:  0010 DS:  ES:  CR0: 80050033
[ 1324.601345] CR2: 0138 CR3: 0003fcdf8004 CR4: 003606e0
[ 1324.608694] DR0:  DR1:  DR2: 
[ 1324.616303] DR3:  DR6: fffe0ff0 DR7: 0400
[ 1324.623678] Call Trace:
[ 1324.626270]  amdgpu_device_gpu_recover+0x6e7/0xc50 [amdgpu]
[ 1324.632018]  ? seq_printf+0x4e/0x70
[ 1324.636652]  amdgpu_debugfs_gpu_recover+0x50/0x80 [amdgpu]
[ 1324.643371]  seq_read+0xda/0x420
[ 1324.647601]  full_proxy_read+0x5c/0x90
[ 1324.652426]  __vfs_read+0x1b/0x40
[ 1324.656734]  vfs_read+0x8e/0x130
[ 1324.660981]  ksys_read+0xa7/0xe0
[ 1324.665201]  __x64_sys_read+0x1a/0x20
[ 1324.669907]  do_syscall_64+0x57/0x1c0
[ 1324.674517]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 1324.680654] RIP: 0033:0x7f44417cf081

Change-Id: I053089a8e44749db23ec882d14f876ded9c1332d
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 9e9e0f7747b7..8a78db648442 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -82,13 +82,13 @@ static bool amdgpu_ras_check_bad_page(struct amdgpu_device 
*adev,
 
 void amdgpu_ras_set_error_query_ready(struct amdgpu_device *adev, bool ready)
 {
-   if (adev)
+   if (adev && amdgpu_ras_get_context(adev))
amdgpu_ras_get_context(adev)->error_query_ready = ready;
 }
 
 bool amdgpu_ras_get_error_query_ready(struct amdgpu_device *adev)
 {
-   if (adev)
+   if (adev && amdgpu_ras_get_context(adev))
return amdgpu_ras_get_context(adev)->error_query_ready;
 
return false;
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amd/powerplay: drop redundant BIF doorbell interrupt operations

2020-03-27 Thread Evan Quan
This is already done in soc15.c. And this is really ASIC specific
and should not be placed here.

Change-Id: I7c9ee3cce07463849a29c7bcbcb493f817626274
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c 
b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index 160ed40bbc86..31b93cff19d5 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -1700,11 +1700,9 @@ enum smu_baco_state smu_v11_0_baco_get_state(struct 
smu_context *smu)
 
 int smu_v11_0_baco_set_state(struct smu_context *smu, enum smu_baco_state 
state)
 {
-
struct smu_baco_context *smu_baco = &smu->smu_baco;
struct amdgpu_device *adev = smu->adev;
struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
-   uint32_t bif_doorbell_intr_cntl;
uint32_t data;
int ret = 0;
 
@@ -1713,14 +1711,7 @@ int smu_v11_0_baco_set_state(struct smu_context *smu, 
enum smu_baco_state state)
 
mutex_lock(&smu_baco->mutex);
 
-   bif_doorbell_intr_cntl = RREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL);
-
if (state == SMU_BACO_STATE_ENTER) {
-   bif_doorbell_intr_cntl = REG_SET_FIELD(bif_doorbell_intr_cntl,
-   BIF_DOORBELL_INT_CNTL,
-   DOORBELL_INTERRUPT_DISABLE, 1);
-   WREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL, 
bif_doorbell_intr_cntl);
-
if (!ras || !ras->supported) {
data = RREG32_SOC15(THM, 0, mmTHM_BACO_CNTL);
data |= 0x8000;
@@ -1741,11 +1732,6 @@ int smu_v11_0_baco_set_state(struct smu_context *smu, 
enum smu_baco_state state)
goto out;
}
 
-   bif_doorbell_intr_cntl = REG_SET_FIELD(bif_doorbell_intr_cntl,
-   BIF_DOORBELL_INT_CNTL,
-   DOORBELL_INTERRUPT_DISABLE, 0);
-   WREG32_SOC15(NBIO, 0, mmBIF_DOORBELL_INT_CNTL, 
bif_doorbell_intr_cntl);
-
/* clear vbios scratch 6 and 7 for coming asic reinit */
WREG32(adev->bios_scratch_reg_offset + 6, 0);
WREG32(adev->bios_scratch_reg_offset + 7, 0);
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: move the ASIC specific nbio operation out of smu_v11_0.c

2020-03-27 Thread Evan Quan
This is ASIC specific and should be placed in _ppt.c of each ASIC.

Change-Id: If2b29ccf0dfc0dc90e1636a806b13ce2efed58c6
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 15 ++-
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c   | 18 --
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c| 10 +-
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c   | 14 +-
 4 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c 
b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
index c6d3bef15320..5db8c56066ee 100644
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
@@ -35,6 +35,7 @@
 #include "arcturus_ppt.h"
 #include "smu_v11_0_pptable.h"
 #include "arcturus_ppsmc.h"
+#include "nbio/nbio_7_4_offset.h"
 #include "nbio/nbio_7_4_sh_mask.h"
 #include "amdgpu_xgmi.h"
 #include 
@@ -2210,6 +2211,18 @@ static void arcturus_i2c_eeprom_control_fini(struct 
i2c_adapter *control)
i2c_del_adapter(control);
 }
 
+static bool arcturus_is_baco_supported(struct smu_context *smu)
+{
+   struct amdgpu_device *adev = smu->adev;
+   uint32_t val;
+
+   if (!smu_v11_0_baco_is_support(smu))
+   return false;
+
+   val = RREG32_SOC15(NBIO, 0, mmRCC_BIF_STRAP0);
+   return (val & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK) ? true : false;
+}
+
 static uint32_t arcturus_get_pptable_power_limit(struct smu_context *smu)
 {
PPTable_t *pptable = smu->smu_table.driver_pptable;
@@ -2321,7 +2334,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
.register_irq_handler = smu_v11_0_register_irq_handler,
.set_azalia_d3_pme = smu_v11_0_set_azalia_d3_pme,
.get_max_sustainable_clocks_by_dc = 
smu_v11_0_get_max_sustainable_clocks_by_dc,
-   .baco_is_support= smu_v11_0_baco_is_support,
+   .baco_is_support= arcturus_is_baco_supported,
.baco_get_state = smu_v11_0_baco_get_state,
.baco_set_state = smu_v11_0_baco_set_state,
.baco_enter = smu_v11_0_baco_enter,
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c 
b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
index 1112e4c5f4d7..c94270f7c198 100644
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
@@ -28,13 +28,15 @@
 #include "smu_internal.h"
 #include "atomfirmware.h"
 #include "amdgpu_atomfirmware.h"
+#include "soc15_common.h"
 #include "smu_v11_0.h"
 #include "smu11_driver_if_navi10.h"
 #include "atom.h"
 #include "navi10_ppt.h"
 #include "smu_v11_0_pptable.h"
 #include "smu_v11_0_ppsmc.h"
-#include "nbio/nbio_7_4_sh_mask.h"
+#include "nbio/nbio_2_3_offset.h"
+#include "nbio/nbio_2_3_sh_mask.h"
 
 #include "asic_reg/mp/mp_11_0_sh_mask.h"
 
@@ -1942,6 +1944,18 @@ static int navi10_setup_od_limits(struct smu_context 
*smu) {
return 0;
 }
 
+static bool navi10_is_baco_supported(struct smu_context *smu)
+{
+   struct amdgpu_device *adev = smu->adev;
+   uint32_t val;
+
+   if (!smu_v11_0_baco_is_support(smu))
+   return false;
+
+   val = RREG32_SOC15(NBIO, 0, mmRCC_BIF_STRAP0);
+   return (val & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK) ? true : false;
+}
+
 static int navi10_set_default_od_settings(struct smu_context *smu, bool 
initialize) {
OverDriveTable_t *od_table, *boot_od_table;
int ret = 0;
@@ -2318,7 +2332,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
.register_irq_handler = smu_v11_0_register_irq_handler,
.set_azalia_d3_pme = smu_v11_0_set_azalia_d3_pme,
.get_max_sustainable_clocks_by_dc = 
smu_v11_0_get_max_sustainable_clocks_by_dc,
-   .baco_is_support= smu_v11_0_baco_is_support,
+   .baco_is_support= navi10_is_baco_supported,
.baco_get_state = smu_v11_0_baco_get_state,
.baco_set_state = smu_v11_0_baco_set_state,
.baco_enter = smu_v11_0_baco_enter,
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c 
b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index 31b93cff19d5..655ba4fb05dc 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -42,8 +42,6 @@
 #include "asic_reg/thm/thm_11_0_2_sh_mask.h"
 #include "asic_reg/mp/mp_11_0_offset.h"
 #include "asic_reg/mp/mp_11_0_sh_mask.h"
-#include "asic_reg/nbio/nbio_7_4_offset.h"
-#include "asic_reg/nbio/nbio_7_4_sh_mask.h"
 #include "asic_reg/smuio/smuio_11_0_0_offset.h"
 #include "asic_reg/smuio/smuio_11_0_0_sh_mask.h"
 
@@ -1662,9 +1660,7 @@ static int smu_v11_0_baco_set_armd3_sequence(struct 
smu_context *smu, enum smu_v
 
 bool smu_v11_0_baco_is_support(struct smu_cont

[PATCH] drm/amd/powerplay: error out on forcing clock setting not supported

2020-04-03 Thread Evan Quan
For Arcturus, forcing clock to some specific level is not supported
with 54.18 and onwards SMU firmware. As according to firmware team,
they adopt new gfx dpm tuned parameters which can cover all the use
case in a much smooth way. Thus setting through driver interface
is not needed and maybe do a disservice.

Change-Id: Ibffdb157639809707aa71049a935e53d1b4d06eb
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 47 +++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c 
b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
index 5db8c56066ee..1ef0923f7190 100644
--- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
@@ -794,8 +794,21 @@ static int arcturus_force_clk_levels(struct smu_context 
*smu,
struct arcturus_dpm_table *dpm_table;
struct arcturus_single_dpm_table *single_dpm_table;
uint32_t soft_min_level, soft_max_level;
+   uint32_t smu_version;
int ret = 0;
 
+   ret = smu_get_smc_version(smu, NULL, &smu_version);
+   if (ret) {
+   pr_err("Failed to get smu version!\n");
+   return ret;
+   }
+
+   if (smu_version >= 0x361200) {
+   pr_err("Forcing clock level is not supported with "
+  "54.18 and onwards SMU firmwares\n");
+   return -EOPNOTSUPP;
+   }
+
soft_min_level = mask ? (ffs(mask) - 1) : 0;
soft_max_level = mask ? (fls(mask) - 1) : 0;
 
@@ -1512,6 +1525,38 @@ static int arcturus_set_power_profile_mode(struct 
smu_context *smu,
return 0;
 }
 
+static int arcturus_set_performance_level(struct smu_context *smu,
+ enum amd_dpm_forced_level level)
+{
+   uint32_t smu_version;
+   int ret;
+
+   ret = smu_get_smc_version(smu, NULL, &smu_version);
+   if (ret) {
+   pr_err("Failed to get smu version!\n");
+   return ret;
+   }
+
+   switch (level) {
+   case AMD_DPM_FORCED_LEVEL_HIGH:
+   case AMD_DPM_FORCED_LEVEL_LOW:
+   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:
+   if (smu_version >= 0x361200) {
+   pr_err("Forcing clock level is not supported with "
+  "54.18 and onwards SMU firmwares\n");
+   return -EOPNOTSUPP;
+   }
+   break;
+   default:
+   break;
+   }
+
+   return smu_v11_0_set_performance_level(smu, level);
+}
+
 static void arcturus_dump_pptable(struct smu_context *smu)
 {
struct smu_table_context *table_context = &smu->smu_table;
@@ -2285,7 +2330,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
.get_profiling_clk_mask = arcturus_get_profiling_clk_mask,
.get_power_profile_mode = arcturus_get_power_profile_mode,
.set_power_profile_mode = arcturus_set_power_profile_mode,
-   .set_performance_level = smu_v11_0_set_performance_level,
+   .set_performance_level = arcturus_set_performance_level,
/* debug (internal used) */
.dump_pptable = arcturus_dump_pptable,
.get_power_limit = arcturus_get_power_limit,
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: fix wrong vram lost counter increment

2020-04-10 Thread Evan Quan
Vram lost counter is wrongly increased by two during baco reset.

Change-Id: I8b9959a5d1632abc774ba07d56cf295bdd8288eb
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 36 --
 drivers/gpu/drm/amd/amdgpu/cik.c   |  2 --
 drivers/gpu/drm/amd/amdgpu/nv.c|  4 ---
 drivers/gpu/drm/amd/amdgpu/soc15.c |  4 ---
 drivers/gpu/drm/amd/amdgpu/vi.c|  2 --
 5 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index a2a4e4b28d00..c9317975c46e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2087,8 +2087,40 @@ static void amdgpu_device_fill_reset_magic(struct 
amdgpu_device *adev)
  */
 static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)
 {
-   return !!memcmp(adev->gart.ptr, adev->reset_magic,
-   AMDGPU_RESET_MAGIC_NUM);
+   if (memcmp(adev->gart.ptr, adev->reset_magic,
+   AMDGPU_RESET_MAGIC_NUM))
+   return true;
+
+   if (!adev->in_gpu_reset)
+   return false;
+
+   /*
+* For all ASICs with baco reset, the VRAM is assumed to be
+* lost.
+* For SOC15 and NV ASICs with mode1 reset, the VRAM is also
+* assumed to be lost.
+*/
+   switch (amdgpu_asic_reset_method(adev)) {
+   case AMD_RESET_METHOD_BACO:
+   return true;
+   case AMD_RESET_METHOD_MODE1:
+   switch (adev->asic_type) {
+   case CHIP_VEGA10:
+   case CHIP_VEGA12:
+   case CHIP_VEGA20:
+   case CHIP_RAVEN:
+   case CHIP_ARCTURUS:
+   case CHIP_RENOIR:
+   case CHIP_NAVI10:
+   case CHIP_NAVI14:
+   case CHIP_NAVI12:
+   return true;
+   default:
+   return false;
+   }
+   default:
+   return false;
+   }
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index db68ffa27984..fe306d0f73f7 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -1358,8 +1358,6 @@ static int cik_asic_reset(struct amdgpu_device *adev)
int r;
 
if (cik_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
r = amdgpu_dpm_baco_reset(adev);
} else {
r = cik_asic_pci_config_reset(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
index 7768880fcccf..995bdec9fa7d 100644
--- a/drivers/gpu/drm/amd/amdgpu/nv.c
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c
@@ -351,8 +351,6 @@ static int nv_asic_reset(struct amdgpu_device *adev)
struct smu_context *smu = &adev->smu;
 
if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
ret = smu_baco_enter(smu);
if (ret)
return ret;
@@ -360,8 +358,6 @@ static int nv_asic_reset(struct amdgpu_device *adev)
if (ret)
return ret;
} else {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
ret = nv_asic_mode1_reset(adev);
}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index a597ad22b675..58a440a15525 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -569,14 +569,10 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
 
switch (soc15_asic_reset_method(adev)) {
case AMD_RESET_METHOD_BACO:
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
return soc15_asic_baco_reset(adev);
case AMD_RESET_METHOD_MODE2:
return amdgpu_dpm_mode2_reset(adev);
default:
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
return soc15_asic_mode1_reset(adev);
}
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 0a90c296409b..af8986a55354 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -744,8 +744,6 @@ static int vi_asic_reset(struct amdgpu_device *adev)
int r;
 
if (vi_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
r = amdgpu_dpm_baco_reset(adev);
} else {
r =

[PATCH] drm/amdgpu: fix wrong vram lost counter increment V2

2020-04-12 Thread Evan Quan
Vram lost counter is wrongly increased by two during baco reset.

V2: assumed vram lost for mode1 reset on all ASICs

Change-Id: I8b9959a5d1632abc774ba07d56cf295bdd8288eb
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 ++--
 drivers/gpu/drm/amd/amdgpu/cik.c   |  2 --
 drivers/gpu/drm/amd/amdgpu/nv.c|  4 
 drivers/gpu/drm/amd/amdgpu/soc15.c |  4 
 drivers/gpu/drm/amd/amdgpu/vi.c|  2 --
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index a2a4e4b28d00..8f479a918f0d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2087,8 +2087,24 @@ static void amdgpu_device_fill_reset_magic(struct 
amdgpu_device *adev)
  */
 static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)
 {
-   return !!memcmp(adev->gart.ptr, adev->reset_magic,
-   AMDGPU_RESET_MAGIC_NUM);
+   if (memcmp(adev->gart.ptr, adev->reset_magic,
+   AMDGPU_RESET_MAGIC_NUM))
+   return true;
+
+   if (!adev->in_gpu_reset)
+   return false;
+
+   /*
+* For all ASICs with baco/mode1 reset, the VRAM is
+* always assumed to be lost.
+*/
+   switch (amdgpu_asic_reset_method(adev)) {
+   case AMD_RESET_METHOD_BACO:
+   case AMD_RESET_METHOD_MODE1:
+   return true;
+   default:
+   return false;
+   }
 }
 
 /**
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index db68ffa27984..fe306d0f73f7 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -1358,8 +1358,6 @@ static int cik_asic_reset(struct amdgpu_device *adev)
int r;
 
if (cik_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
r = amdgpu_dpm_baco_reset(adev);
} else {
r = cik_asic_pci_config_reset(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
index 7768880fcccf..995bdec9fa7d 100644
--- a/drivers/gpu/drm/amd/amdgpu/nv.c
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c
@@ -351,8 +351,6 @@ static int nv_asic_reset(struct amdgpu_device *adev)
struct smu_context *smu = &adev->smu;
 
if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
ret = smu_baco_enter(smu);
if (ret)
return ret;
@@ -360,8 +358,6 @@ static int nv_asic_reset(struct amdgpu_device *adev)
if (ret)
return ret;
} else {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
ret = nv_asic_mode1_reset(adev);
}
 
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index a597ad22b675..58a440a15525 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -569,14 +569,10 @@ static int soc15_asic_reset(struct amdgpu_device *adev)
 
switch (soc15_asic_reset_method(adev)) {
case AMD_RESET_METHOD_BACO:
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
return soc15_asic_baco_reset(adev);
case AMD_RESET_METHOD_MODE2:
return amdgpu_dpm_mode2_reset(adev);
default:
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
return soc15_asic_mode1_reset(adev);
}
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 0a90c296409b..af8986a55354 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -744,8 +744,6 @@ static int vi_asic_reset(struct amdgpu_device *adev)
int r;
 
if (vi_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
-   if (!adev->in_suspend)
-   amdgpu_inc_vram_lost(adev);
r = amdgpu_dpm_baco_reset(adev);
} else {
r = vi_asic_pci_config_reset(adev);
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amd/powerplay: correct i2c eeprom init/fini sequence

2020-04-13 Thread Evan Quan
As data transfer may starts immediately after i2c eeprom init
completed. Thus i2c eeprom should be initialized after SMU
ready. And i2c data transfer should be prohibited when SMU
down. That is the i2c eeprom fini sequence needs to be
updated also.

Change-Id: I8444c05b51e67347841641fe5768d3126d089792
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c| 22 ++-
 .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h|  5 -
 drivers/gpu/drm/amd/powerplay/smu_internal.h  |  5 +
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index e8b27fab6aa1..b69e8d6c0a96 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -932,13 +932,6 @@ static int smu_sw_init(void *handle)
return ret;
}
 
-   if (adev->smu.ppt_funcs->i2c_eeprom_init) {
-   ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
-
-   if (ret)
-   return ret;
-   }
-
return 0;
 }
 
@@ -948,9 +941,6 @@ static int smu_sw_fini(void *handle)
struct smu_context *smu = &adev->smu;
int ret;
 
-   if (adev->smu.ppt_funcs->i2c_eeprom_fini)
-   smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
-
kfree(smu->irq_source);
smu->irq_source = NULL;
 
@@ -1366,6 +1356,10 @@ static int smu_hw_init(void *handle)
if (ret)
goto failed;
 
+   ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
+   if (ret)
+   goto failed;
+
if (!smu->pm_enabled)
adev->pm.dpm_enabled = false;
else
@@ -1403,6 +1397,8 @@ static int smu_hw_fini(void *handle)
if (!smu->pm_enabled)
return 0;
 
+   smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
+
if (!amdgpu_sriov_vf(adev)){
ret = smu_stop_thermal_control(smu);
if (ret) {
@@ -1542,6 +1538,8 @@ static int smu_suspend(void *handle)
if (!smu->pm_enabled)
return 0;
 
+   smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
+
if(!amdgpu_sriov_vf(adev)) {
ret = smu_disable_dpm(smu);
if (ret)
@@ -1587,6 +1585,10 @@ static int smu_resume(void *handle)
if (ret)
goto failed;
 
+   ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
+   if (ret)
+   goto failed;
+
if (smu->is_apu)
smu_set_gfx_cgpg(&adev->smu, true);
 
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h 
b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index ae2c318dd6fa..30643b9b5b3b 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -580,11 +580,6 @@ int smu_check_fw_status(struct smu_context *smu);
 
 int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
 
-#define smu_i2c_eeprom_init(smu, control) \
-   ((smu)->ppt_funcs->i2c_eeprom_init ? 
(smu)->ppt_funcs->i2c_eeprom_init((control)) : -EINVAL)
-#define smu_i2c_eeprom_fini(smu, control) \
-   ((smu)->ppt_funcs->i2c_eeprom_fini ? 
(smu)->ppt_funcs->i2c_eeprom_fini((control)) : -EINVAL)
-
 int smu_set_fan_speed_rpm(struct smu_context *smu, uint32_t speed);
 
 int smu_get_power_limit(struct smu_context *smu,
diff --git a/drivers/gpu/drm/amd/powerplay/smu_internal.h 
b/drivers/gpu/drm/amd/powerplay/smu_internal.h
index 40c35bcc5a0a..c97444841abc 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_internal.h
+++ b/drivers/gpu/drm/amd/powerplay/smu_internal.h
@@ -214,4 +214,9 @@ static inline int smu_send_smc_msg(struct smu_context *smu, 
enum smu_message_typ
 #define smu_set_power_source(smu, power_src) \
((smu)->ppt_funcs->set_power_source ? 
(smu)->ppt_funcs->set_power_source((smu), (power_src)) : 0)
 
+#define smu_i2c_eeprom_init(smu, control) \
+   ((smu)->ppt_funcs->i2c_eeprom_init ? 
(smu)->ppt_funcs->i2c_eeprom_init((control)) : 0)
+#define smu_i2c_eeprom_fini(smu, control) \
+   ((smu)->ppt_funcs->i2c_eeprom_fini ? 
(smu)->ppt_funcs->i2c_eeprom_fini((control)) : 0)
+
 #endif
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: properly set the dpm_enabled state

2020-04-13 Thread Evan Quan
On the ASIC powered down(in baco or system suspend),
the dpm_enabled will be set as false. Then all access
(e.g. df state setting issued on RAS error event) to
SMU will be blocked.

Change-Id: I128c681b6f520d24d4247e438773b2b4b497d43b
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c   | 250 ---
 drivers/gpu/drm/amd/powerplay/arcturus_ppt.c |  10 -
 drivers/gpu/drm/amd/powerplay/renoir_ppt.c   |   2 +-
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c|  20 --
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c   |   4 +-
 5 files changed, 220 insertions(+), 66 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index b69e8d6c0a96..561f7b77398a 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -62,6 +62,7 @@ const char *smu_get_feature_name(struct smu_context *smu, 
enum smu_feature_mask
 
 size_t smu_sys_get_pp_feature_mask(struct smu_context *smu, char *buf)
 {
+   struct amdgpu_device *adev = smu->adev;
size_t size = 0;
int ret = 0, i = 0;
uint32_t feature_mask[2] = { 0 };
@@ -70,6 +71,9 @@ size_t smu_sys_get_pp_feature_mask(struct smu_context *smu, 
char *buf)
uint32_t sort_feature[SMU_FEATURE_COUNT];
uint64_t hw_feature_count = 0;
 
+   if (!adev->pm.dpm_enabled)
+   return -EINVAL;
+
mutex_lock(&smu->mutex);
 
ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
@@ -110,9 +114,6 @@ static int smu_feature_update_enable_state(struct 
smu_context *smu,
uint32_t feature_low = 0, feature_high = 0;
int ret = 0;
 
-   if (!smu->pm_enabled)
-   return ret;
-
feature_low = (feature_mask >> 0 ) & 0x;
feature_high = (feature_mask >> 32) & 0x;
 
@@ -155,6 +156,10 @@ int smu_sys_set_pp_feature_mask(struct smu_context *smu, 
uint64_t new_mask)
uint64_t feature_2_enabled = 0;
uint64_t feature_2_disabled = 0;
uint64_t feature_enables = 0;
+   struct amdgpu_device *adev = smu->adev;
+
+   if (!adev->pm.dpm_enabled)
+   return -EINVAL;
 
mutex_lock(&smu->mutex);
 
@@ -417,8 +422,12 @@ bool smu_clk_dpm_is_enabled(struct smu_context *smu, enum 
smu_clk_type clk_type)
 int smu_dpm_set_power_gate(struct smu_context *smu, uint32_t block_type,
   bool gate)
 {
+   struct amdgpu_device *adev = smu->adev;
int ret = 0;
 
+   if (!adev->pm.dpm_enabled)
+   return -EINVAL;
+
switch (block_type) {
case AMD_IP_BLOCK_TYPE_UVD:
ret = smu_dpm_set_uvd_enable(smu, !gate);
@@ -569,8 +578,12 @@ bool is_support_sw_smu_xgmi(struct amdgpu_device *adev)
 int smu_sys_get_pp_table(struct smu_context *smu, void **table)
 {
struct smu_table_context *smu_table = &smu->smu_table;
+   struct amdgpu_device *adev = smu->adev;
uint32_t powerplay_table_size;
 
+   if (!adev->pm.dpm_enabled)
+   return -EINVAL;
+
if (!smu_table->power_play_table && !smu_table->hardcode_pptable)
return -EINVAL;
 
@@ -591,11 +604,13 @@ int smu_sys_get_pp_table(struct smu_context *smu, void 
**table)
 int smu_sys_set_pp_table(struct smu_context *smu,  void *buf, size_t size)
 {
struct smu_table_context *smu_table = &smu->smu_table;
+   struct amdgpu_device *adev = smu->adev;
ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
int ret = 0;
 
-   if (!smu->pm_enabled)
+   if (!adev->pm.dpm_enabled)
return -EINVAL;
+
if (header->usStructureSize != size) {
pr_err("pp table size not matched !\n");
return -EIO;
@@ -636,8 +651,6 @@ int smu_feature_init_dpm(struct smu_context *smu)
int ret = 0;
uint32_t allowed_feature_mask[SMU_FEATURE_MAX/32];
 
-   if (!smu->pm_enabled)
-   return ret;
mutex_lock(&feature->mutex);
bitmap_zero(feature->allowed, SMU_FEATURE_MAX);
mutex_unlock(&feature->mutex);
@@ -1360,10 +1373,7 @@ static int smu_hw_init(void *handle)
if (ret)
goto failed;
 
-   if (!smu->pm_enabled)
-   adev->pm.dpm_enabled = false;
-   else
-   adev->pm.dpm_enabled = true;/* TODO: will set dpm_enabled 
flag while VCN and DAL DPM is workable */
+   adev->pm.dpm_enabled = true;
 
pr_info("SMU is initialized successfully!\n");
 
@@ -1397,6 +1407,8 @@ static int smu_hw_fini(void *handle)
if (!smu->pm_enabled)
return 0;
 
+   adev->pm.dpm_enabled = false;
+
smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
 
if (!amdgpu_sriov_vf(adev)){
@@ -1538,6 +1550,8 @@ static 

[PATCH 1/2] drm/amd/powerplay: revise the way to retrieve the board parameters

2020-04-13 Thread Evan Quan
It can support different NV1x ASIC better. And this can guard
no member got missing.

Change-Id: Id5e6608f6be1b31ef1c0a5c1d399da295524ff43
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/include/atomfirmware.h | 102 +
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c |  99 ++--
 2 files changed, 130 insertions(+), 71 deletions(-)

diff --git a/drivers/gpu/drm/amd/include/atomfirmware.h 
b/drivers/gpu/drm/amd/include/atomfirmware.h
index 70146518174c..a6f6e6bf5992 100644
--- a/drivers/gpu/drm/amd/include/atomfirmware.h
+++ b/drivers/gpu/drm/amd/include/atomfirmware.h
@@ -1876,6 +1876,108 @@ struct atom_smc_dpm_info_v4_6
   uint32_t   boardreserved[10];
 };
 
+struct atom_smc_dpm_info_v4_7
+{
+  struct   atom_common_table_header  table_header;
+// SECTION: BOARD PARAMETERS
+// I2C Control
+  struct smudpm_i2c_controller_config_v2  I2cControllers[8];
+
+  // SVI2 Board Parameters
+  uint16_t MaxVoltageStepGfx; // In mV(Q2) Max voltage step that SMU will 
request. Multiple steps are taken if voltage change exceeds this value.
+  uint16_t MaxVoltageStepSoc; // In mV(Q2) Max voltage step that SMU will 
request. Multiple steps are taken if voltage change exceeds this value.
+
+  uint8_t  VddGfxVrMapping;   // Use VR_MAPPING* bitfields
+  uint8_t  VddSocVrMapping;   // Use VR_MAPPING* bitfields
+  uint8_t  VddMem0VrMapping;  // Use VR_MAPPING* bitfields
+  uint8_t  VddMem1VrMapping;  // Use VR_MAPPING* bitfields
+
+  uint8_t  GfxUlvPhaseSheddingMask; // set this to 1 to set PSI0/1 to 1 in 
ULV mode
+  uint8_t  SocUlvPhaseSheddingMask; // set this to 1 to set PSI0/1 to 1 in 
ULV mode
+  uint8_t  ExternalSensorPresent; // External RDI connected to TMON (aka 
TEMP IN)
+  uint8_t  Padding8_V;
+
+  // Telemetry Settings
+  uint16_t GfxMaxCurrent;   // in Amps
+  uint8_t  GfxOffset;   // in Amps
+  uint8_t  Padding_TelemetryGfx;
+  uint16_t SocMaxCurrent;   // in Amps
+  uint8_t  SocOffset;   // in Amps
+  uint8_t  Padding_TelemetrySoc;
+
+  uint16_t Mem0MaxCurrent;   // in Amps
+  uint8_t  Mem0Offset;   // in Amps
+  uint8_t  Padding_TelemetryMem0;
+
+  uint16_t Mem1MaxCurrent;   // in Amps
+  uint8_t  Mem1Offset;   // in Amps
+  uint8_t  Padding_TelemetryMem1;
+
+  // GPIO Settings
+  uint8_t  AcDcGpio;// GPIO pin configured for AC/DC switching
+  uint8_t  AcDcPolarity;// GPIO polarity for AC/DC switching
+  uint8_t  VR0HotGpio;  // GPIO pin configured for VR0 HOT event
+  uint8_t  VR0HotPolarity;  // GPIO polarity for VR0 HOT event
+
+  uint8_t  VR1HotGpio;  // GPIO pin configured for VR1 HOT event
+  uint8_t  VR1HotPolarity;  // GPIO polarity for VR1 HOT event
+  uint8_t  GthrGpio;// GPIO pin configured for GTHR Event
+  uint8_t  GthrPolarity;// replace GPIO polarity for GTHR
+
+  // LED Display Settings
+  uint8_t  LedPin0; // GPIO number for LedPin[0]
+  uint8_t  LedPin1; // GPIO number for LedPin[1]
+  uint8_t  LedPin2; // GPIO number for LedPin[2]
+  uint8_t  padding8_4;
+
+  // GFXCLK PLL Spread Spectrum
+  uint8_t  PllGfxclkSpreadEnabled;   // on or off
+  uint8_t  PllGfxclkSpreadPercent;   // Q4.4
+  uint16_t PllGfxclkSpreadFreq;  // kHz
+
+  // GFXCLK DFLL Spread Spectrum
+  uint8_t  DfllGfxclkSpreadEnabled;   // on or off
+  uint8_t  DfllGfxclkSpreadPercent;   // Q4.4
+  uint16_t DfllGfxclkSpreadFreq;  // kHz
+
+  // UCLK Spread Spectrum
+  uint8_t  UclkSpreadEnabled;   // on or off
+  uint8_t  UclkSpreadPercent;   // Q4.4
+  uint16_t UclkSpreadFreq;  // kHz
+
+  // SOCCLK Spread Spectrum
+  uint8_t  SoclkSpreadEnabled;   // on or off
+  uint8_t  SocclkSpreadPercent;   // Q4.4
+  uint16_t SocclkSpreadFreq;  // kHz
+
+  // Total board power
+  uint16_t TotalBoardPower; //Only needed for TCP Estimated case, 
where TCP = TGP+Total Board Power
+  uint16_t BoardPadding;
+
+  // Mvdd Svi2 Div Ratio Setting
+  uint32_t MvddRatio; // This is used for MVDD Vid workaround. It has 16 
fractional bits (Q16.16)
+
+  // GPIO pins for I2C communications with 2nd controller for Input Telemetry 
Sequence
+  uint8_t  GpioI2cScl;  // Serial Clock
+  uint8_t  GpioI2cSda;  // Serial Data
+  uint16_t GpioPadding;
+
+  // Additional LED Display Settings
+  uint8_t  LedPin3; // GPIO number for LedPin[3] - PCIE GEN Speed
+  uint8_t  LedPin4; // GPIO number for LedPin[4] - PMFW Error 
Status
+  uint16_t LedEnableMask;
+
+  // Power Limit Scalars
+  uint8_t  PowerLimitScalar[4];//[PPT_THROTTLER_COUNT]
+
+  uint8_t  MvddUlvPhaseSheddingMask;
+  uint8_t  VddciUlvPhaseSheddingMask;
+  uint8_t  Padding8_Psi1;
+  uint8_t  Padding8_Psi2;
+
+  uint32_t BoardReserved[5

[PATCH 2/2] drm/amd/powerplay: bump the NAVI10 smu-driver if version

2020-04-13 Thread Evan Quan
To fit the latest SMC firmware 42.53 and eliminate the
warning on driver loading.

Change-Id: I3f524d03e53ec6778b7118ef72652a538eec4ace
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h 
b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
index 674e426ed59b..e786d63b1e79 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
@@ -28,7 +28,7 @@
 #define SMU11_DRIVER_IF_VERSION_INV 0x
 #define SMU11_DRIVER_IF_VERSION_VG20 0x13
 #define SMU11_DRIVER_IF_VERSION_ARCT 0x12
-#define SMU11_DRIVER_IF_VERSION_NV10 0x35
+#define SMU11_DRIVER_IF_VERSION_NV10 0x36
 #define SMU11_DRIVER_IF_VERSION_NV12 0x33
 #define SMU11_DRIVER_IF_VERSION_NV14 0x36
 
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: update Arcturus smu-driver if header

2020-04-13 Thread Evan Quan
To fit the latest PMFW.

Change-Id: I1ebc5a4c3386e07a9fed73e4bec2c5d1ab8d4b23
Signed-off-by: Evan Quan 
---
 .../amd/powerplay/inc/smu11_driver_if_arcturus.h  | 15 +--
 drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h |  2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/inc/smu11_driver_if_arcturus.h 
b/drivers/gpu/drm/amd/powerplay/inc/smu11_driver_if_arcturus.h
index ce5b5011c122..8b82059d97e7 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/smu11_driver_if_arcturus.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/smu11_driver_if_arcturus.h
@@ -82,8 +82,8 @@
 // Other
 #define FEATURE_OUT_OF_BAND_MONITOR_BIT 24
 #define FEATURE_TEMP_DEPENDENT_VMIN_BIT 25
+#define FEATURE_PER_PART_VMIN_BIT   26
 
-#define FEATURE_SPARE_26_BIT26
 #define FEATURE_SPARE_27_BIT27
 #define FEATURE_SPARE_28_BIT28
 #define FEATURE_SPARE_29_BIT29
@@ -154,6 +154,7 @@
 
 #define FEATURE_OUT_OF_BAND_MONITOR_MASK  (1 << 
FEATURE_OUT_OF_BAND_MONITOR_BIT   )
 #define FEATURE_TEMP_DEPENDENT_VMIN_MASK  (1 << 
FEATURE_TEMP_DEPENDENT_VMIN_BIT )
+#define FEATURE_PER_PART_VMIN_MASK(1 << FEATURE_PER_PART_VMIN_BIT  
  )
 
 
 //FIXME need updating
@@ -628,8 +629,14 @@ typedef struct {
   uint16_t BasePerformanceFrequencyCap;   //In Mhz
   uint16_t MaxPerformanceFrequencyCap;//In Mhz
 
+  // Per-Part Vmin
+  uint16_t VDDGFX_VminLow;// mv Q2
+  uint16_t VDDGFX_TVminLow;   //Celcius
+  uint16_t VDDGFX_VminLow_HiTemp; // mv Q2
+  uint16_t VDDGFX_VminLow_LoTemp; // mv Q2
+
   // SECTION: Reserved
-  uint32_t Reserved[9];
+  uint32_t Reserved[7];
 
   // SECTION: BOARD PARAMETERS
 
@@ -869,6 +876,10 @@ typedef struct {
   uint8_t   Mem_DownHystLimit;
   uint16_t  Mem_Fps;
 
+  uint32_t  BusyThreshold;  // Q16
+  uint32_t  BusyHyst;
+  uint32_t  IdleHyst;
+
   uint32_t  MmHubPadding[8]; // SMU internal use
 } DpmActivityMonitorCoeffInt_t;
 
diff --git a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h 
b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
index e786d63b1e79..464d40983de9 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
@@ -27,7 +27,7 @@
 
 #define SMU11_DRIVER_IF_VERSION_INV 0x
 #define SMU11_DRIVER_IF_VERSION_VG20 0x13
-#define SMU11_DRIVER_IF_VERSION_ARCT 0x12
+#define SMU11_DRIVER_IF_VERSION_ARCT 0x14
 #define SMU11_DRIVER_IF_VERSION_NV10 0x36
 #define SMU11_DRIVER_IF_VERSION_NV12 0x33
 #define SMU11_DRIVER_IF_VERSION_NV14 0x36
-- 
2.26.0

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: load SMU IP for onevf mode on Navi1x V2

2020-04-16 Thread Evan Quan
SMU IP needs to be loaded for onevf mode. Otherwise, there
may be accesses without initialization.

V2: added SMU IP for all sriov cases since there is necessary
checks in IP operations(hw_init/fini)

Change-Id: I513aa4140f1169ca048b64985cafe9c7577afca7
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/nv.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
index 995bdec9fa7d..15ad9f78344c 100644
--- a/drivers/gpu/drm/amd/amdgpu/nv.c
+++ b/drivers/gpu/drm/amd/amdgpu/nv.c
@@ -474,8 +474,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
-   if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
-   !amdgpu_sriov_vf(adev))
+   if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
@@ -485,8 +484,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
 #endif
amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
-   if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
-   !amdgpu_sriov_vf(adev))
+   if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT)
amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
@@ -498,8 +496,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
-   if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
-   !amdgpu_sriov_vf(adev))
+   if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
@@ -509,8 +506,7 @@ int nv_set_ip_blocks(struct amdgpu_device *adev)
 #endif
amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
-   if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
-   !amdgpu_sriov_vf(adev))
+   if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT)
amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
if (!amdgpu_sriov_vf(adev))
-- 
2.26.1

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/4] drm/amdgpu: correct cancel_delayed_work_sync on gpu reset

2020-04-20 Thread Evan Quan
As for XGMI setup, it should be performed on other devices
from the hive also.

Change-Id: I08554c27216efa21c2c46c0b3379d856b5264c9e
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 6cbe5140b873..c8fe867d6ee3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4248,6 +4248,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
amdgpu_amdkfd_pre_reset(tmp_adev);
}
 
+   cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
+
/*
 * Mark these ASICs to be reseted as untracked first
 * And add them back after reset completed
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/4] drm/amdgpu: correct fbdev suspend on gpu reset

2020-04-20 Thread Evan Quan
As for XGMI setup, it needs to be performed on
all the devices from the same hive.

Change-Id: I25e6364d31f0b34938cf424a410628aa54dd2edd
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 079c9c5ef381..6cbe5140b873 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4254,7 +4254,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 */
amdgpu_unregister_gpu_instance(tmp_adev);
 
-   amdgpu_fbdev_set_suspend(adev, 1);
+   amdgpu_fbdev_set_suspend(tmp_adev, 1);
 
/* disable ras on ALL IPs */
if (!(in_ras_intr && !use_baco) &&
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 0/4] Some XGMI related gpu reset fixes and cleanups

2020-04-20 Thread Evan Quan
Patch 1 and 2 are the necessary fixes for XGMI setup. Since these
operations are needed for other devices from the same hive. That's
missing now.
Patch 3 are 4 are basically code cosmetic.

Evan Quan (4):
  drm/amdgpu: correct fbdev suspend on gpu reset
  drm/amdgpu: correct cancel_delayed_work_sync on gpu reset
  drm/amdgpu: optimize the gpu reset for XGMI setup V2
  drm/amdgpu: code cleanup around gpu reset

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 92 --
 1 file changed, 31 insertions(+), 61 deletions(-)

-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 3/4] drm/amdgpu: optimize the gpu reset for XGMI setup V2

2020-04-20 Thread Evan Quan
This is basically just some code cosmetic. The current design
for XGMI setup gput reset is to operate on current device(adev)
first and then on other devices from the hive(by another 'for' loop).
But actually we can do some sort to the device list(to put current
device 1st position) and handle all the devices in a single 'for'
loop.

V2: added missing hive->hive_lock protection

Change-Id: I84dca425f1ae778c4b4b8bc3a0d2b9a3d1b50043
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 76 +++---
 1 file changed, 25 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index c8fe867d6ee3..b415c1e5ea0d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4182,16 +4182,11 @@ int amdgpu_device_gpu_recover(struct amdgpu_device 
*adev,
}
 
need_full_reset = job_signaled = false;
-   INIT_LIST_HEAD(&device_list);
-
-   amdgpu_ras_set_error_query_ready(adev, false);
 
dev_info(adev->dev, "GPU %s begin!\n",
(in_ras_intr && !use_baco) ? "jobs stop":"reset");
 
-   cancel_delayed_work_sync(&adev->delayed_init_work);
-
-   hive = amdgpu_get_xgmi_hive(adev, false);
+   hive = amdgpu_get_xgmi_hive(adev, true);
 
/*
 * Here we trylock to avoid chain of resets executing from
@@ -4204,35 +4199,21 @@ int amdgpu_device_gpu_recover(struct amdgpu_device 
*adev,
if (hive && !mutex_trylock(&hive->reset_lock)) {
DRM_INFO("Bailing on TDR for s_job:%llx, hive: %llx as another 
already in progress",
  job ? job->base.id : -1, hive->hive_id);
+   mutex_unlock(&hive->hive_lock);
return 0;
}
 
-   /* Start with adev pre asic reset first for soft reset check.*/
-   if (!amdgpu_device_lock_adev(adev, !hive)) {
-   DRM_INFO("Bailing on TDR for s_job:%llx, as another already in 
progress",
- job ? job->base.id : -1);
-   return 0;
-   }
-
-   /* Block kfd: SRIOV would do it separately */
-   if (!amdgpu_sriov_vf(adev))
-amdgpu_amdkfd_pre_reset(adev);
-
-   /* Build list of devices to reset */
-   if  (adev->gmc.xgmi.num_physical_nodes > 1) {
-   if (!hive) {
-   /*unlock kfd: SRIOV would do it separately */
-   if (!amdgpu_sriov_vf(adev))
-   amdgpu_amdkfd_post_reset(adev);
-   amdgpu_device_unlock_adev(adev);
+   /*
+* Build list of devices to reset.
+* In case we are in XGMI hive mode, resort the device list
+* to put adev in the 1st position.
+*/
+   INIT_LIST_HEAD(&device_list);
+   if (adev->gmc.xgmi.num_physical_nodes > 1) {
+   if (!hive)
return -ENODEV;
-   }
-
-   /*
-* In case we are in XGMI hive mode device reset is done for 
all the
-* nodes in the hive to retrain all XGMI links and hence the 
reset
-* sequence is executed in loop on all nodes.
-*/
+   if (!list_is_first(&adev->gmc.xgmi.head, &hive->device_list))
+   list_rotate_to_front(&adev->gmc.xgmi.head, 
&hive->device_list);
device_list_handle = &hive->device_list;
} else {
list_add_tail(&adev->gmc.xgmi.head, &device_list);
@@ -4241,15 +4222,20 @@ int amdgpu_device_gpu_recover(struct amdgpu_device 
*adev,
 
/* block all schedulers and reset given job's ring */
list_for_each_entry(tmp_adev, device_list_handle, gmc.xgmi.head) {
-   if (tmp_adev != adev) {
-   amdgpu_ras_set_error_query_ready(tmp_adev, false);
-   amdgpu_device_lock_adev(tmp_adev, false);
-   if (!amdgpu_sriov_vf(tmp_adev))
-   amdgpu_amdkfd_pre_reset(tmp_adev);
+   if (!amdgpu_device_lock_adev(tmp_adev, !hive)) {
+   DRM_INFO("Bailing on TDR for s_job:%llx, as another 
already in progress",
+ job ? job->base.id : -1);
+   mutex_unlock(&hive->hive_lock);
+   return 0;
}
 
+   amdgpu_ras_set_error_query_ready(tmp_adev, false);
+
cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
 
+   if (!amdgpu_sriov_vf(tmp_adev))
+   amdgpu_amdkfd_pre_reset(tmp_adev);
+
/*
 * Mark these ASICs to be reseted as untracked fi

[PATCH 4/4] drm/amdgpu: code cleanup around gpu reset

2020-04-20 Thread Evan Quan
Make code more readable.

Change-Id: I28444f285b23aac16be421e3447d0de6c3a57ee8
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index b415c1e5ea0d..349c8f85fc8c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4160,7 +4160,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  struct amdgpu_job *job)
 {
struct list_head device_list, *device_list_handle =  NULL;
-   bool need_full_reset, job_signaled;
+   bool need_full_reset = false;
+   bool job_signaled = false;
struct amdgpu_hive_info *hive = NULL;
struct amdgpu_device *tmp_adev = NULL;
int i, r = 0;
@@ -4181,13 +4182,9 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
emergency_restart();
}
 
-   need_full_reset = job_signaled = false;
-
dev_info(adev->dev, "GPU %s begin!\n",
(in_ras_intr && !use_baco) ? "jobs stop":"reset");
 
-   hive = amdgpu_get_xgmi_hive(adev, true);
-
/*
 * Here we trylock to avoid chain of resets executing from
 * either trigger by jobs on different adevs in XGMI hive or jobs on
@@ -4195,7 +4192,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 * We always reset all schedulers for device and all devices for XGMI
 * hive so that should take care of them too.
 */
-
+   hive = amdgpu_get_xgmi_hive(adev, true);
if (hive && !mutex_trylock(&hive->reset_lock)) {
DRM_INFO("Bailing on TDR for s_job:%llx, hive: %llx as another 
already in progress",
  job ? job->base.id : -1, hive->hive_id);
@@ -4262,7 +4259,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
}
}
 
-
if (in_ras_intr && !use_baco)
goto skip_sched_resume;
 
@@ -4273,10 +4269,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 * job->base holds a reference to parent fence
 */
if (job && job->base.s_fence->parent &&
-   dma_fence_is_signaled(job->base.s_fence->parent))
+   dma_fence_is_signaled(job->base.s_fence->parent)) {
job_signaled = true;
-
-   if (job_signaled) {
dev_info(adev->dev, "Guilty job already signaled, skipping HW 
reset");
goto skip_hw_reset;
}
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: put the audio codec into suspend state before gpu reset

2020-04-21 Thread Evan Quan
At default, the autosuspend delay of audio controller is 3S. If the
gpu reset is triggered within 3S(after audio controller idle),
the audio controller may be unable into suspended state. Then
the sudden gpu reset will cause some audio errors. The change
here is targeted to resolve this.

However if the audio controller is in use when the gpu reset
triggered, this change may be still not enough to put the
audio controller into suspend state. Under this case, the
gpu reset will still proceed but there will be a warning
message printed("failed to suspend display audio").

Change-Id: I33d85e6fcad1882eb33f9cde8916d57be8d5a87a
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 60 ++
 1 file changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 2d4b78d96426..983e294d0300 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -69,6 +69,7 @@
 
 #include 
 #include 
+#include 
 
 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/vega12_gpu_info.bin");
@@ -4146,6 +4147,49 @@ static void amdgpu_device_unlock_adev(struct 
amdgpu_device *adev)
mutex_unlock(&adev->lock_reset);
 }
 
+static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
+{
+   struct pci_dev *p = NULL;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (p) {
+   pm_runtime_enable(&(p->dev));
+   pm_runtime_resume(&(p->dev));
+   }
+}
+
+static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
+{
+   struct pci_dev *p = NULL;
+   unsigned long end_jiffies;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (!p)
+   return -ENODEV;
+
+   /*
+* 3S is the audio controller default autosuspend delay setting.
+* 4S used here is guaranteed to cover that.
+*/
+   end_jiffies = msecs_to_jiffies(4000) + jiffies;
+   while (!pm_runtime_status_suspended(&(p->dev))) {
+   if (!pm_runtime_suspend(&(p->dev)))
+   break;
+
+   if (time_after(jiffies, end_jiffies)) {
+   dev_warn(adev->dev, "failed to suspend display 
audio\n");
+   /* TODO: abort the succeeding gpu reset? */
+   return -ETIMEDOUT;
+   }
+   }
+
+   pm_runtime_disable(&(p->dev));
+
+   return 0;
+}
+
 /**
  * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  *
@@ -4170,6 +4214,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
bool use_baco =
(amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) ?
true : false;
+   bool audio_suspended = false;
 
/*
 * Flush RAM to disk so that after reboot
@@ -4227,6 +4272,19 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
return 0;
}
 
+   /*
+* Try to put the audio codec into suspend state
+* before gpu reset started.
+*
+* Due to the power domain of the graphics device
+* is shared with AZ power domain. Without this,
+* we may change the audio hardware from behind
+* the audio driver's back. That will trigger
+* some audio codec errors.
+*/
+   if (!amdgpu_device_suspend_display_audio(tmp_adev))
+   audio_suspended = true;
+
amdgpu_ras_set_error_query_ready(tmp_adev, false);
 
cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
@@ -4339,6 +4397,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
/*unlock kfd: SRIOV would do it separately */
if (!(in_ras_intr && !use_baco) && !amdgpu_sriov_vf(tmp_adev))
amdgpu_amdkfd_post_reset(tmp_adev);
+   if (audio_suspended)
+   amdgpu_device_resume_display_audio(tmp_adev);
amdgpu_device_unlock_adev(tmp_adev);
}
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: put the audio codec into suspend state before gpu reset V2

2020-04-21 Thread Evan Quan
At default, the autosuspend delay of audio controller is 3S. If the
gpu reset is triggered within 3S(after audio controller idle),
the audio controller may be unable into suspended state. Then
the sudden gpu reset will cause some audio errors. The change
here is targeted to resolve this.

However if the audio controller is in use when the gpu reset
triggered, this change may be still not enough to put the
audio controller into suspend state. Under this case, the
gpu reset will still proceed but there will be a warning
message printed("failed to suspend display audio").

V2: limit this for BACO and mode1 reset only

Change-Id: I33d85e6fcad1882eb33f9cde8916d57be8d5a87a
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 70 ++
 1 file changed, 70 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 2d4b78d96426..70f43b1aed78 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -69,6 +69,7 @@
 
 #include 
 #include 
+#include 
 
 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/vega12_gpu_info.bin");
@@ -4146,6 +4147,59 @@ static void amdgpu_device_unlock_adev(struct 
amdgpu_device *adev)
mutex_unlock(&adev->lock_reset);
 }
 
+static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
+{
+   struct pci_dev *p = NULL;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (p) {
+   pm_runtime_enable(&(p->dev));
+   pm_runtime_resume(&(p->dev));
+   }
+}
+
+static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
+{
+   enum amd_reset_method reset_method;
+   struct pci_dev *p = NULL;
+   unsigned long end_jiffies;
+
+   /*
+* For now, only BACO and mode1 reset are confirmed
+* to suffer the audio issue without proper suspended.
+*/
+   reset_method = amdgpu_asic_reset_method(adev);
+   if ((reset_method != AMD_RESET_METHOD_BACO) &&
+(reset_method != AMD_RESET_METHOD_MODE1))
+   return -EINVAL;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (!p)
+   return -ENODEV;
+
+   /*
+* 3S is the audio controller default autosuspend delay setting.
+* 4S used here is guaranteed to cover that.
+*/
+   end_jiffies = msecs_to_jiffies(4000) + jiffies;
+   while (!pm_runtime_status_suspended(&(p->dev))) {
+   if (!pm_runtime_suspend(&(p->dev)))
+   break;
+
+   if (time_after(jiffies, end_jiffies)) {
+   dev_warn(adev->dev, "failed to suspend display 
audio\n");
+   /* TODO: abort the succeeding gpu reset? */
+   return -ETIMEDOUT;
+   }
+   }
+
+   pm_runtime_disable(&(p->dev));
+
+   return 0;
+}
+
 /**
  * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  *
@@ -4170,6 +4224,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
bool use_baco =
(amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) ?
true : false;
+   bool audio_suspended = false;
 
/*
 * Flush RAM to disk so that after reboot
@@ -4227,6 +4282,19 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
return 0;
}
 
+   /*
+* Try to put the audio codec into suspend state
+* before gpu reset started.
+*
+* Due to the power domain of the graphics device
+* is shared with AZ power domain. Without this,
+* we may change the audio hardware from behind
+* the audio driver's back. That will trigger
+* some audio codec errors.
+*/
+   if (!amdgpu_device_suspend_display_audio(tmp_adev))
+   audio_suspended = true;
+
amdgpu_ras_set_error_query_ready(tmp_adev, false);
 
cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
@@ -4339,6 +4407,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
/*unlock kfd: SRIOV would do it separately */
if (!(in_ras_intr && !use_baco) && !amdgpu_sriov_vf(tmp_adev))
amdgpu_amdkfd_post_reset(tmp_adev);
+   if (audio_suspended)
+   amdgpu_device_resume_display_audio(tmp_adev);
amdgpu_device_unlock_adev(tmp_adev);
}
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amdgpu: move kfd suspend after ip_suspend_phase1

2020-04-24 Thread Evan Quan
This sequence change should be safe as what did in ip_suspend_phase1
is to suspend DCE only. And this is a prerequisite for coming
redundant cg/pg ungate dropping.

Change-Id: Ie125e234f8f743d327cf8e0389e4872a312184c0
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 8eb339aff14d..08eeb0d2c149 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3456,12 +3456,12 @@ int amdgpu_device_suspend(struct drm_device *dev, bool 
fbcon)
amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
 
-   amdgpu_amdkfd_suspend(adev, !fbcon);
-
amdgpu_ras_suspend(adev);
 
r = amdgpu_device_ip_suspend_phase1(adev);
 
+   amdgpu_amdkfd_suspend(adev, !fbcon);
+
/* evict vram memory */
amdgpu_bo_evict_vram(adev);
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drma/dmgpu: drop redundant cg/pg ungate on runpm enter

2020-04-24 Thread Evan Quan
CG/PG ungate is already performed in ip_suspend_phase1. Otherwise,
the CG/PG ungate will be performed twice. That will cause gfxoff
disablement is performed twice also on runpm enter while gfxoff
enablemnt once on rump exit. That will put gfxoff into disabled
state.

Change-Id: I489ca456770d3fe482b685f132400202467f712b
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 08eeb0d2c149..71278942f9f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3453,9 +3453,6 @@ int amdgpu_device_suspend(struct drm_device *dev, bool 
fbcon)
}
}
 
-   amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE);
-   amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE);
-
amdgpu_ras_suspend(adev);
 
r = amdgpu_device_ip_suspend_phase1(adev);
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: address the static checker warnings

2020-04-24 Thread Evan Quan
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4199 amdgpu_device_gpu_recover()
error: we previously assumed 'hive' could be null (see line 4196)

This is introduced by "drm/amdgpu: optimize the gpu reset for XGMI setup V2".

Change-Id: I9c22b57abc9f512114112f93fb035f1fecf26beb
Signed-off-by: Evan Quan 
Reported-by: Dan Carpenter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 71278942f9f0..898338dc9605 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4274,7 +4274,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
if (!amdgpu_device_lock_adev(tmp_adev, !hive)) {
DRM_INFO("Bailing on TDR for s_job:%llx, as another 
already in progress",
  job ? job->base.id : -1);
-   mutex_unlock(&hive->hive_lock);
+   if (hive)
+   mutex_unlock(&hive->hive_lock);
return 0;
}
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: address the static checker warnings V2

2020-04-28 Thread Evan Quan
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4199 amdgpu_device_gpu_recover()
error: we previously assumed 'hive' could be null (see line 4196)

This is introduced by "drm/amdgpu: optimize the gpu reset for XGMI setup V2".

V2: drop this mutex release needed for XGMI since XGMI never fails on
this

Change-Id: I9c22b57abc9f512114112f93fb035f1fecf26beb
Signed-off-by: Evan Quan 
Reported-by: Dan Carpenter 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 71278942f9f0..900c636c64be 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4274,7 +4274,6 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
if (!amdgpu_device_lock_adev(tmp_adev, !hive)) {
DRM_INFO("Bailing on TDR for s_job:%llx, as another 
already in progress",
  job ? job->base.id : -1);
-   mutex_unlock(&hive->hive_lock);
return 0;
}
 
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: put the audio codec into suspend state before gpu reset V3

2020-04-28 Thread Evan Quan
At default, the autosuspend delay of audio controller is 3S. If the
gpu reset is triggered within 3S(after audio controller idle),
the audio controller may be unable into suspended state. Then
the sudden gpu reset will cause some audio errors. The change
here is targeted to resolve this.

However if the audio controller is in use when the gpu reset
triggered, this change may be still not enough to put the
audio controller into suspend state. Under this case, the
gpu reset will still proceed but there will be a warning
message printed("failed to suspend display audio").

V2: limit this for BACO and mode1 reset only
V3: try 1st to use pm_runtime_autosuspend_expiration() to
query how much time is left. Use default setting on
failure

Change-Id: I33d85e6fcad1882eb33f9cde8916d57be8d5a87a
Signed-off-by: Evan Quan 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 75 ++
 1 file changed, 75 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index fb4ed0284f12..0a47e60e3c4a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -69,6 +69,7 @@
 
 #include 
 #include 
+#include 
 
 MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
 MODULE_FIRMWARE("amdgpu/vega12_gpu_info.bin");
@@ -4145,6 +4146,64 @@ static void amdgpu_device_unlock_adev(struct 
amdgpu_device *adev)
mutex_unlock(&adev->lock_reset);
 }
 
+static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
+{
+   struct pci_dev *p = NULL;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (p) {
+   pm_runtime_enable(&(p->dev));
+   pm_runtime_resume(&(p->dev));
+   }
+}
+
+static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
+{
+   enum amd_reset_method reset_method;
+   struct pci_dev *p = NULL;
+   u64 expires;
+
+   /*
+* For now, only BACO and mode1 reset are confirmed
+* to suffer the audio issue without proper suspended.
+*/
+   reset_method = amdgpu_asic_reset_method(adev);
+   if ((reset_method != AMD_RESET_METHOD_BACO) &&
+(reset_method != AMD_RESET_METHOD_MODE1))
+   return -EINVAL;
+
+   p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus),
+   adev->pdev->bus->number, 1);
+   if (!p)
+   return -ENODEV;
+
+   expires = pm_runtime_autosuspend_expiration(&(p->dev));
+   if (!expires)
+   /*
+* If we cannot get the audio device autosuspend delay,
+* a fixed 4S interval will be used. Considering 3S is
+* the audio controller default autosuspend delay setting.
+* 4S used here is guaranteed to cover that.
+*/
+   expires = ktime_get_mono_fast_ns() + NSEC_PER_SEC * 4L;
+
+   while (!pm_runtime_status_suspended(&(p->dev))) {
+   if (!pm_runtime_suspend(&(p->dev)))
+   break;
+
+   if (expires < ktime_get_mono_fast_ns()) {
+   dev_warn(adev->dev, "failed to suspend display 
audio\n");
+   /* TODO: abort the succeeding gpu reset? */
+   return -ETIMEDOUT;
+   }
+   }
+
+   pm_runtime_disable(&(p->dev));
+
+   return 0;
+}
+
 /**
  * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  *
@@ -4169,6 +4228,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
bool use_baco =
(amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) ?
true : false;
+   bool audio_suspended = false;
 
/*
 * Flush RAM to disk so that after reboot
@@ -4226,6 +4286,19 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
return 0;
}
 
+   /*
+* Try to put the audio codec into suspend state
+* before gpu reset started.
+*
+* Due to the power domain of the graphics device
+* is shared with AZ power domain. Without this,
+* we may change the audio hardware from behind
+* the audio driver's back. That will trigger
+* some audio codec errors.
+*/
+   if (!amdgpu_device_suspend_display_audio(tmp_adev))
+   audio_suspended = true;
+
amdgpu_ras_set_error_query_ready(tmp_adev, false);
 
cancel_delayed_work_sync(&tmp_adev->delayed_init_work);
@@ -4338,6 +4411,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device 

[PATCH 3/3] drm/amd/powerplay: perform PG ungate prior to CG ungate

2020-04-29 Thread Evan Quan
Since gfxoff should be disabled first before trying to access those
GC registers.

Change-Id: I5bf0fbe01fa05c89bbb392ef40e11c07edfee039
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 6 +++---
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c| 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c 
b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index fdff3e1c5e95..96c91bb70df5 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -322,12 +322,12 @@ static void pp_dpm_en_umd_pstate(struct pp_hwmgr  *hwmgr,
if (*level & profile_mode_mask) {
hwmgr->saved_dpm_level = hwmgr->dpm_level;
hwmgr->en_umd_pstate = true;
-   amdgpu_device_ip_set_clockgating_state(hwmgr->adev,
-   AMD_IP_BLOCK_TYPE_GFX,
-   AMD_CG_STATE_UNGATE);
amdgpu_device_ip_set_powergating_state(hwmgr->adev,
AMD_IP_BLOCK_TYPE_GFX,
AMD_PG_STATE_UNGATE);
+   amdgpu_device_ip_set_clockgating_state(hwmgr->adev,
+   AMD_IP_BLOCK_TYPE_GFX,
+   AMD_CG_STATE_UNGATE);
}
} else {
/* exit umd pstate, restore level, enable gfx cg*/
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 12810fd81d5d..e6252bcaa641 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -1780,12 +1780,12 @@ static int smu_enable_umd_pstate(void *handle,
if (*level & profile_mode_mask) {
smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level;
smu_dpm_ctx->enable_umd_pstate = true;
-   amdgpu_device_ip_set_clockgating_state(smu->adev,
-  
AMD_IP_BLOCK_TYPE_GFX,
-  
AMD_CG_STATE_UNGATE);
amdgpu_device_ip_set_powergating_state(smu->adev,
   
AMD_IP_BLOCK_TYPE_GFX,
   
AMD_PG_STATE_UNGATE);
+   amdgpu_device_ip_set_clockgating_state(smu->adev,
+  
AMD_IP_BLOCK_TYPE_GFX,
+  
AMD_CG_STATE_UNGATE);
}
} else {
/* exit umd pstate, restore level, enable gfx cg*/
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/3] drm/amdgpu: drop unnecessary cancel_delayed_work_sync on PG ungate

2020-04-29 Thread Evan Quan
As this is already properly handled in amdgpu_gfx_off_ctrl(). In fact,
this unnecessary cancel_delayed_work_sync may leave a small time window
for race condition and is dangerous.

Change-Id: I601b7b86850db3ed4f4990fd796de663401451ca
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c |  6 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  | 12 +++-
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 5519f31b2c00..53c47353c7ee 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -7108,11 +7108,7 @@ static int gfx_v10_0_set_powergating_state(void *handle,
case CHIP_NAVI10:
case CHIP_NAVI12:
case CHIP_NAVI14:
-   if (!enable) {
-   amdgpu_gfx_off_ctrl(adev, false);
-   cancel_delayed_work_sync(&adev->gfx.gfx_off_delay_work);
-   } else
-   amdgpu_gfx_off_ctrl(adev, true);
+   amdgpu_gfx_off_ctrl(adev, enable);
break;
default:
break;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index d89359485997..384ebabf8605 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -5031,10 +5031,9 @@ static int gfx_v9_0_set_powergating_state(void *handle,
switch (adev->asic_type) {
case CHIP_RAVEN:
case CHIP_RENOIR:
-   if (!enable) {
+   if (!enable)
amdgpu_gfx_off_ctrl(adev, false);
-   cancel_delayed_work_sync(&adev->gfx.gfx_off_delay_work);
-   }
+
if (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS) {
gfx_v9_0_enable_sck_slow_down_on_power_up(adev, true);
gfx_v9_0_enable_sck_slow_down_on_power_down(adev, true);
@@ -5058,12 +5057,7 @@ static int gfx_v9_0_set_powergating_state(void *handle,
amdgpu_gfx_off_ctrl(adev, true);
break;
case CHIP_VEGA12:
-   if (!enable) {
-   amdgpu_gfx_off_ctrl(adev, false);
-   cancel_delayed_work_sync(&adev->gfx.gfx_off_delay_work);
-   } else {
-   amdgpu_gfx_off_ctrl(adev, true);
-   }
+   amdgpu_gfx_off_ctrl(adev, enable);
break;
default:
break;
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/3] drm/amdgpu: disable MGCG/MGLS also on gfx CG ungate

2020-04-29 Thread Evan Quan
Otherwise, MGCG/MGLS will be left enabled.

Change-Id: I620c5a58b814ae4a0f6005bbc467d7cc2b6d0d66
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index f059c1c546ec..5519f31b2c00 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -7027,7 +7027,7 @@ static int gfx_v10_0_update_gfx_clock_gating(struct 
amdgpu_device *adev,
/* ===  CGCG /CGLS for GFX 3D Only === */
gfx_v10_0_update_3d_clock_gating(adev, enable);
/* ===  MGCG + MGLS === */
-   /* gfx_v10_0_update_medium_grain_clock_gating(adev, enable); */
+   gfx_v10_0_update_medium_grain_clock_gating(adev, enable);
}
 
if (adev->cg_flags &
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amdgpu: enable hibernate support on Navi1X

2020-05-07 Thread Evan Quan
BACO is needed to support hibernate on Navi1X.

Change-Id: Ia283612919e9a5b4e1e198ab2cc0bc15f7f94760
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h| 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c| 2 ++
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 5bd213f88ae5..e649a3d3fd7c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1010,6 +1010,7 @@ struct amdgpu_device {
 
/* s3/s4 mask */
boolin_suspend;
+   boolin_hibernate;
 
boolin_gpu_reset;
enum pp_mp1_state   mp1_state;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index eb351844e46c..5eaa5ea83d0c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1260,7 +1260,9 @@ static int amdgpu_pmops_freeze(struct device *dev)
struct amdgpu_device *adev = drm_dev->dev_private;
int r;
 
+   adev->in_hibernate = true;
r = amdgpu_device_suspend(drm_dev, true);
+   adev->in_hibernate = false;
if (r)
return r;
return amdgpu_asic_reset(adev);
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c 
b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
index 8a0c37dc5182..f1621147db61 100644
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
@@ -1500,7 +1500,7 @@ static int smu_disable_dpm(struct smu_context *smu)
bool use_baco = !smu->is_apu &&
((adev->in_gpu_reset &&
  (amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO)) ||
-(adev->in_runpm && amdgpu_asic_supports_baco(adev)));
+((adev->in_runpm || adev->in_hibernate) && 
amdgpu_asic_supports_baco(adev)));
 
ret = smu_get_smc_version(smu, NULL, &smu_version);
if (ret) {
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 1/2] drm/amdgpu: decode the ctxid for SMC to host IH

2020-05-08 Thread Evan Quan
Driver needs that to tell the different events raised from SMC.

Change-Id: I0e44e22527182fbb45a2db4fc3b1cd73fb17ba33
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h | 1 +
 drivers/gpu/drm/amd/amdgpu/navi10_ih.c  | 1 +
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c  | 1 +
 3 files changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h
index 7b1762b1c595..965875b8bf93 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h
@@ -55,6 +55,7 @@ struct amdgpu_iv_entry {
unsigned timestamp_src;
unsigned pasid;
unsigned pasid_src;
+   unsigned ctxid; /* for SMC to Host interrupt */
unsigned src_data[AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW];
const uint32_t *iv_entry;
 };
diff --git a/drivers/gpu/drm/amd/amdgpu/navi10_ih.c 
b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c
index f97857ed3c7e..932dc3eabbe2 100644
--- a/drivers/gpu/drm/amd/amdgpu/navi10_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/navi10_ih.c
@@ -470,6 +470,7 @@ static void navi10_ih_decode_iv(struct amdgpu_device *adev,
entry->timestamp_src = dw[2] >> 31;
entry->pasid = dw[3] & 0x;
entry->pasid_src = dw[3] >> 31;
+   entry->ctxid = dw[4];
entry->src_data[0] = dw[4];
entry->src_data[1] = dw[5];
entry->src_data[2] = dw[6];
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_ih.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
index 407c6093c2ec..e46d1f9f62ca 100644
--- a/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
@@ -460,6 +460,7 @@ static void vega10_ih_decode_iv(struct amdgpu_device *adev,
entry->timestamp_src = dw[2] >> 31;
entry->pasid = dw[3] & 0x;
entry->pasid_src = dw[3] >> 31;
+   entry->ctxid = dw[4];
entry->src_data[0] = dw[4];
entry->src_data[1] = dw[5];
entry->src_data[2] = dw[6];
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH 2/2] drm/amd/powerplay: report correct AC/DC event based on ctxid

2020-05-08 Thread Evan Quan
'ctxid' is used to distinguish different events raised from SMC.
0x3 and 0x4 are for AC and DC power mode.

Change-Id: I7dbcb053fe9cea7c70e0a33afc2115b3745f6186
Signed-off-by: Evan Quan 
---
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c 
b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index ab727f33b8d9..dcd3a54d18a3 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -1522,6 +1522,7 @@ static int smu_v11_0_irq_process(struct amdgpu_device 
*adev,
 {
uint32_t client_id = entry->client_id;
uint32_t src_id = entry->src_id;
+   uint32_t ctxid = entry->ctxid;
 
if (client_id == SOC15_IH_CLIENTID_THM) {
switch (src_id) {
@@ -1547,8 +1548,18 @@ static int smu_v11_0_irq_process(struct amdgpu_device 
*adev,
 
}
} else if (client_id == SOC15_IH_CLIENTID_MP1) {
-   if (src_id == 0xfe)
-   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   if (src_id == 0xfe) {
+   switch (ctxid) {
+   case 0x3:
+   dev_info(adev->dev, "Switched to AC mode!\n");
+   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   break;
+   case 0x4:
+   dev_info(adev->dev, "Switched to DC mode!\n");
+   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   break;
+   }
+   }
}
 
return 0;
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


[PATCH] drm/amd/powerplay: report correct AC/DC event based on ctxid V2

2020-05-08 Thread Evan Quan
'ctxid' is used to distinguish different events raised from SMC.
0x3 and 0x4 are for AC and DC power mode.

V2: update the way to retrieve the ctxid and change the log level
to debug

Change-Id: I7dbcb053fe9cea7c70e0a33afc2115b3745f6186
Signed-off-by: Evan Quan 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c 
b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index ab727f33b8d9..5792b224b0c3 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -1522,6 +1522,11 @@ static int smu_v11_0_irq_process(struct amdgpu_device 
*adev,
 {
uint32_t client_id = entry->client_id;
uint32_t src_id = entry->src_id;
+   /*
+* ctxid is used to distinguish different
+* events for SMCToHost interrupt.
+*/
+   uint32_t ctxid = entry->src_data[0];
 
if (client_id == SOC15_IH_CLIENTID_THM) {
switch (src_id) {
@@ -1547,8 +1552,18 @@ static int smu_v11_0_irq_process(struct amdgpu_device 
*adev,
 
}
} else if (client_id == SOC15_IH_CLIENTID_MP1) {
-   if (src_id == 0xfe)
-   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   if (src_id == 0xfe) {
+   switch (ctxid) {
+   case 0x3:
+   dev_dbg(adev->dev, "Switched to AC mode!\n");
+   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   break;
+   case 0x4:
+   dev_dbg(adev->dev, "Switched to DC mode!\n");
+   smu_v11_0_ack_ac_dc_interrupt(&adev->smu);
+   break;
+   }
+   }
}
 
return 0;
-- 
2.26.2

___
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx


<    5   6   7   8   9   10   11   12   13   >