1 /*
2 * Copyright 2017 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
24 #include <linux/delay.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
27
28 #include "hwmgr.h"
29 #include "amd_powerplay.h"
30 #include "vega12_smumgr.h"
31 #include "hardwaremanager.h"
32 #include "ppatomfwctrl.h"
33 #include "atomfirmware.h"
34 #include "cgs_common.h"
35 #include "vega12_inc.h"
36 #include "pppcielanes.h"
37 #include "vega12_hwmgr.h"
38 #include "vega12_processpptables.h"
39 #include "vega12_pptable.h"
40 #include "vega12_thermal.h"
41 #include "vega12_ppsmc.h"
42 #include "pp_debug.h"
43 #include "amd_pcie_helpers.h"
44 #include "ppinterrupt.h"
45 #include "pp_overdriver.h"
46 #include "pp_thermal.h"
47 #include "vega12_baco.h"
48
49 #define smnPCIE_LC_SPEED_CNTL 0x11140290
50 #define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
51
52 #define LINK_WIDTH_MAX 6
53 #define LINK_SPEED_MAX 3
54 static const int link_width[] = {0, 1, 2, 4, 8, 12, 16};
55 static const int link_speed[] = {25, 50, 80, 160};
56
57 static int vega12_force_clock_level(struct pp_hwmgr *hwmgr,
58 enum pp_clock_type type, uint32_t mask);
59 static int vega12_get_clock_ranges(struct pp_hwmgr *hwmgr,
60 uint32_t *clock,
61 PPCLK_e clock_select,
62 bool max);
63
vega12_set_default_registry_data(struct pp_hwmgr * hwmgr)64 static void vega12_set_default_registry_data(struct pp_hwmgr *hwmgr)
65 {
66 struct vega12_hwmgr *data =
67 (struct vega12_hwmgr *)(hwmgr->backend);
68
69 data->gfxclk_average_alpha = PPVEGA12_VEGA12GFXCLKAVERAGEALPHA_DFLT;
70 data->socclk_average_alpha = PPVEGA12_VEGA12SOCCLKAVERAGEALPHA_DFLT;
71 data->uclk_average_alpha = PPVEGA12_VEGA12UCLKCLKAVERAGEALPHA_DFLT;
72 data->gfx_activity_average_alpha = PPVEGA12_VEGA12GFXACTIVITYAVERAGEALPHA_DFLT;
73 data->lowest_uclk_reserved_for_ulv = PPVEGA12_VEGA12LOWESTUCLKRESERVEDFORULV_DFLT;
74
75 data->display_voltage_mode = PPVEGA12_VEGA12DISPLAYVOLTAGEMODE_DFLT;
76 data->dcef_clk_quad_eqn_a = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
77 data->dcef_clk_quad_eqn_b = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
78 data->dcef_clk_quad_eqn_c = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
79 data->disp_clk_quad_eqn_a = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
80 data->disp_clk_quad_eqn_b = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
81 data->disp_clk_quad_eqn_c = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
82 data->pixel_clk_quad_eqn_a = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
83 data->pixel_clk_quad_eqn_b = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
84 data->pixel_clk_quad_eqn_c = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
85 data->phy_clk_quad_eqn_a = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
86 data->phy_clk_quad_eqn_b = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
87 data->phy_clk_quad_eqn_c = PPREGKEY_VEGA12QUADRATICEQUATION_DFLT;
88
89 data->registry_data.disallowed_features = 0x0;
90 data->registry_data.od_state_in_dc_support = 0;
91 data->registry_data.thermal_support = 1;
92 data->registry_data.skip_baco_hardware = 0;
93
94 data->registry_data.log_avfs_param = 0;
95 data->registry_data.sclk_throttle_low_notification = 1;
96 data->registry_data.force_dpm_high = 0;
97 data->registry_data.stable_pstate_sclk_dpm_percentage = 75;
98
99 data->registry_data.didt_support = 0;
100 if (data->registry_data.didt_support) {
101 data->registry_data.didt_mode = 6;
102 data->registry_data.sq_ramping_support = 1;
103 data->registry_data.db_ramping_support = 0;
104 data->registry_data.td_ramping_support = 0;
105 data->registry_data.tcp_ramping_support = 0;
106 data->registry_data.dbr_ramping_support = 0;
107 data->registry_data.edc_didt_support = 1;
108 data->registry_data.gc_didt_support = 0;
109 data->registry_data.psm_didt_support = 0;
110 }
111
112 data->registry_data.pcie_lane_override = 0xff;
113 data->registry_data.pcie_speed_override = 0xff;
114 data->registry_data.pcie_clock_override = 0xffffffff;
115 data->registry_data.regulator_hot_gpio_support = 1;
116 data->registry_data.ac_dc_switch_gpio_support = 0;
117 data->registry_data.quick_transition_support = 0;
118 data->registry_data.zrpm_start_temp = 0xffff;
119 data->registry_data.zrpm_stop_temp = 0xffff;
120 data->registry_data.odn_feature_enable = 1;
121 data->registry_data.disable_water_mark = 0;
122 data->registry_data.disable_pp_tuning = 0;
123 data->registry_data.disable_xlpp_tuning = 0;
124 data->registry_data.disable_workload_policy = 0;
125 data->registry_data.perf_ui_tuning_profile_turbo = 0x19190F0F;
126 data->registry_data.perf_ui_tuning_profile_powerSave = 0x19191919;
127 data->registry_data.perf_ui_tuning_profile_xl = 0x00000F0A;
128 data->registry_data.force_workload_policy_mask = 0;
129 data->registry_data.disable_3d_fs_detection = 0;
130 data->registry_data.fps_support = 1;
131 data->registry_data.disable_auto_wattman = 1;
132 data->registry_data.auto_wattman_debug = 0;
133 data->registry_data.auto_wattman_sample_period = 100;
134 data->registry_data.auto_wattman_threshold = 50;
135 data->registry_data.pcie_dpm_key_disabled = !(hwmgr->feature_mask & PP_PCIE_DPM_MASK);
136 }
137
vega12_set_features_platform_caps(struct pp_hwmgr * hwmgr)138 static int vega12_set_features_platform_caps(struct pp_hwmgr *hwmgr)
139 {
140 struct vega12_hwmgr *data =
141 (struct vega12_hwmgr *)(hwmgr->backend);
142 struct amdgpu_device *adev = hwmgr->adev;
143
144 if (data->vddci_control == VEGA12_VOLTAGE_CONTROL_NONE)
145 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
146 PHM_PlatformCaps_ControlVDDCI);
147
148 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
149 PHM_PlatformCaps_TablelessHardwareInterface);
150
151 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
152 PHM_PlatformCaps_EnableSMU7ThermalManagement);
153
154 if (adev->pg_flags & AMD_PG_SUPPORT_UVD) {
155 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
156 PHM_PlatformCaps_UVDPowerGating);
157 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
158 PHM_PlatformCaps_UVDDynamicPowerGating);
159 }
160
161 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
162 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
163 PHM_PlatformCaps_VCEPowerGating);
164
165 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
166 PHM_PlatformCaps_UnTabledHardwareInterface);
167
168 if (data->registry_data.odn_feature_enable)
169 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
170 PHM_PlatformCaps_ODNinACSupport);
171 else {
172 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
173 PHM_PlatformCaps_OD6inACSupport);
174 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
175 PHM_PlatformCaps_OD6PlusinACSupport);
176 }
177
178 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
179 PHM_PlatformCaps_ActivityReporting);
180 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
181 PHM_PlatformCaps_FanSpeedInTableIsRPM);
182
183 if (data->registry_data.od_state_in_dc_support) {
184 if (data->registry_data.odn_feature_enable)
185 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
186 PHM_PlatformCaps_ODNinDCSupport);
187 else {
188 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
189 PHM_PlatformCaps_OD6inDCSupport);
190 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
191 PHM_PlatformCaps_OD6PlusinDCSupport);
192 }
193 }
194
195 if (data->registry_data.thermal_support
196 && data->registry_data.fuzzy_fan_control_support
197 && hwmgr->thermal_controller.advanceFanControlParameters.usTMax)
198 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
199 PHM_PlatformCaps_ODFuzzyFanControlSupport);
200
201 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
202 PHM_PlatformCaps_DynamicPowerManagement);
203 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
204 PHM_PlatformCaps_SMC);
205 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
206 PHM_PlatformCaps_ThermalPolicyDelay);
207
208 if (data->registry_data.force_dpm_high)
209 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
210 PHM_PlatformCaps_ExclusiveModeAlwaysHigh);
211
212 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
213 PHM_PlatformCaps_DynamicUVDState);
214
215 if (data->registry_data.sclk_throttle_low_notification)
216 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
217 PHM_PlatformCaps_SclkThrottleLowNotification);
218
219 /* power tune caps */
220 /* assume disabled */
221 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
222 PHM_PlatformCaps_PowerContainment);
223 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
224 PHM_PlatformCaps_DiDtSupport);
225 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
226 PHM_PlatformCaps_SQRamping);
227 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
228 PHM_PlatformCaps_DBRamping);
229 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
230 PHM_PlatformCaps_TDRamping);
231 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
232 PHM_PlatformCaps_TCPRamping);
233 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
234 PHM_PlatformCaps_DBRRamping);
235 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
236 PHM_PlatformCaps_DiDtEDCEnable);
237 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
238 PHM_PlatformCaps_GCEDC);
239 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
240 PHM_PlatformCaps_PSM);
241
242 if (data->registry_data.didt_support) {
243 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtSupport);
244 if (data->registry_data.sq_ramping_support)
245 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SQRamping);
246 if (data->registry_data.db_ramping_support)
247 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRamping);
248 if (data->registry_data.td_ramping_support)
249 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TDRamping);
250 if (data->registry_data.tcp_ramping_support)
251 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TCPRamping);
252 if (data->registry_data.dbr_ramping_support)
253 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRRamping);
254 if (data->registry_data.edc_didt_support)
255 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtEDCEnable);
256 if (data->registry_data.gc_didt_support)
257 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_GCEDC);
258 if (data->registry_data.psm_didt_support)
259 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PSM);
260 }
261
262 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
263 PHM_PlatformCaps_RegulatorHot);
264
265 if (data->registry_data.ac_dc_switch_gpio_support) {
266 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
267 PHM_PlatformCaps_AutomaticDCTransition);
268 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
269 PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
270 }
271
272 if (data->registry_data.quick_transition_support) {
273 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
274 PHM_PlatformCaps_AutomaticDCTransition);
275 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
276 PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
277 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
278 PHM_PlatformCaps_Falcon_QuickTransition);
279 }
280
281 if (data->lowest_uclk_reserved_for_ulv != PPVEGA12_VEGA12LOWESTUCLKRESERVEDFORULV_DFLT) {
282 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
283 PHM_PlatformCaps_LowestUclkReservedForUlv);
284 if (data->lowest_uclk_reserved_for_ulv == 1)
285 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
286 PHM_PlatformCaps_LowestUclkReservedForUlv);
287 }
288
289 if (data->registry_data.custom_fan_support)
290 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
291 PHM_PlatformCaps_CustomFanControlSupport);
292
293 return 0;
294 }
295
vega12_init_dpm_defaults(struct pp_hwmgr * hwmgr)296 static int vega12_init_dpm_defaults(struct pp_hwmgr *hwmgr)
297 {
298 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
299 struct amdgpu_device *adev = hwmgr->adev;
300 uint32_t top32, bottom32;
301 int i, ret;
302
303 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_id =
304 FEATURE_DPM_PREFETCHER_BIT;
305 data->smu_features[GNLD_DPM_GFXCLK].smu_feature_id =
306 FEATURE_DPM_GFXCLK_BIT;
307 data->smu_features[GNLD_DPM_UCLK].smu_feature_id =
308 FEATURE_DPM_UCLK_BIT;
309 data->smu_features[GNLD_DPM_SOCCLK].smu_feature_id =
310 FEATURE_DPM_SOCCLK_BIT;
311 data->smu_features[GNLD_DPM_UVD].smu_feature_id =
312 FEATURE_DPM_UVD_BIT;
313 data->smu_features[GNLD_DPM_VCE].smu_feature_id =
314 FEATURE_DPM_VCE_BIT;
315 data->smu_features[GNLD_ULV].smu_feature_id =
316 FEATURE_ULV_BIT;
317 data->smu_features[GNLD_DPM_MP0CLK].smu_feature_id =
318 FEATURE_DPM_MP0CLK_BIT;
319 data->smu_features[GNLD_DPM_LINK].smu_feature_id =
320 FEATURE_DPM_LINK_BIT;
321 data->smu_features[GNLD_DPM_DCEFCLK].smu_feature_id =
322 FEATURE_DPM_DCEFCLK_BIT;
323 data->smu_features[GNLD_DS_GFXCLK].smu_feature_id =
324 FEATURE_DS_GFXCLK_BIT;
325 data->smu_features[GNLD_DS_SOCCLK].smu_feature_id =
326 FEATURE_DS_SOCCLK_BIT;
327 data->smu_features[GNLD_DS_LCLK].smu_feature_id =
328 FEATURE_DS_LCLK_BIT;
329 data->smu_features[GNLD_PPT].smu_feature_id =
330 FEATURE_PPT_BIT;
331 data->smu_features[GNLD_TDC].smu_feature_id =
332 FEATURE_TDC_BIT;
333 data->smu_features[GNLD_THERMAL].smu_feature_id =
334 FEATURE_THERMAL_BIT;
335 data->smu_features[GNLD_GFX_PER_CU_CG].smu_feature_id =
336 FEATURE_GFX_PER_CU_CG_BIT;
337 data->smu_features[GNLD_RM].smu_feature_id =
338 FEATURE_RM_BIT;
339 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_id =
340 FEATURE_DS_DCEFCLK_BIT;
341 data->smu_features[GNLD_ACDC].smu_feature_id =
342 FEATURE_ACDC_BIT;
343 data->smu_features[GNLD_VR0HOT].smu_feature_id =
344 FEATURE_VR0HOT_BIT;
345 data->smu_features[GNLD_VR1HOT].smu_feature_id =
346 FEATURE_VR1HOT_BIT;
347 data->smu_features[GNLD_FW_CTF].smu_feature_id =
348 FEATURE_FW_CTF_BIT;
349 data->smu_features[GNLD_LED_DISPLAY].smu_feature_id =
350 FEATURE_LED_DISPLAY_BIT;
351 data->smu_features[GNLD_FAN_CONTROL].smu_feature_id =
352 FEATURE_FAN_CONTROL_BIT;
353 data->smu_features[GNLD_DIDT].smu_feature_id = FEATURE_GFX_EDC_BIT;
354 data->smu_features[GNLD_GFXOFF].smu_feature_id = FEATURE_GFXOFF_BIT;
355 data->smu_features[GNLD_CG].smu_feature_id = FEATURE_CG_BIT;
356 data->smu_features[GNLD_ACG].smu_feature_id = FEATURE_ACG_BIT;
357
358 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
359 data->smu_features[i].smu_feature_bitmap =
360 (uint64_t)(1ULL << data->smu_features[i].smu_feature_id);
361 data->smu_features[i].allowed =
362 ((data->registry_data.disallowed_features >> i) & 1) ?
363 false : true;
364 }
365
366 /* Get the SN to turn into a Unique ID */
367 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32, &top32);
368 if (ret)
369 return ret;
370 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32, &bottom32);
371 if (ret)
372 return ret;
373
374 adev->unique_id = ((uint64_t)bottom32 << 32) | top32;
375
376 return 0;
377 }
378
vega12_set_private_data_based_on_pptable(struct pp_hwmgr * hwmgr)379 static int vega12_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
380 {
381 return 0;
382 }
383
vega12_hwmgr_backend_fini(struct pp_hwmgr * hwmgr)384 static int vega12_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
385 {
386 kfree(hwmgr->backend);
387 hwmgr->backend = NULL;
388
389 return 0;
390 }
391
vega12_hwmgr_backend_init(struct pp_hwmgr * hwmgr)392 static int vega12_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
393 {
394 int result = 0;
395 struct vega12_hwmgr *data;
396 struct amdgpu_device *adev = hwmgr->adev;
397
398 data = kzalloc_obj(struct vega12_hwmgr);
399 if (data == NULL)
400 return -ENOMEM;
401
402 hwmgr->backend = data;
403
404 vega12_set_default_registry_data(hwmgr);
405
406 data->disable_dpm_mask = 0xff;
407 data->workload_mask = 0xff;
408
409 /* need to set voltage control types before EVV patching */
410 data->vddc_control = VEGA12_VOLTAGE_CONTROL_NONE;
411 data->mvdd_control = VEGA12_VOLTAGE_CONTROL_NONE;
412 data->vddci_control = VEGA12_VOLTAGE_CONTROL_NONE;
413
414 data->water_marks_bitmap = 0;
415 data->avfs_exist = false;
416
417 vega12_set_features_platform_caps(hwmgr);
418
419 result = vega12_init_dpm_defaults(hwmgr);
420 if (result) {
421 pr_err("%s failed\n", __func__);
422 return result;
423 }
424
425 /* Parse pptable data read from VBIOS */
426 vega12_set_private_data_based_on_pptable(hwmgr);
427
428 data->is_tlu_enabled = false;
429
430 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
431 VEGA12_MAX_HARDWARE_POWERLEVELS;
432 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
433 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
434
435 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
436 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
437 hwmgr->platform_descriptor.clockStep.engineClock = 500;
438 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
439
440 data->total_active_cus = adev->gfx.cu_info.number;
441 /* Setup default Overdrive Fan control settings */
442 data->odn_fan_table.target_fan_speed =
443 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM;
444 data->odn_fan_table.target_temperature =
445 hwmgr->thermal_controller.advanceFanControlParameters.ucTargetTemperature;
446 data->odn_fan_table.min_performance_clock =
447 hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit;
448 data->odn_fan_table.min_fan_limit =
449 hwmgr->thermal_controller.advanceFanControlParameters.usFanPWMMinLimit *
450 hwmgr->thermal_controller.fanInfo.ulMaxRPM / 100;
451
452 if (hwmgr->feature_mask & PP_GFXOFF_MASK)
453 data->gfxoff_controlled_by_driver = true;
454 else
455 data->gfxoff_controlled_by_driver = false;
456
457 return result;
458 }
459
vega12_init_sclk_threshold(struct pp_hwmgr * hwmgr)460 static int vega12_init_sclk_threshold(struct pp_hwmgr *hwmgr)
461 {
462 struct vega12_hwmgr *data =
463 (struct vega12_hwmgr *)(hwmgr->backend);
464
465 data->low_sclk_interrupt_threshold = 0;
466
467 return 0;
468 }
469
vega12_setup_asic_task(struct pp_hwmgr * hwmgr)470 static int vega12_setup_asic_task(struct pp_hwmgr *hwmgr)
471 {
472 PP_ASSERT_WITH_CODE(!vega12_init_sclk_threshold(hwmgr),
473 "Failed to init sclk threshold!",
474 return -EINVAL);
475
476 return 0;
477 }
478
479 /*
480 * @fn vega12_init_dpm_state
481 * @brief Function to initialize all Soft Min/Max and Hard Min/Max to 0xff.
482 *
483 * @param dpm_state - the address of the DPM Table to initiailize.
484 * @return None.
485 */
vega12_init_dpm_state(struct vega12_dpm_state * dpm_state)486 static void vega12_init_dpm_state(struct vega12_dpm_state *dpm_state)
487 {
488 dpm_state->soft_min_level = 0x0;
489 dpm_state->soft_max_level = 0xffff;
490 dpm_state->hard_min_level = 0x0;
491 dpm_state->hard_max_level = 0xffff;
492 }
493
vega12_override_pcie_parameters(struct pp_hwmgr * hwmgr)494 static int vega12_override_pcie_parameters(struct pp_hwmgr *hwmgr)
495 {
496 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
497 struct vega12_hwmgr *data =
498 (struct vega12_hwmgr *)(hwmgr->backend);
499 uint32_t pcie_gen = 0, pcie_width = 0, smu_pcie_arg, pcie_gen_arg, pcie_width_arg;
500 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
501 int i;
502 int ret;
503
504 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4)
505 pcie_gen = 3;
506 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
507 pcie_gen = 2;
508 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
509 pcie_gen = 1;
510 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1)
511 pcie_gen = 0;
512
513 if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16)
514 pcie_width = 6;
515 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12)
516 pcie_width = 5;
517 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8)
518 pcie_width = 4;
519 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4)
520 pcie_width = 3;
521 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2)
522 pcie_width = 2;
523 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X1)
524 pcie_width = 1;
525
526 /* Bit 31:16: LCLK DPM level. 0 is DPM0, and 1 is DPM1
527 * Bit 15:8: PCIE GEN, 0 to 3 corresponds to GEN1 to GEN4
528 * Bit 7:0: PCIE lane width, 1 to 7 corresponds is x1 to x32
529 */
530 for (i = 0; i < NUM_LINK_LEVELS; i++) {
531 pcie_gen_arg = (pp_table->PcieGenSpeed[i] > pcie_gen) ? pcie_gen :
532 pp_table->PcieGenSpeed[i];
533 pcie_width_arg = (pp_table->PcieLaneCount[i] > pcie_width) ? pcie_width :
534 pp_table->PcieLaneCount[i];
535
536 if (pcie_gen_arg != pp_table->PcieGenSpeed[i] || pcie_width_arg !=
537 pp_table->PcieLaneCount[i]) {
538 smu_pcie_arg = (i << 16) | (pcie_gen_arg << 8) | pcie_width_arg;
539 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
540 PPSMC_MSG_OverridePcieParameters, smu_pcie_arg,
541 NULL);
542 PP_ASSERT_WITH_CODE(!ret,
543 "[OverridePcieParameters] Attempt to override pcie params failed!",
544 return ret);
545 }
546
547 /* update the pptable */
548 pp_table->PcieGenSpeed[i] = pcie_gen_arg;
549 pp_table->PcieLaneCount[i] = pcie_width_arg;
550 }
551
552 /* override to the highest if it's disabled from ppfeaturmask */
553 if (data->registry_data.pcie_dpm_key_disabled) {
554 for (i = 0; i < NUM_LINK_LEVELS; i++) {
555 smu_pcie_arg = (i << 16) | (pcie_gen << 8) | pcie_width;
556 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
557 PPSMC_MSG_OverridePcieParameters, smu_pcie_arg,
558 NULL);
559 PP_ASSERT_WITH_CODE(!ret,
560 "[OverridePcieParameters] Attempt to override pcie params failed!",
561 return ret);
562
563 pp_table->PcieGenSpeed[i] = pcie_gen;
564 pp_table->PcieLaneCount[i] = pcie_width;
565 }
566 ret = vega12_enable_smc_features(hwmgr,
567 false,
568 data->smu_features[GNLD_DPM_LINK].smu_feature_bitmap);
569 PP_ASSERT_WITH_CODE(!ret,
570 "Attempt to Disable DPM LINK Failed!",
571 return ret);
572 data->smu_features[GNLD_DPM_LINK].enabled = false;
573 data->smu_features[GNLD_DPM_LINK].supported = false;
574 }
575 return 0;
576 }
577
vega12_get_number_of_dpm_level(struct pp_hwmgr * hwmgr,PPCLK_e clk_id,uint32_t * num_of_levels)578 static int vega12_get_number_of_dpm_level(struct pp_hwmgr *hwmgr,
579 PPCLK_e clk_id, uint32_t *num_of_levels)
580 {
581 int ret = 0;
582
583 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
584 PPSMC_MSG_GetDpmFreqByIndex,
585 (clk_id << 16 | 0xFF),
586 num_of_levels);
587 PP_ASSERT_WITH_CODE(!ret,
588 "[GetNumOfDpmLevel] failed to get dpm levels!",
589 return ret);
590
591 return ret;
592 }
593
vega12_get_dpm_frequency_by_index(struct pp_hwmgr * hwmgr,PPCLK_e clkID,uint32_t index,uint32_t * clock)594 static int vega12_get_dpm_frequency_by_index(struct pp_hwmgr *hwmgr,
595 PPCLK_e clkID, uint32_t index, uint32_t *clock)
596 {
597 /*
598 *SMU expects the Clock ID to be in the top 16 bits.
599 *Lower 16 bits specify the level
600 */
601 PP_ASSERT_WITH_CODE(smum_send_msg_to_smc_with_parameter(hwmgr,
602 PPSMC_MSG_GetDpmFreqByIndex, (clkID << 16 | index),
603 clock) == 0,
604 "[GetDpmFrequencyByIndex] Failed to get dpm frequency from SMU!",
605 return -EINVAL);
606
607 return 0;
608 }
609
vega12_setup_single_dpm_table(struct pp_hwmgr * hwmgr,struct vega12_single_dpm_table * dpm_table,PPCLK_e clk_id)610 static int vega12_setup_single_dpm_table(struct pp_hwmgr *hwmgr,
611 struct vega12_single_dpm_table *dpm_table, PPCLK_e clk_id)
612 {
613 int ret = 0;
614 uint32_t i, num_of_levels, clk;
615
616 ret = vega12_get_number_of_dpm_level(hwmgr, clk_id, &num_of_levels);
617 PP_ASSERT_WITH_CODE(!ret,
618 "[SetupSingleDpmTable] failed to get clk levels!",
619 return ret);
620
621 dpm_table->count = num_of_levels;
622
623 for (i = 0; i < num_of_levels; i++) {
624 ret = vega12_get_dpm_frequency_by_index(hwmgr, clk_id, i, &clk);
625 PP_ASSERT_WITH_CODE(!ret,
626 "[SetupSingleDpmTable] failed to get clk of specific level!",
627 return ret);
628 dpm_table->dpm_levels[i].value = clk;
629 dpm_table->dpm_levels[i].enabled = true;
630 }
631
632 return ret;
633 }
634
635 /*
636 * This function is to initialize all DPM state tables
637 * for SMU based on the dependency table.
638 * Dynamic state patching function will then trim these
639 * state tables to the allowed range based
640 * on the power policy or external client requests,
641 * such as UVD request, etc.
642 */
vega12_setup_default_dpm_tables(struct pp_hwmgr * hwmgr)643 static int vega12_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
644 {
645
646 struct vega12_hwmgr *data =
647 (struct vega12_hwmgr *)(hwmgr->backend);
648 struct vega12_single_dpm_table *dpm_table;
649 int ret = 0;
650
651 memset(&data->dpm_table, 0, sizeof(data->dpm_table));
652
653 /* socclk */
654 dpm_table = &(data->dpm_table.soc_table);
655 if (data->smu_features[GNLD_DPM_SOCCLK].enabled) {
656 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_SOCCLK);
657 PP_ASSERT_WITH_CODE(!ret,
658 "[SetupDefaultDpmTable] failed to get socclk dpm levels!",
659 return ret);
660 } else {
661 dpm_table->count = 1;
662 dpm_table->dpm_levels[0].value = data->vbios_boot_state.soc_clock / 100;
663 }
664 vega12_init_dpm_state(&(dpm_table->dpm_state));
665
666 /* gfxclk */
667 dpm_table = &(data->dpm_table.gfx_table);
668 if (data->smu_features[GNLD_DPM_GFXCLK].enabled) {
669 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_GFXCLK);
670 PP_ASSERT_WITH_CODE(!ret,
671 "[SetupDefaultDpmTable] failed to get gfxclk dpm levels!",
672 return ret);
673 } else {
674 dpm_table->count = 1;
675 dpm_table->dpm_levels[0].value = data->vbios_boot_state.gfx_clock / 100;
676 }
677 vega12_init_dpm_state(&(dpm_table->dpm_state));
678
679 /* memclk */
680 dpm_table = &(data->dpm_table.mem_table);
681 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
682 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_UCLK);
683 PP_ASSERT_WITH_CODE(!ret,
684 "[SetupDefaultDpmTable] failed to get memclk dpm levels!",
685 return ret);
686 } else {
687 dpm_table->count = 1;
688 dpm_table->dpm_levels[0].value = data->vbios_boot_state.mem_clock / 100;
689 }
690 vega12_init_dpm_state(&(dpm_table->dpm_state));
691
692 /* eclk */
693 dpm_table = &(data->dpm_table.eclk_table);
694 if (data->smu_features[GNLD_DPM_VCE].enabled) {
695 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_ECLK);
696 PP_ASSERT_WITH_CODE(!ret,
697 "[SetupDefaultDpmTable] failed to get eclk dpm levels!",
698 return ret);
699 } else {
700 dpm_table->count = 1;
701 dpm_table->dpm_levels[0].value = data->vbios_boot_state.eclock / 100;
702 }
703 vega12_init_dpm_state(&(dpm_table->dpm_state));
704
705 /* vclk */
706 dpm_table = &(data->dpm_table.vclk_table);
707 if (data->smu_features[GNLD_DPM_UVD].enabled) {
708 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_VCLK);
709 PP_ASSERT_WITH_CODE(!ret,
710 "[SetupDefaultDpmTable] failed to get vclk dpm levels!",
711 return ret);
712 } else {
713 dpm_table->count = 1;
714 dpm_table->dpm_levels[0].value = data->vbios_boot_state.vclock / 100;
715 }
716 vega12_init_dpm_state(&(dpm_table->dpm_state));
717
718 /* dclk */
719 dpm_table = &(data->dpm_table.dclk_table);
720 if (data->smu_features[GNLD_DPM_UVD].enabled) {
721 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DCLK);
722 PP_ASSERT_WITH_CODE(!ret,
723 "[SetupDefaultDpmTable] failed to get dclk dpm levels!",
724 return ret);
725 } else {
726 dpm_table->count = 1;
727 dpm_table->dpm_levels[0].value = data->vbios_boot_state.dclock / 100;
728 }
729 vega12_init_dpm_state(&(dpm_table->dpm_state));
730
731 /* dcefclk */
732 dpm_table = &(data->dpm_table.dcef_table);
733 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
734 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DCEFCLK);
735 PP_ASSERT_WITH_CODE(!ret,
736 "[SetupDefaultDpmTable] failed to get dcefclk dpm levels!",
737 return ret);
738 } else {
739 dpm_table->count = 1;
740 dpm_table->dpm_levels[0].value = data->vbios_boot_state.dcef_clock / 100;
741 }
742 vega12_init_dpm_state(&(dpm_table->dpm_state));
743
744 /* pixclk */
745 dpm_table = &(data->dpm_table.pixel_table);
746 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
747 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_PIXCLK);
748 PP_ASSERT_WITH_CODE(!ret,
749 "[SetupDefaultDpmTable] failed to get pixclk dpm levels!",
750 return ret);
751 } else
752 dpm_table->count = 0;
753 vega12_init_dpm_state(&(dpm_table->dpm_state));
754
755 /* dispclk */
756 dpm_table = &(data->dpm_table.display_table);
757 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
758 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DISPCLK);
759 PP_ASSERT_WITH_CODE(!ret,
760 "[SetupDefaultDpmTable] failed to get dispclk dpm levels!",
761 return ret);
762 } else
763 dpm_table->count = 0;
764 vega12_init_dpm_state(&(dpm_table->dpm_state));
765
766 /* phyclk */
767 dpm_table = &(data->dpm_table.phy_table);
768 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
769 ret = vega12_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_PHYCLK);
770 PP_ASSERT_WITH_CODE(!ret,
771 "[SetupDefaultDpmTable] failed to get phyclk dpm levels!",
772 return ret);
773 } else
774 dpm_table->count = 0;
775 vega12_init_dpm_state(&(dpm_table->dpm_state));
776
777 /* save a copy of the default DPM table */
778 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
779 sizeof(struct vega12_dpm_table));
780
781 return 0;
782 }
783
784 #if 0
785 static int vega12_save_default_power_profile(struct pp_hwmgr *hwmgr)
786 {
787 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
788 struct vega12_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table);
789 uint32_t min_level;
790
791 hwmgr->default_gfx_power_profile.type = AMD_PP_GFX_PROFILE;
792 hwmgr->default_compute_power_profile.type = AMD_PP_COMPUTE_PROFILE;
793
794 /* Optimize compute power profile: Use only highest
795 * 2 power levels (if more than 2 are available)
796 */
797 if (dpm_table->count > 2)
798 min_level = dpm_table->count - 2;
799 else if (dpm_table->count == 2)
800 min_level = 1;
801 else
802 min_level = 0;
803
804 hwmgr->default_compute_power_profile.min_sclk =
805 dpm_table->dpm_levels[min_level].value;
806
807 hwmgr->gfx_power_profile = hwmgr->default_gfx_power_profile;
808 hwmgr->compute_power_profile = hwmgr->default_compute_power_profile;
809
810 return 0;
811 }
812 #endif
813
814 /**
815 * vega12_init_smc_table - Initializes the SMC table and uploads it
816 *
817 * @hwmgr: the address of the powerplay hardware manager.
818 * return: always 0
819 */
vega12_init_smc_table(struct pp_hwmgr * hwmgr)820 static int vega12_init_smc_table(struct pp_hwmgr *hwmgr)
821 {
822 int result;
823 struct vega12_hwmgr *data =
824 (struct vega12_hwmgr *)(hwmgr->backend);
825 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
826 struct pp_atomfwctrl_bios_boot_up_values boot_up_values;
827 struct phm_ppt_v3_information *pptable_information =
828 (struct phm_ppt_v3_information *)hwmgr->pptable;
829
830 result = pp_atomfwctrl_get_vbios_bootup_values(hwmgr, &boot_up_values);
831 if (!result) {
832 data->vbios_boot_state.vddc = boot_up_values.usVddc;
833 data->vbios_boot_state.vddci = boot_up_values.usVddci;
834 data->vbios_boot_state.mvddc = boot_up_values.usMvddc;
835 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk;
836 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk;
837 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk;
838 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk;
839 data->vbios_boot_state.uc_cooling_id = boot_up_values.ucCoolingID;
840 data->vbios_boot_state.eclock = boot_up_values.ulEClk;
841 data->vbios_boot_state.dclock = boot_up_values.ulDClk;
842 data->vbios_boot_state.vclock = boot_up_values.ulVClk;
843 smum_send_msg_to_smc_with_parameter(hwmgr,
844 PPSMC_MSG_SetMinDeepSleepDcefclk,
845 (uint32_t)(data->vbios_boot_state.dcef_clock / 100),
846 NULL);
847 }
848
849 memcpy(pp_table, pptable_information->smc_pptable, sizeof(PPTable_t));
850
851 result = smum_smc_table_manager(hwmgr,
852 (uint8_t *)pp_table, TABLE_PPTABLE, false);
853 PP_ASSERT_WITH_CODE(!result,
854 "Failed to upload PPtable!", return result);
855
856 return 0;
857 }
858
vega12_run_acg_btc(struct pp_hwmgr * hwmgr)859 static int vega12_run_acg_btc(struct pp_hwmgr *hwmgr)
860 {
861 uint32_t result;
862
863 PP_ASSERT_WITH_CODE(
864 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgBtc, &result) == 0,
865 "[Run_ACG_BTC] Attempt to run ACG BTC failed!",
866 return -EINVAL);
867
868 PP_ASSERT_WITH_CODE(result == 1,
869 "Failed to run ACG BTC!", return -EINVAL);
870
871 return 0;
872 }
873
vega12_set_allowed_featuresmask(struct pp_hwmgr * hwmgr)874 static int vega12_set_allowed_featuresmask(struct pp_hwmgr *hwmgr)
875 {
876 struct vega12_hwmgr *data =
877 (struct vega12_hwmgr *)(hwmgr->backend);
878 int i;
879 uint32_t allowed_features_low = 0, allowed_features_high = 0;
880
881 for (i = 0; i < GNLD_FEATURES_MAX; i++)
882 if (data->smu_features[i].allowed)
883 data->smu_features[i].smu_feature_id > 31 ?
884 (allowed_features_high |= ((data->smu_features[i].smu_feature_bitmap >> SMU_FEATURES_HIGH_SHIFT) & 0xFFFFFFFF)) :
885 (allowed_features_low |= ((data->smu_features[i].smu_feature_bitmap >> SMU_FEATURES_LOW_SHIFT) & 0xFFFFFFFF));
886
887 PP_ASSERT_WITH_CODE(
888 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetAllowedFeaturesMaskHigh, allowed_features_high,
889 NULL) == 0,
890 "[SetAllowedFeaturesMask] Attempt to set allowed features mask (high) failed!",
891 return -1);
892
893 PP_ASSERT_WITH_CODE(
894 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetAllowedFeaturesMaskLow, allowed_features_low,
895 NULL) == 0,
896 "[SetAllowedFeaturesMask] Attempt to set allowed features mask (low) failed!",
897 return -1);
898
899 return 0;
900 }
901
vega12_init_powergate_state(struct pp_hwmgr * hwmgr)902 static void vega12_init_powergate_state(struct pp_hwmgr *hwmgr)
903 {
904 struct vega12_hwmgr *data =
905 (struct vega12_hwmgr *)(hwmgr->backend);
906
907 data->uvd_power_gated = true;
908 data->vce_power_gated = true;
909
910 if (data->smu_features[GNLD_DPM_UVD].enabled)
911 data->uvd_power_gated = false;
912
913 if (data->smu_features[GNLD_DPM_VCE].enabled)
914 data->vce_power_gated = false;
915 }
916
vega12_enable_all_smu_features(struct pp_hwmgr * hwmgr)917 static int vega12_enable_all_smu_features(struct pp_hwmgr *hwmgr)
918 {
919 struct vega12_hwmgr *data =
920 (struct vega12_hwmgr *)(hwmgr->backend);
921 uint64_t features_enabled;
922 int i;
923 bool enabled;
924
925 PP_ASSERT_WITH_CODE(
926 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableAllSmuFeatures, NULL) == 0,
927 "[EnableAllSMUFeatures] Failed to enable all smu features!",
928 return -1);
929
930 if (vega12_get_enabled_smc_features(hwmgr, &features_enabled) == 0) {
931 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
932 enabled = (features_enabled & data->smu_features[i].smu_feature_bitmap) ? true : false;
933 data->smu_features[i].enabled = enabled;
934 data->smu_features[i].supported = enabled;
935 }
936 }
937
938 vega12_init_powergate_state(hwmgr);
939
940 return 0;
941 }
942
vega12_disable_all_smu_features(struct pp_hwmgr * hwmgr)943 static int vega12_disable_all_smu_features(struct pp_hwmgr *hwmgr)
944 {
945 struct vega12_hwmgr *data =
946 (struct vega12_hwmgr *)(hwmgr->backend);
947 uint64_t features_enabled;
948 int i;
949 bool enabled;
950
951 PP_ASSERT_WITH_CODE(
952 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisableAllSmuFeatures, NULL) == 0,
953 "[DisableAllSMUFeatures] Failed to disable all smu features!",
954 return -1);
955
956 if (vega12_get_enabled_smc_features(hwmgr, &features_enabled) == 0) {
957 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
958 enabled = (features_enabled & data->smu_features[i].smu_feature_bitmap) ? true : false;
959 data->smu_features[i].enabled = enabled;
960 data->smu_features[i].supported = enabled;
961 }
962 }
963
964 return 0;
965 }
966
vega12_odn_initialize_default_settings(struct pp_hwmgr * hwmgr)967 static int vega12_odn_initialize_default_settings(
968 struct pp_hwmgr *hwmgr)
969 {
970 return 0;
971 }
972
vega12_set_overdrive_target_percentage(struct pp_hwmgr * hwmgr,uint32_t adjust_percent)973 static int vega12_set_overdrive_target_percentage(struct pp_hwmgr *hwmgr,
974 uint32_t adjust_percent)
975 {
976 return smum_send_msg_to_smc_with_parameter(hwmgr,
977 PPSMC_MSG_OverDriveSetPercentage, adjust_percent,
978 NULL);
979 }
980
vega12_power_control_set_level(struct pp_hwmgr * hwmgr)981 static int vega12_power_control_set_level(struct pp_hwmgr *hwmgr)
982 {
983 int adjust_percent, result = 0;
984
985 if (PP_CAP(PHM_PlatformCaps_PowerContainment)) {
986 adjust_percent =
987 hwmgr->platform_descriptor.TDPAdjustmentPolarity ?
988 hwmgr->platform_descriptor.TDPAdjustment :
989 (-1 * hwmgr->platform_descriptor.TDPAdjustment);
990 result = vega12_set_overdrive_target_percentage(hwmgr,
991 (uint32_t)adjust_percent);
992 }
993 return result;
994 }
995
vega12_get_all_clock_ranges_helper(struct pp_hwmgr * hwmgr,PPCLK_e clkid,struct vega12_clock_range * clock)996 static int vega12_get_all_clock_ranges_helper(struct pp_hwmgr *hwmgr,
997 PPCLK_e clkid, struct vega12_clock_range *clock)
998 {
999 /* AC Max */
1000 PP_ASSERT_WITH_CODE(
1001 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetMaxDpmFreq, (clkid << 16),
1002 &(clock->ACMax)) == 0,
1003 "[GetClockRanges] Failed to get max ac clock from SMC!",
1004 return -EINVAL);
1005
1006 /* AC Min */
1007 PP_ASSERT_WITH_CODE(
1008 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetMinDpmFreq, (clkid << 16),
1009 &(clock->ACMin)) == 0,
1010 "[GetClockRanges] Failed to get min ac clock from SMC!",
1011 return -EINVAL);
1012
1013 /* DC Max */
1014 PP_ASSERT_WITH_CODE(
1015 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetDcModeMaxDpmFreq, (clkid << 16),
1016 &(clock->DCMax)) == 0,
1017 "[GetClockRanges] Failed to get max dc clock from SMC!",
1018 return -EINVAL);
1019
1020 return 0;
1021 }
1022
vega12_get_all_clock_ranges(struct pp_hwmgr * hwmgr)1023 static int vega12_get_all_clock_ranges(struct pp_hwmgr *hwmgr)
1024 {
1025 struct vega12_hwmgr *data =
1026 (struct vega12_hwmgr *)(hwmgr->backend);
1027 uint32_t i;
1028
1029 for (i = 0; i < PPCLK_COUNT; i++)
1030 PP_ASSERT_WITH_CODE(!vega12_get_all_clock_ranges_helper(hwmgr,
1031 i, &(data->clk_range[i])),
1032 "Failed to get clk range from SMC!",
1033 return -EINVAL);
1034
1035 return 0;
1036 }
1037
vega12_populate_umdpstate_clocks(struct pp_hwmgr * hwmgr)1038 static void vega12_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
1039 {
1040 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1041 struct vega12_single_dpm_table *gfx_dpm_table = &(data->dpm_table.gfx_table);
1042 struct vega12_single_dpm_table *mem_dpm_table = &(data->dpm_table.mem_table);
1043
1044 if (gfx_dpm_table->count > VEGA12_UMD_PSTATE_GFXCLK_LEVEL &&
1045 mem_dpm_table->count > VEGA12_UMD_PSTATE_MCLK_LEVEL) {
1046 hwmgr->pstate_sclk = gfx_dpm_table->dpm_levels[VEGA12_UMD_PSTATE_GFXCLK_LEVEL].value;
1047 hwmgr->pstate_mclk = mem_dpm_table->dpm_levels[VEGA12_UMD_PSTATE_MCLK_LEVEL].value;
1048 } else {
1049 hwmgr->pstate_sclk = gfx_dpm_table->dpm_levels[0].value;
1050 hwmgr->pstate_mclk = mem_dpm_table->dpm_levels[0].value;
1051 }
1052
1053 hwmgr->pstate_sclk_peak = gfx_dpm_table->dpm_levels[gfx_dpm_table->count].value;
1054 hwmgr->pstate_mclk_peak = mem_dpm_table->dpm_levels[mem_dpm_table->count].value;
1055 }
1056
vega12_enable_dpm_tasks(struct pp_hwmgr * hwmgr)1057 static int vega12_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1058 {
1059 int tmp_result, result = 0;
1060
1061 smum_send_msg_to_smc_with_parameter(hwmgr,
1062 PPSMC_MSG_NumOfDisplays, 0, NULL);
1063
1064 result = vega12_set_allowed_featuresmask(hwmgr);
1065 PP_ASSERT_WITH_CODE(result == 0,
1066 "[EnableDPMTasks] Failed to set allowed featuresmask!\n",
1067 return result);
1068
1069 tmp_result = vega12_init_smc_table(hwmgr);
1070 PP_ASSERT_WITH_CODE(!tmp_result,
1071 "Failed to initialize SMC table!",
1072 result = tmp_result);
1073
1074 tmp_result = vega12_run_acg_btc(hwmgr);
1075 PP_ASSERT_WITH_CODE(!tmp_result,
1076 "Failed to run ACG BTC!",
1077 result = tmp_result);
1078
1079 result = vega12_enable_all_smu_features(hwmgr);
1080 PP_ASSERT_WITH_CODE(!result,
1081 "Failed to enable all smu features!",
1082 return result);
1083
1084 result = vega12_override_pcie_parameters(hwmgr);
1085 PP_ASSERT_WITH_CODE(!result,
1086 "[EnableDPMTasks] Failed to override pcie parameters!",
1087 return result);
1088
1089 tmp_result = vega12_power_control_set_level(hwmgr);
1090 PP_ASSERT_WITH_CODE(!tmp_result,
1091 "Failed to power control set level!",
1092 result = tmp_result);
1093
1094 result = vega12_get_all_clock_ranges(hwmgr);
1095 PP_ASSERT_WITH_CODE(!result,
1096 "Failed to get all clock ranges!",
1097 return result);
1098
1099 result = vega12_odn_initialize_default_settings(hwmgr);
1100 PP_ASSERT_WITH_CODE(!result,
1101 "Failed to power control set level!",
1102 return result);
1103
1104 result = vega12_setup_default_dpm_tables(hwmgr);
1105 PP_ASSERT_WITH_CODE(!result,
1106 "Failed to setup default DPM tables!",
1107 return result);
1108
1109 vega12_populate_umdpstate_clocks(hwmgr);
1110
1111 return result;
1112 }
1113
vega12_patch_boot_state(struct pp_hwmgr * hwmgr,struct pp_hw_power_state * hw_ps)1114 static int vega12_patch_boot_state(struct pp_hwmgr *hwmgr,
1115 struct pp_hw_power_state *hw_ps)
1116 {
1117 return 0;
1118 }
1119
vega12_find_lowest_dpm_level(struct vega12_single_dpm_table * table)1120 static uint32_t vega12_find_lowest_dpm_level(
1121 struct vega12_single_dpm_table *table)
1122 {
1123 uint32_t i;
1124
1125 for (i = 0; i < table->count; i++) {
1126 if (table->dpm_levels[i].enabled)
1127 break;
1128 }
1129
1130 if (i >= table->count) {
1131 i = 0;
1132 table->dpm_levels[i].enabled = true;
1133 }
1134
1135 return i;
1136 }
1137
vega12_find_highest_dpm_level(struct vega12_single_dpm_table * table)1138 static uint32_t vega12_find_highest_dpm_level(
1139 struct vega12_single_dpm_table *table)
1140 {
1141 int32_t i = 0;
1142 PP_ASSERT_WITH_CODE(table->count <= MAX_REGULAR_DPM_NUMBER,
1143 "[FindHighestDPMLevel] DPM Table has too many entries!",
1144 return MAX_REGULAR_DPM_NUMBER - 1);
1145
1146 for (i = table->count - 1; i >= 0; i--) {
1147 if (table->dpm_levels[i].enabled)
1148 break;
1149 }
1150
1151 if (i < 0) {
1152 i = 0;
1153 table->dpm_levels[i].enabled = true;
1154 }
1155
1156 return (uint32_t)i;
1157 }
1158
vega12_upload_dpm_min_level(struct pp_hwmgr * hwmgr)1159 static int vega12_upload_dpm_min_level(struct pp_hwmgr *hwmgr)
1160 {
1161 struct vega12_hwmgr *data = hwmgr->backend;
1162 uint32_t min_freq;
1163 int ret = 0;
1164
1165 if (data->smu_features[GNLD_DPM_GFXCLK].enabled) {
1166 min_freq = data->dpm_table.gfx_table.dpm_state.soft_min_level;
1167 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1168 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1169 (PPCLK_GFXCLK << 16) | (min_freq & 0xffff),
1170 NULL)),
1171 "Failed to set soft min gfxclk !",
1172 return ret);
1173 }
1174
1175 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
1176 min_freq = data->dpm_table.mem_table.dpm_state.soft_min_level;
1177 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1178 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1179 (PPCLK_UCLK << 16) | (min_freq & 0xffff),
1180 NULL)),
1181 "Failed to set soft min memclk !",
1182 return ret);
1183
1184 min_freq = data->dpm_table.mem_table.dpm_state.hard_min_level;
1185 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1186 hwmgr, PPSMC_MSG_SetHardMinByFreq,
1187 (PPCLK_UCLK << 16) | (min_freq & 0xffff),
1188 NULL)),
1189 "Failed to set hard min memclk !",
1190 return ret);
1191 }
1192
1193 if (data->smu_features[GNLD_DPM_UVD].enabled) {
1194 min_freq = data->dpm_table.vclk_table.dpm_state.soft_min_level;
1195
1196 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1197 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1198 (PPCLK_VCLK << 16) | (min_freq & 0xffff),
1199 NULL)),
1200 "Failed to set soft min vclk!",
1201 return ret);
1202
1203 min_freq = data->dpm_table.dclk_table.dpm_state.soft_min_level;
1204
1205 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1206 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1207 (PPCLK_DCLK << 16) | (min_freq & 0xffff),
1208 NULL)),
1209 "Failed to set soft min dclk!",
1210 return ret);
1211 }
1212
1213 if (data->smu_features[GNLD_DPM_VCE].enabled) {
1214 min_freq = data->dpm_table.eclk_table.dpm_state.soft_min_level;
1215
1216 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1217 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1218 (PPCLK_ECLK << 16) | (min_freq & 0xffff),
1219 NULL)),
1220 "Failed to set soft min eclk!",
1221 return ret);
1222 }
1223
1224 if (data->smu_features[GNLD_DPM_SOCCLK].enabled) {
1225 min_freq = data->dpm_table.soc_table.dpm_state.soft_min_level;
1226
1227 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1228 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1229 (PPCLK_SOCCLK << 16) | (min_freq & 0xffff),
1230 NULL)),
1231 "Failed to set soft min socclk!",
1232 return ret);
1233 }
1234
1235 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
1236 min_freq = data->dpm_table.dcef_table.dpm_state.hard_min_level;
1237
1238 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1239 hwmgr, PPSMC_MSG_SetHardMinByFreq,
1240 (PPCLK_DCEFCLK << 16) | (min_freq & 0xffff),
1241 NULL)),
1242 "Failed to set hard min dcefclk!",
1243 return ret);
1244 }
1245
1246 return ret;
1247
1248 }
1249
vega12_upload_dpm_max_level(struct pp_hwmgr * hwmgr)1250 static int vega12_upload_dpm_max_level(struct pp_hwmgr *hwmgr)
1251 {
1252 struct vega12_hwmgr *data = hwmgr->backend;
1253 uint32_t max_freq;
1254 int ret = 0;
1255
1256 if (data->smu_features[GNLD_DPM_GFXCLK].enabled) {
1257 max_freq = data->dpm_table.gfx_table.dpm_state.soft_max_level;
1258
1259 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1260 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1261 (PPCLK_GFXCLK << 16) | (max_freq & 0xffff),
1262 NULL)),
1263 "Failed to set soft max gfxclk!",
1264 return ret);
1265 }
1266
1267 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
1268 max_freq = data->dpm_table.mem_table.dpm_state.soft_max_level;
1269
1270 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1271 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1272 (PPCLK_UCLK << 16) | (max_freq & 0xffff),
1273 NULL)),
1274 "Failed to set soft max memclk!",
1275 return ret);
1276 }
1277
1278 if (data->smu_features[GNLD_DPM_UVD].enabled) {
1279 max_freq = data->dpm_table.vclk_table.dpm_state.soft_max_level;
1280
1281 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1282 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1283 (PPCLK_VCLK << 16) | (max_freq & 0xffff),
1284 NULL)),
1285 "Failed to set soft max vclk!",
1286 return ret);
1287
1288 max_freq = data->dpm_table.dclk_table.dpm_state.soft_max_level;
1289 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1290 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1291 (PPCLK_DCLK << 16) | (max_freq & 0xffff),
1292 NULL)),
1293 "Failed to set soft max dclk!",
1294 return ret);
1295 }
1296
1297 if (data->smu_features[GNLD_DPM_VCE].enabled) {
1298 max_freq = data->dpm_table.eclk_table.dpm_state.soft_max_level;
1299
1300 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1301 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1302 (PPCLK_ECLK << 16) | (max_freq & 0xffff),
1303 NULL)),
1304 "Failed to set soft max eclk!",
1305 return ret);
1306 }
1307
1308 if (data->smu_features[GNLD_DPM_SOCCLK].enabled) {
1309 max_freq = data->dpm_table.soc_table.dpm_state.soft_max_level;
1310
1311 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1312 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1313 (PPCLK_SOCCLK << 16) | (max_freq & 0xffff),
1314 NULL)),
1315 "Failed to set soft max socclk!",
1316 return ret);
1317 }
1318
1319 return ret;
1320 }
1321
vega12_enable_disable_vce_dpm(struct pp_hwmgr * hwmgr,bool enable)1322 int vega12_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
1323 {
1324 struct vega12_hwmgr *data =
1325 (struct vega12_hwmgr *)(hwmgr->backend);
1326
1327 if (data->smu_features[GNLD_DPM_VCE].supported) {
1328 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(hwmgr,
1329 enable,
1330 data->smu_features[GNLD_DPM_VCE].smu_feature_bitmap),
1331 "Attempt to Enable/Disable DPM VCE Failed!",
1332 return -1);
1333 data->smu_features[GNLD_DPM_VCE].enabled = enable;
1334 }
1335
1336 return 0;
1337 }
1338
vega12_dpm_get_sclk(struct pp_hwmgr * hwmgr,bool low)1339 static uint32_t vega12_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
1340 {
1341 struct vega12_hwmgr *data =
1342 (struct vega12_hwmgr *)(hwmgr->backend);
1343 uint32_t gfx_clk;
1344
1345 if (!data->smu_features[GNLD_DPM_GFXCLK].enabled)
1346 return -1;
1347
1348 if (low)
1349 PP_ASSERT_WITH_CODE(
1350 vega12_get_clock_ranges(hwmgr, &gfx_clk, PPCLK_GFXCLK, false) == 0,
1351 "[GetSclks]: fail to get min PPCLK_GFXCLK\n",
1352 return -1);
1353 else
1354 PP_ASSERT_WITH_CODE(
1355 vega12_get_clock_ranges(hwmgr, &gfx_clk, PPCLK_GFXCLK, true) == 0,
1356 "[GetSclks]: fail to get max PPCLK_GFXCLK\n",
1357 return -1);
1358
1359 return (gfx_clk * 100);
1360 }
1361
vega12_dpm_get_mclk(struct pp_hwmgr * hwmgr,bool low)1362 static uint32_t vega12_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
1363 {
1364 struct vega12_hwmgr *data =
1365 (struct vega12_hwmgr *)(hwmgr->backend);
1366 uint32_t mem_clk;
1367
1368 if (!data->smu_features[GNLD_DPM_UCLK].enabled)
1369 return -1;
1370
1371 if (low)
1372 PP_ASSERT_WITH_CODE(
1373 vega12_get_clock_ranges(hwmgr, &mem_clk, PPCLK_UCLK, false) == 0,
1374 "[GetMclks]: fail to get min PPCLK_UCLK\n",
1375 return -1);
1376 else
1377 PP_ASSERT_WITH_CODE(
1378 vega12_get_clock_ranges(hwmgr, &mem_clk, PPCLK_UCLK, true) == 0,
1379 "[GetMclks]: fail to get max PPCLK_UCLK\n",
1380 return -1);
1381
1382 return (mem_clk * 100);
1383 }
1384
vega12_get_metrics_table(struct pp_hwmgr * hwmgr,SmuMetrics_t * metrics_table,bool bypass_cache)1385 static int vega12_get_metrics_table(struct pp_hwmgr *hwmgr,
1386 SmuMetrics_t *metrics_table,
1387 bool bypass_cache)
1388 {
1389 struct vega12_hwmgr *data =
1390 (struct vega12_hwmgr *)(hwmgr->backend);
1391 int ret = 0;
1392
1393 if (bypass_cache ||
1394 !data->metrics_time ||
1395 time_after(jiffies, data->metrics_time + msecs_to_jiffies(1))) {
1396 ret = smum_smc_table_manager(hwmgr,
1397 (uint8_t *)(&data->metrics_table),
1398 TABLE_SMU_METRICS,
1399 true);
1400 if (ret) {
1401 pr_info("Failed to export SMU metrics table!\n");
1402 return ret;
1403 }
1404 data->metrics_time = jiffies;
1405 }
1406
1407 if (metrics_table)
1408 memcpy(metrics_table, &data->metrics_table, sizeof(SmuMetrics_t));
1409
1410 return ret;
1411 }
1412
vega12_get_gpu_power(struct pp_hwmgr * hwmgr,uint32_t * query)1413 static int vega12_get_gpu_power(struct pp_hwmgr *hwmgr, uint32_t *query)
1414 {
1415 SmuMetrics_t metrics_table;
1416 int ret = 0;
1417
1418 ret = vega12_get_metrics_table(hwmgr, &metrics_table, false);
1419 if (ret)
1420 return ret;
1421
1422 *query = metrics_table.CurrSocketPower * MILLIWATT_PER_WATT;
1423
1424 return ret;
1425 }
1426
vega12_get_current_gfx_clk_freq(struct pp_hwmgr * hwmgr,uint32_t * gfx_freq)1427 static int vega12_get_current_gfx_clk_freq(struct pp_hwmgr *hwmgr, uint32_t *gfx_freq)
1428 {
1429 uint32_t gfx_clk = 0;
1430
1431 *gfx_freq = 0;
1432
1433 PP_ASSERT_WITH_CODE(smum_send_msg_to_smc_with_parameter(hwmgr,
1434 PPSMC_MSG_GetDpmClockFreq, (PPCLK_GFXCLK << 16),
1435 &gfx_clk) == 0,
1436 "[GetCurrentGfxClkFreq] Attempt to get Current GFXCLK Frequency Failed!",
1437 return -EINVAL);
1438
1439 *gfx_freq = gfx_clk * 100;
1440
1441 return 0;
1442 }
1443
vega12_get_current_mclk_freq(struct pp_hwmgr * hwmgr,uint32_t * mclk_freq)1444 static int vega12_get_current_mclk_freq(struct pp_hwmgr *hwmgr, uint32_t *mclk_freq)
1445 {
1446 uint32_t mem_clk = 0;
1447
1448 *mclk_freq = 0;
1449
1450 PP_ASSERT_WITH_CODE(
1451 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetDpmClockFreq, (PPCLK_UCLK << 16),
1452 &mem_clk) == 0,
1453 "[GetCurrentMClkFreq] Attempt to get Current MCLK Frequency Failed!",
1454 return -EINVAL);
1455
1456 *mclk_freq = mem_clk * 100;
1457
1458 return 0;
1459 }
1460
vega12_get_current_activity_percent(struct pp_hwmgr * hwmgr,int idx,uint32_t * activity_percent)1461 static int vega12_get_current_activity_percent(
1462 struct pp_hwmgr *hwmgr,
1463 int idx,
1464 uint32_t *activity_percent)
1465 {
1466 SmuMetrics_t metrics_table;
1467 int ret = 0;
1468
1469 ret = vega12_get_metrics_table(hwmgr, &metrics_table, false);
1470 if (ret)
1471 return ret;
1472
1473 switch (idx) {
1474 case AMDGPU_PP_SENSOR_GPU_LOAD:
1475 *activity_percent = metrics_table.AverageGfxActivity;
1476 break;
1477 case AMDGPU_PP_SENSOR_MEM_LOAD:
1478 *activity_percent = metrics_table.AverageUclkActivity;
1479 break;
1480 default:
1481 pr_err("Invalid index for retrieving clock activity\n");
1482 return -EINVAL;
1483 }
1484
1485 return ret;
1486 }
1487
vega12_read_sensor(struct pp_hwmgr * hwmgr,int idx,void * value,int * size)1488 static int vega12_read_sensor(struct pp_hwmgr *hwmgr, int idx,
1489 void *value, int *size)
1490 {
1491 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1492 SmuMetrics_t metrics_table;
1493 int ret = 0;
1494
1495 switch (idx) {
1496 case AMDGPU_PP_SENSOR_GFX_SCLK:
1497 ret = vega12_get_current_gfx_clk_freq(hwmgr, (uint32_t *)value);
1498 if (!ret)
1499 *size = 4;
1500 break;
1501 case AMDGPU_PP_SENSOR_GFX_MCLK:
1502 ret = vega12_get_current_mclk_freq(hwmgr, (uint32_t *)value);
1503 if (!ret)
1504 *size = 4;
1505 break;
1506 case AMDGPU_PP_SENSOR_GPU_LOAD:
1507 case AMDGPU_PP_SENSOR_MEM_LOAD:
1508 ret = vega12_get_current_activity_percent(hwmgr, idx, (uint32_t *)value);
1509 if (!ret)
1510 *size = 4;
1511 break;
1512 case AMDGPU_PP_SENSOR_GPU_TEMP:
1513 *((uint32_t *)value) = vega12_thermal_get_temperature(hwmgr);
1514 *size = 4;
1515 break;
1516 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1517 ret = vega12_get_metrics_table(hwmgr, &metrics_table, false);
1518 if (ret)
1519 return ret;
1520
1521 *((uint32_t *)value) = metrics_table.TemperatureHotspot *
1522 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1523 *size = 4;
1524 break;
1525 case AMDGPU_PP_SENSOR_MEM_TEMP:
1526 ret = vega12_get_metrics_table(hwmgr, &metrics_table, false);
1527 if (ret)
1528 return ret;
1529
1530 *((uint32_t *)value) = metrics_table.TemperatureHBM *
1531 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1532 *size = 4;
1533 break;
1534 case AMDGPU_PP_SENSOR_UVD_POWER:
1535 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
1536 *size = 4;
1537 break;
1538 case AMDGPU_PP_SENSOR_VCE_POWER:
1539 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
1540 *size = 4;
1541 break;
1542 case AMDGPU_PP_SENSOR_GPU_INPUT_POWER:
1543 ret = vega12_get_gpu_power(hwmgr, (uint32_t *)value);
1544 if (!ret)
1545 *size = 4;
1546 break;
1547 case AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK:
1548 ret = vega12_get_enabled_smc_features(hwmgr, (uint64_t *)value);
1549 if (!ret)
1550 *size = 8;
1551 break;
1552 default:
1553 ret = -EOPNOTSUPP;
1554 break;
1555 }
1556 return ret;
1557 }
1558
vega12_notify_smc_display_change(struct pp_hwmgr * hwmgr,bool has_disp)1559 static int vega12_notify_smc_display_change(struct pp_hwmgr *hwmgr,
1560 bool has_disp)
1561 {
1562 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1563
1564 if (data->smu_features[GNLD_DPM_UCLK].enabled)
1565 return smum_send_msg_to_smc_with_parameter(hwmgr,
1566 PPSMC_MSG_SetUclkFastSwitch,
1567 has_disp ? 1 : 0,
1568 NULL);
1569
1570 return 0;
1571 }
1572
vega12_display_clock_voltage_request(struct pp_hwmgr * hwmgr,struct pp_display_clock_request * clock_req)1573 static int vega12_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
1574 struct pp_display_clock_request *clock_req)
1575 {
1576 int result = 0;
1577 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1578 enum amd_pp_clock_type clk_type = clock_req->clock_type;
1579 uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
1580 PPCLK_e clk_select = 0;
1581 uint32_t clk_request = 0;
1582
1583 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
1584 switch (clk_type) {
1585 case amd_pp_dcef_clock:
1586 clk_select = PPCLK_DCEFCLK;
1587 break;
1588 case amd_pp_disp_clock:
1589 clk_select = PPCLK_DISPCLK;
1590 break;
1591 case amd_pp_pixel_clock:
1592 clk_select = PPCLK_PIXCLK;
1593 break;
1594 case amd_pp_phy_clock:
1595 clk_select = PPCLK_PHYCLK;
1596 break;
1597 default:
1598 pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
1599 result = -1;
1600 break;
1601 }
1602
1603 if (!result) {
1604 clk_request = (clk_select << 16) | clk_freq;
1605 result = smum_send_msg_to_smc_with_parameter(hwmgr,
1606 PPSMC_MSG_SetHardMinByFreq,
1607 clk_request,
1608 NULL);
1609 }
1610 }
1611
1612 return result;
1613 }
1614
vega12_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr * hwmgr)1615 static int vega12_notify_smc_display_config_after_ps_adjustment(
1616 struct pp_hwmgr *hwmgr)
1617 {
1618 struct vega12_hwmgr *data =
1619 (struct vega12_hwmgr *)(hwmgr->backend);
1620 struct PP_Clocks min_clocks = {0};
1621 struct pp_display_clock_request clock_req;
1622
1623 if ((hwmgr->display_config->num_display > 1) &&
1624 !hwmgr->display_config->multi_monitor_in_sync &&
1625 !hwmgr->display_config->nb_pstate_switch_disable)
1626 vega12_notify_smc_display_change(hwmgr, false);
1627 else
1628 vega12_notify_smc_display_change(hwmgr, true);
1629
1630 min_clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
1631 min_clocks.dcefClockInSR = hwmgr->display_config->min_dcef_deep_sleep_set_clk;
1632 min_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
1633
1634 if (data->smu_features[GNLD_DPM_DCEFCLK].supported) {
1635 clock_req.clock_type = amd_pp_dcef_clock;
1636 clock_req.clock_freq_in_khz = min_clocks.dcefClock / 10;
1637 if (!vega12_display_clock_voltage_request(hwmgr, &clock_req)) {
1638 if (data->smu_features[GNLD_DS_DCEFCLK].supported)
1639 PP_ASSERT_WITH_CODE(
1640 !smum_send_msg_to_smc_with_parameter(
1641 hwmgr, PPSMC_MSG_SetMinDeepSleepDcefclk,
1642 min_clocks.dcefClockInSR / 100,
1643 NULL),
1644 "Attempt to set divider for DCEFCLK Failed!",
1645 return -1);
1646 } else {
1647 pr_info("Attempt to set Hard Min for DCEFCLK Failed!");
1648 }
1649 }
1650
1651 return 0;
1652 }
1653
vega12_force_dpm_highest(struct pp_hwmgr * hwmgr)1654 static int vega12_force_dpm_highest(struct pp_hwmgr *hwmgr)
1655 {
1656 struct vega12_hwmgr *data =
1657 (struct vega12_hwmgr *)(hwmgr->backend);
1658
1659 uint32_t soft_level;
1660
1661 soft_level = vega12_find_highest_dpm_level(&(data->dpm_table.gfx_table));
1662
1663 data->dpm_table.gfx_table.dpm_state.soft_min_level =
1664 data->dpm_table.gfx_table.dpm_state.soft_max_level =
1665 data->dpm_table.gfx_table.dpm_levels[soft_level].value;
1666
1667 soft_level = vega12_find_highest_dpm_level(&(data->dpm_table.mem_table));
1668
1669 data->dpm_table.mem_table.dpm_state.soft_min_level =
1670 data->dpm_table.mem_table.dpm_state.soft_max_level =
1671 data->dpm_table.mem_table.dpm_levels[soft_level].value;
1672
1673 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_min_level(hwmgr),
1674 "Failed to upload boot level to highest!",
1675 return -1);
1676
1677 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_max_level(hwmgr),
1678 "Failed to upload dpm max level to highest!",
1679 return -1);
1680
1681 return 0;
1682 }
1683
vega12_force_dpm_lowest(struct pp_hwmgr * hwmgr)1684 static int vega12_force_dpm_lowest(struct pp_hwmgr *hwmgr)
1685 {
1686 struct vega12_hwmgr *data =
1687 (struct vega12_hwmgr *)(hwmgr->backend);
1688 uint32_t soft_level;
1689
1690 soft_level = vega12_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
1691
1692 data->dpm_table.gfx_table.dpm_state.soft_min_level =
1693 data->dpm_table.gfx_table.dpm_state.soft_max_level =
1694 data->dpm_table.gfx_table.dpm_levels[soft_level].value;
1695
1696 soft_level = vega12_find_lowest_dpm_level(&(data->dpm_table.mem_table));
1697
1698 data->dpm_table.mem_table.dpm_state.soft_min_level =
1699 data->dpm_table.mem_table.dpm_state.soft_max_level =
1700 data->dpm_table.mem_table.dpm_levels[soft_level].value;
1701
1702 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_min_level(hwmgr),
1703 "Failed to upload boot level to highest!",
1704 return -1);
1705
1706 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_max_level(hwmgr),
1707 "Failed to upload dpm max level to highest!",
1708 return -1);
1709
1710 return 0;
1711
1712 }
1713
vega12_unforce_dpm_levels(struct pp_hwmgr * hwmgr)1714 static int vega12_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
1715 {
1716 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_min_level(hwmgr),
1717 "Failed to upload DPM Bootup Levels!",
1718 return -1);
1719
1720 PP_ASSERT_WITH_CODE(!vega12_upload_dpm_max_level(hwmgr),
1721 "Failed to upload DPM Max Levels!",
1722 return -1);
1723
1724 return 0;
1725 }
1726
vega12_get_profiling_clk_mask(struct pp_hwmgr * hwmgr,enum amd_dpm_forced_level level,uint32_t * sclk_mask,uint32_t * mclk_mask,uint32_t * soc_mask)1727 static int vega12_get_profiling_clk_mask(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
1728 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *soc_mask)
1729 {
1730 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1731 struct vega12_single_dpm_table *gfx_dpm_table = &(data->dpm_table.gfx_table);
1732 struct vega12_single_dpm_table *mem_dpm_table = &(data->dpm_table.mem_table);
1733 struct vega12_single_dpm_table *soc_dpm_table = &(data->dpm_table.soc_table);
1734
1735 *sclk_mask = 0;
1736 *mclk_mask = 0;
1737 *soc_mask = 0;
1738
1739 if (gfx_dpm_table->count > VEGA12_UMD_PSTATE_GFXCLK_LEVEL &&
1740 mem_dpm_table->count > VEGA12_UMD_PSTATE_MCLK_LEVEL &&
1741 soc_dpm_table->count > VEGA12_UMD_PSTATE_SOCCLK_LEVEL) {
1742 *sclk_mask = VEGA12_UMD_PSTATE_GFXCLK_LEVEL;
1743 *mclk_mask = VEGA12_UMD_PSTATE_MCLK_LEVEL;
1744 *soc_mask = VEGA12_UMD_PSTATE_SOCCLK_LEVEL;
1745 }
1746
1747 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
1748 *sclk_mask = 0;
1749 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
1750 *mclk_mask = 0;
1751 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
1752 *sclk_mask = gfx_dpm_table->count - 1;
1753 *mclk_mask = mem_dpm_table->count - 1;
1754 *soc_mask = soc_dpm_table->count - 1;
1755 }
1756
1757 return 0;
1758 }
1759
vega12_set_fan_control_mode(struct pp_hwmgr * hwmgr,uint32_t mode)1760 static void vega12_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
1761 {
1762 switch (mode) {
1763 case AMD_FAN_CTRL_NONE:
1764 break;
1765 case AMD_FAN_CTRL_MANUAL:
1766 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
1767 vega12_fan_ctrl_stop_smc_fan_control(hwmgr);
1768 break;
1769 case AMD_FAN_CTRL_AUTO:
1770 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
1771 vega12_fan_ctrl_start_smc_fan_control(hwmgr);
1772 break;
1773 default:
1774 break;
1775 }
1776 }
1777
vega12_dpm_force_dpm_level(struct pp_hwmgr * hwmgr,enum amd_dpm_forced_level level)1778 static int vega12_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
1779 enum amd_dpm_forced_level level)
1780 {
1781 int ret = 0;
1782 uint32_t sclk_mask = 0;
1783 uint32_t mclk_mask = 0;
1784 uint32_t soc_mask = 0;
1785
1786 switch (level) {
1787 case AMD_DPM_FORCED_LEVEL_HIGH:
1788 ret = vega12_force_dpm_highest(hwmgr);
1789 break;
1790 case AMD_DPM_FORCED_LEVEL_LOW:
1791 ret = vega12_force_dpm_lowest(hwmgr);
1792 break;
1793 case AMD_DPM_FORCED_LEVEL_AUTO:
1794 ret = vega12_unforce_dpm_levels(hwmgr);
1795 break;
1796 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
1797 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
1798 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
1799 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
1800 ret = vega12_get_profiling_clk_mask(hwmgr, level, &sclk_mask, &mclk_mask, &soc_mask);
1801 if (ret)
1802 return ret;
1803 vega12_force_clock_level(hwmgr, PP_SCLK, 1 << sclk_mask);
1804 vega12_force_clock_level(hwmgr, PP_MCLK, 1 << mclk_mask);
1805 break;
1806 case AMD_DPM_FORCED_LEVEL_MANUAL:
1807 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
1808 default:
1809 break;
1810 }
1811
1812 return ret;
1813 }
1814
vega12_get_fan_control_mode(struct pp_hwmgr * hwmgr)1815 static uint32_t vega12_get_fan_control_mode(struct pp_hwmgr *hwmgr)
1816 {
1817 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1818
1819 if (data->smu_features[GNLD_FAN_CONTROL].enabled == false)
1820 return AMD_FAN_CTRL_MANUAL;
1821 else
1822 return AMD_FAN_CTRL_AUTO;
1823 }
1824
vega12_get_clock_ranges(struct pp_hwmgr * hwmgr,uint32_t * clock,PPCLK_e clock_select,bool max)1825 static int vega12_get_clock_ranges(struct pp_hwmgr *hwmgr,
1826 uint32_t *clock,
1827 PPCLK_e clock_select,
1828 bool max)
1829 {
1830 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1831
1832 if (max)
1833 *clock = data->clk_range[clock_select].ACMax;
1834 else
1835 *clock = data->clk_range[clock_select].ACMin;
1836
1837 return 0;
1838 }
1839
vega12_get_sclks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)1840 static int vega12_get_sclks(struct pp_hwmgr *hwmgr,
1841 struct pp_clock_levels_with_latency *clocks)
1842 {
1843 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1844 uint32_t ucount;
1845 int i;
1846 struct vega12_single_dpm_table *dpm_table;
1847
1848 if (!data->smu_features[GNLD_DPM_GFXCLK].enabled)
1849 return -1;
1850
1851 dpm_table = &(data->dpm_table.gfx_table);
1852 ucount = (dpm_table->count > MAX_NUM_CLOCKS) ?
1853 MAX_NUM_CLOCKS : dpm_table->count;
1854
1855 for (i = 0; i < ucount; i++) {
1856 clocks->data[i].clocks_in_khz =
1857 dpm_table->dpm_levels[i].value * 1000;
1858
1859 clocks->data[i].latency_in_us = 0;
1860 }
1861
1862 clocks->num_levels = ucount;
1863
1864 return 0;
1865 }
1866
vega12_get_mem_latency(struct pp_hwmgr * hwmgr,uint32_t clock)1867 static uint32_t vega12_get_mem_latency(struct pp_hwmgr *hwmgr,
1868 uint32_t clock)
1869 {
1870 return 25;
1871 }
1872
vega12_get_memclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)1873 static int vega12_get_memclocks(struct pp_hwmgr *hwmgr,
1874 struct pp_clock_levels_with_latency *clocks)
1875 {
1876 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1877 uint32_t ucount;
1878 int i;
1879 struct vega12_single_dpm_table *dpm_table;
1880 if (!data->smu_features[GNLD_DPM_UCLK].enabled)
1881 return -1;
1882
1883 dpm_table = &(data->dpm_table.mem_table);
1884 ucount = (dpm_table->count > MAX_NUM_CLOCKS) ?
1885 MAX_NUM_CLOCKS : dpm_table->count;
1886
1887 for (i = 0; i < ucount; i++) {
1888 clocks->data[i].clocks_in_khz = dpm_table->dpm_levels[i].value * 1000;
1889 data->mclk_latency_table.entries[i].frequency = dpm_table->dpm_levels[i].value * 100;
1890 clocks->data[i].latency_in_us =
1891 data->mclk_latency_table.entries[i].latency =
1892 vega12_get_mem_latency(hwmgr, dpm_table->dpm_levels[i].value);
1893 }
1894
1895 clocks->num_levels = data->mclk_latency_table.count = ucount;
1896
1897 return 0;
1898 }
1899
vega12_get_dcefclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)1900 static int vega12_get_dcefclocks(struct pp_hwmgr *hwmgr,
1901 struct pp_clock_levels_with_latency *clocks)
1902 {
1903 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1904 uint32_t ucount;
1905 int i;
1906 struct vega12_single_dpm_table *dpm_table;
1907
1908 if (!data->smu_features[GNLD_DPM_DCEFCLK].enabled)
1909 return -1;
1910
1911
1912 dpm_table = &(data->dpm_table.dcef_table);
1913 ucount = (dpm_table->count > MAX_NUM_CLOCKS) ?
1914 MAX_NUM_CLOCKS : dpm_table->count;
1915
1916 for (i = 0; i < ucount; i++) {
1917 clocks->data[i].clocks_in_khz =
1918 dpm_table->dpm_levels[i].value * 1000;
1919
1920 clocks->data[i].latency_in_us = 0;
1921 }
1922
1923 clocks->num_levels = ucount;
1924
1925 return 0;
1926 }
1927
vega12_get_socclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)1928 static int vega12_get_socclocks(struct pp_hwmgr *hwmgr,
1929 struct pp_clock_levels_with_latency *clocks)
1930 {
1931 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1932 uint32_t ucount;
1933 int i;
1934 struct vega12_single_dpm_table *dpm_table;
1935
1936 if (!data->smu_features[GNLD_DPM_SOCCLK].enabled)
1937 return -1;
1938
1939
1940 dpm_table = &(data->dpm_table.soc_table);
1941 ucount = (dpm_table->count > MAX_NUM_CLOCKS) ?
1942 MAX_NUM_CLOCKS : dpm_table->count;
1943
1944 for (i = 0; i < ucount; i++) {
1945 clocks->data[i].clocks_in_khz =
1946 dpm_table->dpm_levels[i].value * 1000;
1947
1948 clocks->data[i].latency_in_us = 0;
1949 }
1950
1951 clocks->num_levels = ucount;
1952
1953 return 0;
1954
1955 }
1956
vega12_get_clock_by_type_with_latency(struct pp_hwmgr * hwmgr,enum amd_pp_clock_type type,struct pp_clock_levels_with_latency * clocks)1957 static int vega12_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
1958 enum amd_pp_clock_type type,
1959 struct pp_clock_levels_with_latency *clocks)
1960 {
1961 int ret;
1962
1963 switch (type) {
1964 case amd_pp_sys_clock:
1965 ret = vega12_get_sclks(hwmgr, clocks);
1966 break;
1967 case amd_pp_mem_clock:
1968 ret = vega12_get_memclocks(hwmgr, clocks);
1969 break;
1970 case amd_pp_dcef_clock:
1971 ret = vega12_get_dcefclocks(hwmgr, clocks);
1972 break;
1973 case amd_pp_soc_clock:
1974 ret = vega12_get_socclocks(hwmgr, clocks);
1975 break;
1976 default:
1977 return -EINVAL;
1978 }
1979
1980 return ret;
1981 }
1982
vega12_get_clock_by_type_with_voltage(struct pp_hwmgr * hwmgr,enum amd_pp_clock_type type,struct pp_clock_levels_with_voltage * clocks)1983 static int vega12_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
1984 enum amd_pp_clock_type type,
1985 struct pp_clock_levels_with_voltage *clocks)
1986 {
1987 clocks->num_levels = 0;
1988
1989 return 0;
1990 }
1991
vega12_set_watermarks_for_clocks_ranges(struct pp_hwmgr * hwmgr,void * clock_ranges)1992 static int vega12_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
1993 void *clock_ranges)
1994 {
1995 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
1996 Watermarks_t *table = &(data->smc_state_table.water_marks_table);
1997 struct dm_pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges = clock_ranges;
1998
1999 if (!data->registry_data.disable_water_mark &&
2000 data->smu_features[GNLD_DPM_DCEFCLK].supported &&
2001 data->smu_features[GNLD_DPM_SOCCLK].supported) {
2002 smu_set_watermarks_for_clocks_ranges(table, wm_with_clock_ranges);
2003 data->water_marks_bitmap |= WaterMarksExist;
2004 data->water_marks_bitmap &= ~WaterMarksLoaded;
2005 }
2006
2007 return 0;
2008 }
2009
vega12_force_clock_level(struct pp_hwmgr * hwmgr,enum pp_clock_type type,uint32_t mask)2010 static int vega12_force_clock_level(struct pp_hwmgr *hwmgr,
2011 enum pp_clock_type type, uint32_t mask)
2012 {
2013 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2014 uint32_t soft_min_level, soft_max_level, hard_min_level;
2015 int ret = 0;
2016
2017 switch (type) {
2018 case PP_SCLK:
2019 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2020 soft_max_level = mask ? (fls(mask) - 1) : 0;
2021
2022 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2023 data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
2024 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2025 data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
2026
2027 ret = vega12_upload_dpm_min_level(hwmgr);
2028 PP_ASSERT_WITH_CODE(!ret,
2029 "Failed to upload boot level to lowest!",
2030 return ret);
2031
2032 ret = vega12_upload_dpm_max_level(hwmgr);
2033 PP_ASSERT_WITH_CODE(!ret,
2034 "Failed to upload dpm max level to highest!",
2035 return ret);
2036 break;
2037
2038 case PP_MCLK:
2039 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2040 soft_max_level = mask ? (fls(mask) - 1) : 0;
2041
2042 data->dpm_table.mem_table.dpm_state.soft_min_level =
2043 data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
2044 data->dpm_table.mem_table.dpm_state.soft_max_level =
2045 data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
2046
2047 ret = vega12_upload_dpm_min_level(hwmgr);
2048 PP_ASSERT_WITH_CODE(!ret,
2049 "Failed to upload boot level to lowest!",
2050 return ret);
2051
2052 ret = vega12_upload_dpm_max_level(hwmgr);
2053 PP_ASSERT_WITH_CODE(!ret,
2054 "Failed to upload dpm max level to highest!",
2055 return ret);
2056
2057 break;
2058
2059 case PP_SOCCLK:
2060 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2061 soft_max_level = mask ? (fls(mask) - 1) : 0;
2062
2063 if (soft_max_level >= data->dpm_table.soc_table.count) {
2064 pr_err("Clock level specified %d is over max allowed %d\n",
2065 soft_max_level,
2066 data->dpm_table.soc_table.count - 1);
2067 return -EINVAL;
2068 }
2069
2070 data->dpm_table.soc_table.dpm_state.soft_min_level =
2071 data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
2072 data->dpm_table.soc_table.dpm_state.soft_max_level =
2073 data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
2074
2075 ret = vega12_upload_dpm_min_level(hwmgr);
2076 PP_ASSERT_WITH_CODE(!ret,
2077 "Failed to upload boot level to lowest!",
2078 return ret);
2079
2080 ret = vega12_upload_dpm_max_level(hwmgr);
2081 PP_ASSERT_WITH_CODE(!ret,
2082 "Failed to upload dpm max level to highest!",
2083 return ret);
2084
2085 break;
2086
2087 case PP_DCEFCLK:
2088 hard_min_level = mask ? (ffs(mask) - 1) : 0;
2089
2090 if (hard_min_level >= data->dpm_table.dcef_table.count) {
2091 pr_err("Clock level specified %d is over max allowed %d\n",
2092 hard_min_level,
2093 data->dpm_table.dcef_table.count - 1);
2094 return -EINVAL;
2095 }
2096
2097 data->dpm_table.dcef_table.dpm_state.hard_min_level =
2098 data->dpm_table.dcef_table.dpm_levels[hard_min_level].value;
2099
2100 ret = vega12_upload_dpm_min_level(hwmgr);
2101 PP_ASSERT_WITH_CODE(!ret,
2102 "Failed to upload boot level to lowest!",
2103 return ret);
2104
2105 //TODO: Setting DCEFCLK max dpm level is not supported
2106
2107 break;
2108
2109 case PP_PCIE:
2110 break;
2111
2112 default:
2113 break;
2114 }
2115
2116 return 0;
2117 }
2118
vega12_get_ppfeature_status(struct pp_hwmgr * hwmgr,char * buf)2119 static int vega12_get_ppfeature_status(struct pp_hwmgr *hwmgr, char *buf)
2120 {
2121 static const char *ppfeature_name[] = {
2122 "DPM_PREFETCHER",
2123 "GFXCLK_DPM",
2124 "UCLK_DPM",
2125 "SOCCLK_DPM",
2126 "UVD_DPM",
2127 "VCE_DPM",
2128 "ULV",
2129 "MP0CLK_DPM",
2130 "LINK_DPM",
2131 "DCEFCLK_DPM",
2132 "GFXCLK_DS",
2133 "SOCCLK_DS",
2134 "LCLK_DS",
2135 "PPT",
2136 "TDC",
2137 "THERMAL",
2138 "GFX_PER_CU_CG",
2139 "RM",
2140 "DCEFCLK_DS",
2141 "ACDC",
2142 "VR0HOT",
2143 "VR1HOT",
2144 "FW_CTF",
2145 "LED_DISPLAY",
2146 "FAN_CONTROL",
2147 "DIDT",
2148 "GFXOFF",
2149 "CG",
2150 "ACG"};
2151 static const char *output_title[] = {
2152 "FEATURES",
2153 "BITMASK",
2154 "ENABLEMENT"};
2155 uint64_t features_enabled;
2156 int i;
2157 int ret = 0;
2158 int size = 0;
2159
2160 phm_get_sysfs_buf(&buf, &size);
2161
2162 ret = vega12_get_enabled_smc_features(hwmgr, &features_enabled);
2163 PP_ASSERT_WITH_CODE(!ret,
2164 "[EnableAllSmuFeatures] Failed to get enabled smc features!",
2165 return ret);
2166
2167 size += sysfs_emit_at(buf, size, "Current ppfeatures: 0x%016llx\n", features_enabled);
2168 size += sysfs_emit_at(buf, size, "%-19s %-22s %s\n",
2169 output_title[0],
2170 output_title[1],
2171 output_title[2]);
2172 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
2173 size += sysfs_emit_at(buf, size, "%-19s 0x%016llx %6s\n",
2174 ppfeature_name[i],
2175 1ULL << i,
2176 (features_enabled & (1ULL << i)) ? "Y" : "N");
2177 }
2178
2179 return size;
2180 }
2181
vega12_set_ppfeature_status(struct pp_hwmgr * hwmgr,uint64_t new_ppfeature_masks)2182 static int vega12_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfeature_masks)
2183 {
2184 uint64_t features_enabled;
2185 uint64_t features_to_enable;
2186 uint64_t features_to_disable;
2187 int ret = 0;
2188
2189 if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
2190 return -EINVAL;
2191
2192 ret = vega12_get_enabled_smc_features(hwmgr, &features_enabled);
2193 if (ret)
2194 return ret;
2195
2196 features_to_disable =
2197 features_enabled & ~new_ppfeature_masks;
2198 features_to_enable =
2199 ~features_enabled & new_ppfeature_masks;
2200
2201 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
2202 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
2203
2204 if (features_to_disable) {
2205 ret = vega12_enable_smc_features(hwmgr, false, features_to_disable);
2206 if (ret)
2207 return ret;
2208 }
2209
2210 if (features_to_enable) {
2211 ret = vega12_enable_smc_features(hwmgr, true, features_to_enable);
2212 if (ret)
2213 return ret;
2214 }
2215
2216 return 0;
2217 }
2218
vega12_get_current_pcie_link_width_level(struct pp_hwmgr * hwmgr)2219 static int vega12_get_current_pcie_link_width_level(struct pp_hwmgr *hwmgr)
2220 {
2221 struct amdgpu_device *adev = hwmgr->adev;
2222
2223 return (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
2224 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
2225 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
2226 }
2227
vega12_get_current_pcie_link_width(struct pp_hwmgr * hwmgr)2228 static int vega12_get_current_pcie_link_width(struct pp_hwmgr *hwmgr)
2229 {
2230 uint32_t width_level;
2231
2232 width_level = vega12_get_current_pcie_link_width_level(hwmgr);
2233 if (width_level > LINK_WIDTH_MAX)
2234 width_level = 0;
2235
2236 return link_width[width_level];
2237 }
2238
vega12_get_current_pcie_link_speed_level(struct pp_hwmgr * hwmgr)2239 static int vega12_get_current_pcie_link_speed_level(struct pp_hwmgr *hwmgr)
2240 {
2241 struct amdgpu_device *adev = hwmgr->adev;
2242
2243 return (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
2244 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
2245 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
2246 }
2247
vega12_get_current_pcie_link_speed(struct pp_hwmgr * hwmgr)2248 static int vega12_get_current_pcie_link_speed(struct pp_hwmgr *hwmgr)
2249 {
2250 uint32_t speed_level;
2251
2252 speed_level = vega12_get_current_pcie_link_speed_level(hwmgr);
2253 if (speed_level > LINK_SPEED_MAX)
2254 speed_level = 0;
2255
2256 return link_speed[speed_level];
2257 }
2258
vega12_emit_clock_levels(struct pp_hwmgr * hwmgr,enum pp_clock_type type,char * buf,int * offset)2259 static int vega12_emit_clock_levels(struct pp_hwmgr *hwmgr,
2260 enum pp_clock_type type, char *buf,
2261 int *offset)
2262 {
2263 struct pp_clock_levels_with_latency clocks;
2264 int i, now, size = *offset;
2265
2266 switch (type) {
2267 case PP_SCLK:
2268 PP_ASSERT_WITH_CODE(
2269 vega12_get_current_gfx_clk_freq(hwmgr, &now) == 0,
2270 "Attempt to get current gfx clk Failed!",
2271 return -1);
2272
2273 PP_ASSERT_WITH_CODE(
2274 vega12_get_sclks(hwmgr, &clocks) == 0,
2275 "Attempt to get gfx clk levels Failed!",
2276 return -1);
2277 for (i = 0; i < clocks.num_levels; i++)
2278 size += sysfs_emit_at(
2279 buf, size, "%d: %uMhz %s\n", i,
2280 clocks.data[i].clocks_in_khz / 1000,
2281 (clocks.data[i].clocks_in_khz / 1000 ==
2282 now / 100) ?
2283 "*" :
2284 "");
2285 break;
2286
2287 case PP_MCLK:
2288 PP_ASSERT_WITH_CODE(
2289 vega12_get_current_mclk_freq(hwmgr, &now) == 0,
2290 "Attempt to get current mclk freq Failed!",
2291 return -1);
2292
2293 PP_ASSERT_WITH_CODE(
2294 vega12_get_memclocks(hwmgr, &clocks) == 0,
2295 "Attempt to get memory clk levels Failed!",
2296 return -1);
2297 for (i = 0; i < clocks.num_levels; i++)
2298 size += sysfs_emit_at(
2299 buf, size, "%d: %uMhz %s\n", i,
2300 clocks.data[i].clocks_in_khz / 1000,
2301 (clocks.data[i].clocks_in_khz / 1000 ==
2302 now / 100) ?
2303 "*" :
2304 "");
2305 break;
2306
2307 case PP_SOCCLK:
2308 PP_ASSERT_WITH_CODE(
2309 smum_send_msg_to_smc_with_parameter(hwmgr,
2310 PPSMC_MSG_GetDpmClockFreq, (PPCLK_SOCCLK << 16),
2311 &now) == 0,
2312 "Attempt to get Current SOCCLK Frequency Failed!",
2313 return -EINVAL);
2314
2315 PP_ASSERT_WITH_CODE(
2316 vega12_get_socclocks(hwmgr, &clocks) == 0,
2317 "Attempt to get soc clk levels Failed!",
2318 return -1);
2319 for (i = 0; i < clocks.num_levels; i++)
2320 size += sysfs_emit_at(
2321 buf, size, "%d: %uMhz %s\n", i,
2322 clocks.data[i].clocks_in_khz / 1000,
2323 (clocks.data[i].clocks_in_khz / 1000 == now) ?
2324 "*" :
2325 "");
2326 break;
2327
2328 case PP_DCEFCLK:
2329 PP_ASSERT_WITH_CODE(
2330 smum_send_msg_to_smc_with_parameter(hwmgr,
2331 PPSMC_MSG_GetDpmClockFreq, (PPCLK_DCEFCLK << 16),
2332 &now) == 0,
2333 "Attempt to get Current DCEFCLK Frequency Failed!",
2334 return -EINVAL);
2335
2336 PP_ASSERT_WITH_CODE(
2337 vega12_get_dcefclocks(hwmgr, &clocks) == 0,
2338 "Attempt to get dcef clk levels Failed!",
2339 return -1);
2340 for (i = 0; i < clocks.num_levels; i++)
2341 size += sysfs_emit_at(
2342 buf, size, "%d: %uMhz %s\n", i,
2343 clocks.data[i].clocks_in_khz / 1000,
2344 (clocks.data[i].clocks_in_khz / 1000 == now) ?
2345 "*" :
2346 "");
2347 break;
2348
2349 case PP_PCIE:
2350 break;
2351
2352 default:
2353 break;
2354 }
2355
2356 *offset = size;
2357
2358 return 0;
2359 }
2360
vega12_apply_clocks_adjust_rules(struct pp_hwmgr * hwmgr)2361 static int vega12_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
2362 {
2363 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2364 struct vega12_single_dpm_table *dpm_table;
2365 bool vblank_too_short = false;
2366 bool disable_mclk_switching;
2367 uint32_t i, latency;
2368
2369 disable_mclk_switching = ((1 < hwmgr->display_config->num_display) &&
2370 !hwmgr->display_config->multi_monitor_in_sync) ||
2371 vblank_too_short;
2372 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
2373
2374 /* gfxclk */
2375 dpm_table = &(data->dpm_table.gfx_table);
2376 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2377 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2378 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2379 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2380
2381 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2382 if (VEGA12_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) {
2383 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_GFXCLK_LEVEL].value;
2384 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_GFXCLK_LEVEL].value;
2385 }
2386
2387 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
2388 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2389 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
2390 }
2391
2392 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2393 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2394 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2395 }
2396 }
2397
2398 /* memclk */
2399 dpm_table = &(data->dpm_table.mem_table);
2400 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2401 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2402 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2403 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2404
2405 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2406 if (VEGA12_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) {
2407 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_MCLK_LEVEL].value;
2408 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_MCLK_LEVEL].value;
2409 }
2410
2411 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
2412 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2413 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
2414 }
2415
2416 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2417 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2418 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2419 }
2420 }
2421
2422 /* honour DAL's UCLK Hardmin */
2423 if (dpm_table->dpm_state.hard_min_level < (hwmgr->display_config->min_mem_set_clock / 100))
2424 dpm_table->dpm_state.hard_min_level = hwmgr->display_config->min_mem_set_clock / 100;
2425
2426 /* Hardmin is dependent on displayconfig */
2427 if (disable_mclk_switching) {
2428 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2429 for (i = 0; i < data->mclk_latency_table.count - 1; i++) {
2430 if (data->mclk_latency_table.entries[i].latency <= latency) {
2431 if (dpm_table->dpm_levels[i].value >= (hwmgr->display_config->min_mem_set_clock / 100)) {
2432 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[i].value;
2433 break;
2434 }
2435 }
2436 }
2437 }
2438
2439 if (hwmgr->display_config->nb_pstate_switch_disable)
2440 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2441
2442 /* vclk */
2443 dpm_table = &(data->dpm_table.vclk_table);
2444 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2445 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2446 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2447 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2448
2449 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2450 if (VEGA12_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
2451 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_UVDCLK_LEVEL].value;
2452 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_UVDCLK_LEVEL].value;
2453 }
2454
2455 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2456 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2457 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2458 }
2459 }
2460
2461 /* dclk */
2462 dpm_table = &(data->dpm_table.dclk_table);
2463 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2464 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2465 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2466 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2467
2468 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2469 if (VEGA12_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
2470 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_UVDCLK_LEVEL].value;
2471 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_UVDCLK_LEVEL].value;
2472 }
2473
2474 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2475 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2476 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2477 }
2478 }
2479
2480 /* socclk */
2481 dpm_table = &(data->dpm_table.soc_table);
2482 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2483 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2484 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2485 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2486
2487 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2488 if (VEGA12_UMD_PSTATE_SOCCLK_LEVEL < dpm_table->count) {
2489 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_SOCCLK_LEVEL].value;
2490 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_SOCCLK_LEVEL].value;
2491 }
2492
2493 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2494 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2495 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2496 }
2497 }
2498
2499 /* eclk */
2500 dpm_table = &(data->dpm_table.eclk_table);
2501 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
2502 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2503 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
2504 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2505
2506 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
2507 if (VEGA12_UMD_PSTATE_VCEMCLK_LEVEL < dpm_table->count) {
2508 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_VCEMCLK_LEVEL].value;
2509 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA12_UMD_PSTATE_VCEMCLK_LEVEL].value;
2510 }
2511
2512 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2513 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2514 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2515 }
2516 }
2517
2518 return 0;
2519 }
2520
vega12_set_uclk_to_highest_dpm_level(struct pp_hwmgr * hwmgr,struct vega12_single_dpm_table * dpm_table)2521 static int vega12_set_uclk_to_highest_dpm_level(struct pp_hwmgr *hwmgr,
2522 struct vega12_single_dpm_table *dpm_table)
2523 {
2524 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2525 int ret = 0;
2526
2527 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
2528 PP_ASSERT_WITH_CODE(dpm_table->count > 0,
2529 "[SetUclkToHightestDpmLevel] Dpm table has no entry!",
2530 return -EINVAL);
2531 PP_ASSERT_WITH_CODE(dpm_table->count <= NUM_UCLK_DPM_LEVELS,
2532 "[SetUclkToHightestDpmLevel] Dpm table has too many entries!",
2533 return -EINVAL);
2534
2535 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
2536 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(hwmgr,
2537 PPSMC_MSG_SetHardMinByFreq,
2538 (PPCLK_UCLK << 16) | dpm_table->dpm_state.hard_min_level,
2539 NULL)),
2540 "[SetUclkToHightestDpmLevel] Set hard min uclk failed!",
2541 return ret);
2542 }
2543
2544 return ret;
2545 }
2546
vega12_pre_display_configuration_changed_task(struct pp_hwmgr * hwmgr)2547 static int vega12_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
2548 {
2549 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2550 int ret = 0;
2551
2552 smum_send_msg_to_smc_with_parameter(hwmgr,
2553 PPSMC_MSG_NumOfDisplays, 0,
2554 NULL);
2555
2556 ret = vega12_set_uclk_to_highest_dpm_level(hwmgr,
2557 &data->dpm_table.mem_table);
2558
2559 return ret;
2560 }
2561
vega12_display_configuration_changed_task(struct pp_hwmgr * hwmgr)2562 static int vega12_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
2563 {
2564 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2565 int result = 0;
2566 Watermarks_t *wm_table = &(data->smc_state_table.water_marks_table);
2567
2568 if ((data->water_marks_bitmap & WaterMarksExist) &&
2569 !(data->water_marks_bitmap & WaterMarksLoaded)) {
2570 result = smum_smc_table_manager(hwmgr,
2571 (uint8_t *)wm_table, TABLE_WATERMARKS, false);
2572 PP_ASSERT_WITH_CODE(result, "Failed to update WMTABLE!", return -EINVAL);
2573 data->water_marks_bitmap |= WaterMarksLoaded;
2574 }
2575
2576 if ((data->water_marks_bitmap & WaterMarksExist) &&
2577 data->smu_features[GNLD_DPM_DCEFCLK].supported &&
2578 data->smu_features[GNLD_DPM_SOCCLK].supported)
2579 smum_send_msg_to_smc_with_parameter(hwmgr,
2580 PPSMC_MSG_NumOfDisplays, hwmgr->display_config->num_display,
2581 NULL);
2582
2583 return result;
2584 }
2585
vega12_enable_disable_uvd_dpm(struct pp_hwmgr * hwmgr,bool enable)2586 static int vega12_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
2587 {
2588 struct vega12_hwmgr *data =
2589 (struct vega12_hwmgr *)(hwmgr->backend);
2590
2591 if (data->smu_features[GNLD_DPM_UVD].supported) {
2592 PP_ASSERT_WITH_CODE(!vega12_enable_smc_features(hwmgr,
2593 enable,
2594 data->smu_features[GNLD_DPM_UVD].smu_feature_bitmap),
2595 "Attempt to Enable/Disable DPM UVD Failed!",
2596 return -1);
2597 data->smu_features[GNLD_DPM_UVD].enabled = enable;
2598 }
2599
2600 return 0;
2601 }
2602
vega12_power_gate_vce(struct pp_hwmgr * hwmgr,bool bgate)2603 static void vega12_power_gate_vce(struct pp_hwmgr *hwmgr, bool bgate)
2604 {
2605 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2606
2607 if (data->vce_power_gated == bgate)
2608 return;
2609
2610 data->vce_power_gated = bgate;
2611 vega12_enable_disable_vce_dpm(hwmgr, !bgate);
2612 }
2613
vega12_power_gate_uvd(struct pp_hwmgr * hwmgr,bool bgate)2614 static void vega12_power_gate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
2615 {
2616 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2617
2618 if (data->uvd_power_gated == bgate)
2619 return;
2620
2621 data->uvd_power_gated = bgate;
2622 vega12_enable_disable_uvd_dpm(hwmgr, !bgate);
2623 }
2624
2625 static bool
vega12_check_smc_update_required_for_display_configuration(struct pp_hwmgr * hwmgr)2626 vega12_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
2627 {
2628 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2629 bool is_update_required = false;
2630
2631 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
2632 is_update_required = true;
2633
2634 if (data->registry_data.gfx_clk_deep_sleep_support) {
2635 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr)
2636 is_update_required = true;
2637 }
2638
2639 return is_update_required;
2640 }
2641
vega12_disable_dpm_tasks(struct pp_hwmgr * hwmgr)2642 static int vega12_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
2643 {
2644 int tmp_result, result = 0;
2645
2646 tmp_result = vega12_disable_all_smu_features(hwmgr);
2647 PP_ASSERT_WITH_CODE((tmp_result == 0),
2648 "Failed to disable all smu features!", result = tmp_result);
2649
2650 return result;
2651 }
2652
vega12_power_off_asic(struct pp_hwmgr * hwmgr)2653 static int vega12_power_off_asic(struct pp_hwmgr *hwmgr)
2654 {
2655 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2656 int result;
2657
2658 result = vega12_disable_dpm_tasks(hwmgr);
2659 PP_ASSERT_WITH_CODE((0 == result),
2660 "[disable_dpm_tasks] Failed to disable DPM!",
2661 );
2662 data->water_marks_bitmap &= ~(WaterMarksLoaded);
2663
2664 return result;
2665 }
2666
2667 #if 0
2668 static void vega12_find_min_clock_index(struct pp_hwmgr *hwmgr,
2669 uint32_t *sclk_idx, uint32_t *mclk_idx,
2670 uint32_t min_sclk, uint32_t min_mclk)
2671 {
2672 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2673 struct vega12_dpm_table *dpm_table = &(data->dpm_table);
2674 uint32_t i;
2675
2676 for (i = 0; i < dpm_table->gfx_table.count; i++) {
2677 if (dpm_table->gfx_table.dpm_levels[i].enabled &&
2678 dpm_table->gfx_table.dpm_levels[i].value >= min_sclk) {
2679 *sclk_idx = i;
2680 break;
2681 }
2682 }
2683
2684 for (i = 0; i < dpm_table->mem_table.count; i++) {
2685 if (dpm_table->mem_table.dpm_levels[i].enabled &&
2686 dpm_table->mem_table.dpm_levels[i].value >= min_mclk) {
2687 *mclk_idx = i;
2688 break;
2689 }
2690 }
2691 }
2692 #endif
2693
2694 #if 0
2695 static int vega12_set_power_profile_state(struct pp_hwmgr *hwmgr,
2696 struct amd_pp_profile *request)
2697 {
2698 return 0;
2699 }
2700
2701 static int vega12_get_sclk_od(struct pp_hwmgr *hwmgr)
2702 {
2703 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2704 struct vega12_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
2705 struct vega12_single_dpm_table *golden_sclk_table =
2706 &(data->golden_dpm_table.gfx_table);
2707 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
2708 int golden_value = golden_sclk_table->dpm_levels
2709 [golden_sclk_table->count - 1].value;
2710
2711 value -= golden_value;
2712 value = DIV_ROUND_UP(value * 100, golden_value);
2713
2714 return value;
2715 }
2716
2717 static int vega12_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
2718 {
2719 return 0;
2720 }
2721
2722 static int vega12_get_mclk_od(struct pp_hwmgr *hwmgr)
2723 {
2724 struct vega12_hwmgr *data = (struct vega12_hwmgr *)(hwmgr->backend);
2725 struct vega12_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
2726 struct vega12_single_dpm_table *golden_mclk_table =
2727 &(data->golden_dpm_table.mem_table);
2728 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
2729 int golden_value = golden_mclk_table->dpm_levels
2730 [golden_mclk_table->count - 1].value;
2731
2732 value -= golden_value;
2733 value = DIV_ROUND_UP(value * 100, golden_value);
2734
2735 return value;
2736 }
2737
2738 static int vega12_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
2739 {
2740 return 0;
2741 }
2742 #endif
2743
vega12_notify_cac_buffer_info(struct pp_hwmgr * hwmgr,uint32_t virtual_addr_low,uint32_t virtual_addr_hi,uint32_t mc_addr_low,uint32_t mc_addr_hi,uint32_t size)2744 static int vega12_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
2745 uint32_t virtual_addr_low,
2746 uint32_t virtual_addr_hi,
2747 uint32_t mc_addr_low,
2748 uint32_t mc_addr_hi,
2749 uint32_t size)
2750 {
2751 smum_send_msg_to_smc_with_parameter(hwmgr,
2752 PPSMC_MSG_SetSystemVirtualDramAddrHigh,
2753 virtual_addr_hi,
2754 NULL);
2755 smum_send_msg_to_smc_with_parameter(hwmgr,
2756 PPSMC_MSG_SetSystemVirtualDramAddrLow,
2757 virtual_addr_low,
2758 NULL);
2759 smum_send_msg_to_smc_with_parameter(hwmgr,
2760 PPSMC_MSG_DramLogSetDramAddrHigh,
2761 mc_addr_hi,
2762 NULL);
2763
2764 smum_send_msg_to_smc_with_parameter(hwmgr,
2765 PPSMC_MSG_DramLogSetDramAddrLow,
2766 mc_addr_low,
2767 NULL);
2768
2769 smum_send_msg_to_smc_with_parameter(hwmgr,
2770 PPSMC_MSG_DramLogSetDramSize,
2771 size,
2772 NULL);
2773 return 0;
2774 }
2775
vega12_get_thermal_temperature_range(struct pp_hwmgr * hwmgr,struct PP_TemperatureRange * thermal_data)2776 static int vega12_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
2777 struct PP_TemperatureRange *thermal_data)
2778 {
2779 struct phm_ppt_v3_information *pptable_information =
2780 (struct phm_ppt_v3_information *)hwmgr->pptable;
2781 struct vega12_hwmgr *data =
2782 (struct vega12_hwmgr *)(hwmgr->backend);
2783 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2784
2785 memcpy(thermal_data, &SMU7ThermalWithDelayPolicy[0], sizeof(struct PP_TemperatureRange));
2786
2787 thermal_data->max = pp_table->TedgeLimit *
2788 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2789 thermal_data->edge_emergency_max = (pp_table->TedgeLimit + CTF_OFFSET_EDGE) *
2790 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2791 thermal_data->hotspot_crit_max = pp_table->ThotspotLimit *
2792 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2793 thermal_data->hotspot_emergency_max = (pp_table->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
2794 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2795 thermal_data->mem_crit_max = pp_table->ThbmLimit *
2796 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2797 thermal_data->mem_emergency_max = (pp_table->ThbmLimit + CTF_OFFSET_HBM)*
2798 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2799 thermal_data->sw_ctf_threshold = pptable_information->us_software_shutdown_temp *
2800 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
2801
2802 return 0;
2803 }
2804
vega12_enable_gfx_off(struct pp_hwmgr * hwmgr)2805 static int vega12_enable_gfx_off(struct pp_hwmgr *hwmgr)
2806 {
2807 struct vega12_hwmgr *data =
2808 (struct vega12_hwmgr *)(hwmgr->backend);
2809 int ret = 0;
2810
2811 if (data->gfxoff_controlled_by_driver)
2812 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_AllowGfxOff, NULL);
2813
2814 return ret;
2815 }
2816
vega12_disable_gfx_off(struct pp_hwmgr * hwmgr)2817 static int vega12_disable_gfx_off(struct pp_hwmgr *hwmgr)
2818 {
2819 struct vega12_hwmgr *data =
2820 (struct vega12_hwmgr *)(hwmgr->backend);
2821 int ret = 0;
2822
2823 if (data->gfxoff_controlled_by_driver)
2824 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_DisallowGfxOff, NULL);
2825
2826 return ret;
2827 }
2828
vega12_gfx_off_control(struct pp_hwmgr * hwmgr,bool enable)2829 static int vega12_gfx_off_control(struct pp_hwmgr *hwmgr, bool enable)
2830 {
2831 if (enable)
2832 return vega12_enable_gfx_off(hwmgr);
2833 else
2834 return vega12_disable_gfx_off(hwmgr);
2835 }
2836
vega12_get_performance_level(struct pp_hwmgr * hwmgr,const struct pp_hw_power_state * state,PHM_PerformanceLevelDesignation designation,uint32_t index,PHM_PerformanceLevel * level)2837 static int vega12_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
2838 PHM_PerformanceLevelDesignation designation, uint32_t index,
2839 PHM_PerformanceLevel *level)
2840 {
2841 return 0;
2842 }
2843
vega12_set_mp1_state(struct pp_hwmgr * hwmgr,enum pp_mp1_state mp1_state)2844 static int vega12_set_mp1_state(struct pp_hwmgr *hwmgr,
2845 enum pp_mp1_state mp1_state)
2846 {
2847 uint16_t msg;
2848 int ret;
2849
2850 switch (mp1_state) {
2851 case PP_MP1_STATE_UNLOAD:
2852 msg = PPSMC_MSG_PrepareMp1ForUnload;
2853 break;
2854 case PP_MP1_STATE_SHUTDOWN:
2855 case PP_MP1_STATE_RESET:
2856 case PP_MP1_STATE_NONE:
2857 default:
2858 return 0;
2859 }
2860
2861 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc(hwmgr, msg, NULL)) == 0,
2862 "[PrepareMp1] Failed!",
2863 return ret);
2864
2865 return 0;
2866 }
2867
vega12_init_gpu_metrics_v1_0(struct gpu_metrics_v1_0 * gpu_metrics)2868 static void vega12_init_gpu_metrics_v1_0(struct gpu_metrics_v1_0 *gpu_metrics)
2869 {
2870 memset(gpu_metrics, 0xFF, sizeof(struct gpu_metrics_v1_0));
2871
2872 gpu_metrics->common_header.structure_size =
2873 sizeof(struct gpu_metrics_v1_0);
2874 gpu_metrics->common_header.format_revision = 1;
2875 gpu_metrics->common_header.content_revision = 0;
2876
2877 gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
2878 }
2879
vega12_get_gpu_metrics(struct pp_hwmgr * hwmgr,void ** table)2880 static ssize_t vega12_get_gpu_metrics(struct pp_hwmgr *hwmgr,
2881 void **table)
2882 {
2883 struct vega12_hwmgr *data =
2884 (struct vega12_hwmgr *)(hwmgr->backend);
2885 struct gpu_metrics_v1_0 *gpu_metrics =
2886 &data->gpu_metrics_table;
2887 SmuMetrics_t metrics;
2888 uint32_t fan_speed_rpm;
2889 int ret;
2890
2891 ret = vega12_get_metrics_table(hwmgr, &metrics, true);
2892 if (ret)
2893 return ret;
2894
2895 vega12_init_gpu_metrics_v1_0(gpu_metrics);
2896
2897 gpu_metrics->temperature_edge = metrics.TemperatureEdge;
2898 gpu_metrics->temperature_hotspot = metrics.TemperatureHotspot;
2899 gpu_metrics->temperature_mem = metrics.TemperatureHBM;
2900 gpu_metrics->temperature_vrgfx = metrics.TemperatureVrGfx;
2901 gpu_metrics->temperature_vrmem = metrics.TemperatureVrMem;
2902
2903 gpu_metrics->average_gfx_activity = metrics.AverageGfxActivity;
2904 gpu_metrics->average_umc_activity = metrics.AverageUclkActivity;
2905
2906 gpu_metrics->average_gfxclk_frequency = metrics.AverageGfxclkFrequency;
2907 gpu_metrics->average_socclk_frequency = metrics.AverageSocclkFrequency;
2908 gpu_metrics->average_uclk_frequency = metrics.AverageUclkFrequency;
2909
2910 gpu_metrics->current_gfxclk = metrics.CurrClock[PPCLK_GFXCLK];
2911 gpu_metrics->current_socclk = metrics.CurrClock[PPCLK_SOCCLK];
2912 gpu_metrics->current_uclk = metrics.CurrClock[PPCLK_UCLK];
2913 gpu_metrics->current_vclk0 = metrics.CurrClock[PPCLK_VCLK];
2914 gpu_metrics->current_dclk0 = metrics.CurrClock[PPCLK_DCLK];
2915
2916 gpu_metrics->throttle_status = metrics.ThrottlerStatus;
2917
2918 vega12_fan_ctrl_get_fan_speed_rpm(hwmgr, &fan_speed_rpm);
2919 gpu_metrics->current_fan_speed = (uint16_t)fan_speed_rpm;
2920
2921 gpu_metrics->pcie_link_width =
2922 vega12_get_current_pcie_link_width(hwmgr);
2923 gpu_metrics->pcie_link_speed =
2924 vega12_get_current_pcie_link_speed(hwmgr);
2925
2926 *table = (void *)gpu_metrics;
2927
2928 return sizeof(struct gpu_metrics_v1_0);
2929 }
2930
2931 static const struct pp_hwmgr_func vega12_hwmgr_funcs = {
2932 .backend_init = vega12_hwmgr_backend_init,
2933 .backend_fini = vega12_hwmgr_backend_fini,
2934 .asic_setup = vega12_setup_asic_task,
2935 .dynamic_state_management_enable = vega12_enable_dpm_tasks,
2936 .dynamic_state_management_disable = vega12_disable_dpm_tasks,
2937 .patch_boot_state = vega12_patch_boot_state,
2938 .get_sclk = vega12_dpm_get_sclk,
2939 .get_mclk = vega12_dpm_get_mclk,
2940 .notify_smc_display_config_after_ps_adjustment =
2941 vega12_notify_smc_display_config_after_ps_adjustment,
2942 .force_dpm_level = vega12_dpm_force_dpm_level,
2943 .stop_thermal_controller = vega12_thermal_stop_thermal_controller,
2944 .get_fan_speed_info = vega12_fan_ctrl_get_fan_speed_info,
2945 .reset_fan_speed_to_default =
2946 vega12_fan_ctrl_reset_fan_speed_to_default,
2947 .get_fan_speed_rpm = vega12_fan_ctrl_get_fan_speed_rpm,
2948 .set_fan_control_mode = vega12_set_fan_control_mode,
2949 .get_fan_control_mode = vega12_get_fan_control_mode,
2950 .read_sensor = vega12_read_sensor,
2951 .get_clock_by_type_with_latency = vega12_get_clock_by_type_with_latency,
2952 .get_clock_by_type_with_voltage = vega12_get_clock_by_type_with_voltage,
2953 .set_watermarks_for_clocks_ranges = vega12_set_watermarks_for_clocks_ranges,
2954 .display_clock_voltage_request = vega12_display_clock_voltage_request,
2955 .force_clock_level = vega12_force_clock_level,
2956 .emit_clock_levels = vega12_emit_clock_levels,
2957 .apply_clocks_adjust_rules =
2958 vega12_apply_clocks_adjust_rules,
2959 .pre_display_config_changed =
2960 vega12_pre_display_configuration_changed_task,
2961 .display_config_changed = vega12_display_configuration_changed_task,
2962 .powergate_uvd = vega12_power_gate_uvd,
2963 .powergate_vce = vega12_power_gate_vce,
2964 .check_smc_update_required_for_display_configuration =
2965 vega12_check_smc_update_required_for_display_configuration,
2966 .power_off_asic = vega12_power_off_asic,
2967 .disable_smc_firmware_ctf = vega12_thermal_disable_alert,
2968 #if 0
2969 .set_power_profile_state = vega12_set_power_profile_state,
2970 .get_sclk_od = vega12_get_sclk_od,
2971 .set_sclk_od = vega12_set_sclk_od,
2972 .get_mclk_od = vega12_get_mclk_od,
2973 .set_mclk_od = vega12_set_mclk_od,
2974 #endif
2975 .notify_cac_buffer_info = vega12_notify_cac_buffer_info,
2976 .get_thermal_temperature_range = vega12_get_thermal_temperature_range,
2977 .register_irq_handlers = smu9_register_irq_handlers,
2978 .start_thermal_controller = vega12_start_thermal_controller,
2979 .powergate_gfx = vega12_gfx_off_control,
2980 .get_performance_level = vega12_get_performance_level,
2981 .get_bamaco_support = smu9_get_bamaco_support,
2982 .get_asic_baco_state = smu9_baco_get_state,
2983 .set_asic_baco_state = vega12_baco_set_state,
2984 .get_ppfeature_status = vega12_get_ppfeature_status,
2985 .set_ppfeature_status = vega12_set_ppfeature_status,
2986 .set_mp1_state = vega12_set_mp1_state,
2987 .get_gpu_metrics = vega12_get_gpu_metrics,
2988 };
2989
vega12_hwmgr_init(struct pp_hwmgr * hwmgr)2990 int vega12_hwmgr_init(struct pp_hwmgr *hwmgr)
2991 {
2992 hwmgr->hwmgr_func = &vega12_hwmgr_funcs;
2993 hwmgr->pptable_func = &vega12_pptable_funcs;
2994
2995 return 0;
2996 }
2997