<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi Alex,</p>
<p><br>
</p>
<p>Would you prefer I re-write #1 to avoid churn in the tree?</p>
<p><br>
</p>
<p>Cheers,</p>
<p>Tom</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Alex Deucher <alexdeucher@gmail.com><br>
<b>Sent:</b> Monday, September 19, 2016 11:53<br>
<b>To:</b> Tom St Denis<br>
<b>Cc:</b> amd-gfx list; StDenis, Tom<br>
<b>Subject:</b> Re: [PATCH 1/2] drm/amd/powerplay: Add read_sensor() callback to hwmgr (v3)</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On Mon, Sep 19, 2016 at 9:10 AM, Tom St Denis <tstdenis82@gmail.com> wrote:<br>
> Provides standardized interface to read various sensors.<br>
> The API is extensible (by adding to the end of the<br>
> amd_pp_sensors enumeration list.<br>
><br>
> Support has been added to Carrizo/smu7<br>
><br>
> (v2) Squashed the two sensor patches into one.<br>
> (v3) Updated to apply to smu7_hwmgr instead<br>
><br>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
> ---<br>
>  drivers/gpu/drm/amd/powerplay/amd_powerplay.c     | 20 +++++<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c    | 96 +++++++++++++++++++++++<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c  | 36 +++++++++<br>
>  drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h | 12 +++<br>
>  drivers/gpu/drm/amd/powerplay/inc/hwmgr.h         |  1 +<br>
>  5 files changed, 165 insertions(+)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
> index b1d19409bf86..ee0368381e82 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
> @@ -894,6 +894,25 @@ static int pp_dpm_set_mclk_od(void *handle, uint32_t value)<br>
>         return hwmgr->hwmgr_func->set_mclk_od(hwmgr, value);<br>
>  }<br>
><br>
> +static int pp_dpm_read_sensor(void *handle, int idx, int32_t *value)<br>
> +{<br>
> +       struct pp_hwmgr *hwmgr;<br>
> +<br>
> +       if (!handle)<br>
> +               return -EINVAL;<br>
> +<br>
> +       hwmgr = ((struct pp_instance *)handle)->hwmgr;<br>
> +<br>
> +       PP_CHECK_HW(hwmgr);<br>
> +<br>
> +       if (hwmgr->hwmgr_func->read_sensor == NULL) {<br>
> +               printk(KERN_INFO "%s was not implemented.\n", __func__);<br>
> +               return 0;<br>
> +       }<br>
> +<br>
> +       return hwmgr->hwmgr_func->read_sensor(hwmgr, idx, value);<br>
> +}<br>
> +<br>
>  const struct amd_powerplay_funcs pp_dpm_funcs = {<br>
>         .get_temperature = pp_dpm_get_temperature,<br>
>         .load_firmware = pp_dpm_load_fw,<br>
> @@ -920,6 +939,7 @@ const struct amd_powerplay_funcs pp_dpm_funcs = {<br>
>         .set_sclk_od = pp_dpm_set_sclk_od,<br>
>         .get_mclk_od = pp_dpm_get_mclk_od,<br>
>         .set_mclk_od = pp_dpm_set_mclk_od,<br>
> +       .read_sensor = pp_dpm_read_sensor,<br>
<br>
As a future patch it would be nice to hook up this sensor interface to<br>
the existing amdgpu_pm_info code and make that asic indpendent.<br>
<br>
Series is:<br>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
<br>
Alex<br>
<br>
<br>
>  };<br>
><br>
>  static int amd_pp_instance_init(struct amd_pp_init *pp_init,<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> index 5ecef1732e20..9f3c5a8a903c 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> @@ -1857,6 +1857,101 @@ static int cz_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_c<br>
>         return 0;<br>
>  }<br>
><br>
> +static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value)<br>
> +{<br>
> +       struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);<br>
> +<br>
> +       struct phm_clock_voltage_dependency_table *table =<br>
> +                               hwmgr->dyn_state.vddc_dependency_on_sclk;<br>
> +<br>
> +       struct phm_vce_clock_voltage_dependency_table *vce_table =<br>
> +               hwmgr->dyn_state.vce_clock_voltage_dependency_table;<br>
> +<br>
> +       struct phm_uvd_clock_voltage_dependency_table *uvd_table =<br>
> +               hwmgr->dyn_state.uvd_clock_voltage_dependency_table;<br>
> +<br>
> +       uint32_t sclk_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX),<br>
> +                                       TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX);<br>
> +       uint32_t uvd_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),<br>
> +                                       TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_UVD_INDEX);<br>
> +       uint32_t vce_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),<br>
> +                                       TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_VCE_INDEX);<br>
> +<br>
> +       uint32_t sclk, vclk, dclk, ecclk, tmp, activity_percent;<br>
> +       uint16_t vddnb, vddgfx;<br>
> +       int result;<br>
> +<br>
> +       switch (idx) {<br>
> +       case AMDGPU_PP_SENSOR_GFX_SCLK:<br>
> +               if (sclk_index < NUM_SCLK_LEVELS) {<br>
> +                       sclk = table->entries[sclk_index].clk;<br>
> +                       *value = sclk;<br>
> +                       return 0;<br>
> +               }<br>
> +               return -EINVAL;<br>
> +       case AMDGPU_PP_SENSOR_VDDNB:<br>
> +               tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_NB_CURRENTVID) &<br>
> +                       CURRENT_NB_VID_MASK) >> CURRENT_NB_VID__SHIFT;<br>
> +               vddnb = cz_convert_8Bit_index_to_voltage(hwmgr, tmp);<br>
> +               *value = vddnb;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_VDDGFX:<br>
> +               tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_GFX_CURRENTVID) &<br>
> +                       CURRENT_GFX_VID_MASK) >> CURRENT_GFX_VID__SHIFT;<br>
> +               vddgfx = cz_convert_8Bit_index_to_voltage(hwmgr, (u16)tmp);<br>
> +               *value = vddgfx;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_UVD_VCLK:<br>
> +               if (!cz_hwmgr->uvd_power_gated) {<br>
> +                       if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {<br>
> +                               return -EINVAL;<br>
> +                       } else {<br>
> +                               vclk = uvd_table->entries[uvd_index].vclk;<br>
> +                               *value = vclk;<br>
> +                               return 0;<br>
> +                       }<br>
> +               }<br>
> +               *value = 0;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_UVD_DCLK:<br>
> +               if (!cz_hwmgr->uvd_power_gated) {<br>
> +                       if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {<br>
> +                               return -EINVAL;<br>
> +                       } else {<br>
> +                               dclk = uvd_table->entries[uvd_index].dclk;<br>
> +                               *value = dclk;<br>
> +                               return 0;<br>
> +                       }<br>
> +               }<br>
> +               *value = 0;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_VCE_ECCLK:<br>
> +               if (!cz_hwmgr->vce_power_gated) {<br>
> +                       if (vce_index >= CZ_MAX_HARDWARE_POWERLEVELS) {<br>
> +                               return -EINVAL;<br>
> +                       } else {<br>
> +                               ecclk = vce_table->entries[vce_index].ecclk;<br>
> +                               *value = ecclk;<br>
> +                               return 0;<br>
> +                       }<br>
> +               }<br>
> +               *value = 0;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_GPU_LOAD:<br>
> +               result = smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetAverageGraphicsActivity);<br>
> +               if (0 == result) {<br>
> +                       activity_percent = cgs_read_register(hwmgr->device, mmSMU_MP1_SRBM2P_ARG_0);<br>
> +                       activity_percent = activity_percent > 100 ? 100 : activity_percent;<br>
> +               } else {<br>
> +                       activity_percent = 50;<br>
> +               }<br>
> +               *value = activity_percent;<br>
> +               return 0;<br>
> +       default:<br>
> +               return -EINVAL;<br>
> +       }<br>
> +}<br>
> +<br>
>  static const struct pp_hwmgr_func cz_hwmgr_funcs = {<br>
>         .backend_init = cz_hwmgr_backend_init,<br>
>         .backend_fini = cz_hwmgr_backend_fini,<br>
> @@ -1882,6 +1977,7 @@ static const struct pp_hwmgr_func cz_hwmgr_funcs = {<br>
>         .get_current_shallow_sleep_clocks = cz_get_current_shallow_sleep_clocks,<br>
>         .get_clock_by_type = cz_get_clock_by_type,<br>
>         .get_max_high_clocks = cz_get_max_high_clocks,<br>
> +       .read_sensor = cz_read_sensor,<br>
>  };<br>
><br>
>  int cz_hwmgr_init(struct pp_hwmgr *hwmgr)<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> index f67e1e260b30..07a7d046d6f6 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c<br>
> @@ -3144,6 +3144,41 @@ smu7_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)<br>
>         seq_printf(m, "vce    %sabled\n", data->vce_power_gated ? "dis" : "en");<br>
>  }<br>
><br>
> +static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value)<br>
> +{<br>
> +       uint32_t sclk, mclk, activity_percent;<br>
> +       uint32_t offset;<br>
> +       struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);<br>
> +<br>
> +       switch (idx) {<br>
> +       case AMDGPU_PP_SENSOR_GFX_SCLK:<br>
> +               smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetSclkFrequency);<br>
> +               sclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);<br>
> +               *value = sclk;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_GFX_MCLK:<br>
> +               smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_API_GetMclkFrequency);<br>
> +               mclk = cgs_read_register(hwmgr->device, mmSMC_MSG_ARG_0);<br>
> +               *value = mclk;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_GPU_LOAD:<br>
> +               offset = data->soft_regs_start + smum_get_offsetof(hwmgr->smumgr,<br>
> +                                                               SMU_SoftRegisters,<br>
> +                                                               AverageGraphicsActivity);<br>
> +<br>
> +               activity_percent = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, offset);<br>
> +               activity_percent += 0x80;<br>
> +               activity_percent >>= 8;<br>
> +               *value = activity_percent > 100 ? 100 : activity_percent;<br>
> +               return 0;<br>
> +       case AMDGPU_PP_SENSOR_GPU_TEMP:<br>
> +               *value = smu7_thermal_get_temperature(hwmgr);<br>
> +               return 0;<br>
> +       default:<br>
> +               return -EINVAL;<br>
> +       }<br>
> +}<br>
> +<br>
>  static int smu7_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)<br>
>  {<br>
>         const struct phm_set_power_state_input *states =<br>
> @@ -4315,6 +4350,7 @@ static struct pp_hwmgr_func smu7_hwmgr_funcs = {<br>
>         .get_mclk_od = smu7_get_mclk_od,<br>
>         .set_mclk_od = smu7_set_mclk_od,<br>
>         .get_clock_by_type = smu7_get_clock_by_type,<br>
> +       .read_sensor = smu7_read_sensor,<br>
>  };<br>
><br>
>  uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h b/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h<br>
> index f941acf563a9..dfa0f38a5e76 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h<br>
> +++ b/drivers/gpu/drm/amd/powerplay/inc/amd_powerplay.h<br>
> @@ -29,6 +29,17 @@<br>
>  #include "amd_shared.h"<br>
>  #include "cgs_common.h"<br>
><br>
> +enum amd_pp_sensors {<br>
> +       AMDGPU_PP_SENSOR_GFX_SCLK = 0,<br>
> +       AMDGPU_PP_SENSOR_VDDNB,<br>
> +       AMDGPU_PP_SENSOR_VDDGFX,<br>
> +       AMDGPU_PP_SENSOR_UVD_VCLK,<br>
> +       AMDGPU_PP_SENSOR_UVD_DCLK,<br>
> +       AMDGPU_PP_SENSOR_VCE_ECCLK,<br>
> +       AMDGPU_PP_SENSOR_GPU_LOAD,<br>
> +       AMDGPU_PP_SENSOR_GFX_MCLK,<br>
> +       AMDGPU_PP_SENSOR_GPU_TEMP,<br>
> +};<br>
><br>
>  enum amd_pp_event {<br>
>         AMD_PP_EVENT_INITIALIZE = 0,<br>
> @@ -347,6 +358,7 @@ struct amd_powerplay_funcs {<br>
>         int (*set_sclk_od)(void *handle, uint32_t value);<br>
>         int (*get_mclk_od)(void *handle);<br>
>         int (*set_mclk_od)(void *handle, uint32_t value);<br>
> +       int (*read_sensor)(void *handle, int idx, int32_t *value);<br>
>  };<br>
><br>
>  struct amd_powerplay {<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
> index c9628b4db2c3..fcd45452380d 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
> +++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
> @@ -359,6 +359,7 @@ struct pp_hwmgr_func {<br>
>         int (*set_sclk_od)(struct pp_hwmgr *hwmgr, uint32_t value);<br>
>         int (*get_mclk_od)(struct pp_hwmgr *hwmgr);<br>
>         int (*set_mclk_od)(struct pp_hwmgr *hwmgr, uint32_t value);<br>
> +       int (*read_sensor)(struct pp_hwmgr *hwmgr, int idx, int32_t *value);<br>
>  };<br>
><br>
>  struct pp_table_func {<br>
> --<br>
> 2.10.0<br>
><br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> amd-gfx@lists.freedesktop.org<br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" id="LPlnk724524">
https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
<div id="LPBorder_GT_14743004775210.15276233173698328" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_14743004775190.49899342106105293" cellspacing="0" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td id="TextCell_14743004775200.7956016082987132" colspan="2" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;">
<div id="LPRemovePreviewContainer_14743004775200.6248479015358717"></div>
<div id="LPTitle_14743004775200.21508066420594152" style="top: 0px; color: rgb(59, 87, 119); font-weight: normal; font-size: 21px; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_14743004775200.7167293884594854" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" target="_blank" style="text-decoration: none;">amd-gfx Info Page - lists.freedesktop.org</a></div>
<div id="LPMetadata_14743004775200.2972104013311352" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: normal; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
lists.freedesktop.org</div>
<div id="LPDescription_14743004775200.9065864460282174" style="display: block; color: rgb(102, 102, 102); font-weight: normal; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
To see the collection of prior postings to the list, visit the amd-gfx Archives. Using amd-gfx: To post a message to all the list members, send email ...</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>