]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/amd/powerplay/smu_v11_0.c
drm/amd/powerplay: simplify the interface of get_gpu_power
[linux.git] / drivers / gpu / drm / amd / powerplay / smu_v11_0.c
1 /*
2  * Copyright 2019 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 #include "pp_debug.h"
24 #include <linux/firmware.h>
25 #include "amdgpu.h"
26 #include "amdgpu_smu.h"
27 #include "atomfirmware.h"
28 #include "amdgpu_atomfirmware.h"
29 #include "smu_v11_0.h"
30 #include "soc15_common.h"
31 #include "atom.h"
32 #include "vega20_ppt.h"
33 #include "navi10_ppt.h"
34 #include "pp_thermal.h"
35
36 #include "asic_reg/thm/thm_11_0_2_offset.h"
37 #include "asic_reg/thm/thm_11_0_2_sh_mask.h"
38 #include "asic_reg/mp/mp_11_0_offset.h"
39 #include "asic_reg/mp/mp_11_0_sh_mask.h"
40 #include "asic_reg/nbio/nbio_7_4_offset.h"
41 #include "asic_reg/smuio/smuio_11_0_0_offset.h"
42 #include "asic_reg/smuio/smuio_11_0_0_sh_mask.h"
43
44 MODULE_FIRMWARE("amdgpu/vega20_smc.bin");
45 MODULE_FIRMWARE("amdgpu/navi10_smc.bin");
46
47 #define SMU11_THERMAL_MINIMUM_ALERT_TEMP      0
48 #define SMU11_THERMAL_MAXIMUM_ALERT_TEMP      255
49
50 #define SMU11_TEMPERATURE_UNITS_PER_CENTIGRADES 1000
51 #define SMU11_VOLTAGE_SCALE 4
52
53 static int smu_v11_0_send_msg_without_waiting(struct smu_context *smu,
54                                               uint16_t msg)
55 {
56         struct amdgpu_device *adev = smu->adev;
57         WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_66, msg);
58         return 0;
59 }
60
61 static int smu_v11_0_read_arg(struct smu_context *smu, uint32_t *arg)
62 {
63         struct amdgpu_device *adev = smu->adev;
64
65         *arg = RREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_82);
66         return 0;
67 }
68
69 static int smu_v11_0_wait_for_response(struct smu_context *smu)
70 {
71         struct amdgpu_device *adev = smu->adev;
72         uint32_t cur_value, i;
73
74         for (i = 0; i < adev->usec_timeout; i++) {
75                 cur_value = RREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90);
76                 if ((cur_value & MP1_C2PMSG_90__CONTENT_MASK) != 0)
77                         break;
78                 udelay(1);
79         }
80
81         /* timeout means wrong logic */
82         if (i == adev->usec_timeout)
83                 return -ETIME;
84
85         return RREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90) == 0x1 ? 0 : -EIO;
86 }
87
88 static int smu_v11_0_send_msg(struct smu_context *smu, uint16_t msg)
89 {
90         struct amdgpu_device *adev = smu->adev;
91         int ret = 0, index = 0;
92
93         index = smu_msg_get_index(smu, msg);
94         if (index < 0)
95                 return index;
96
97         smu_v11_0_wait_for_response(smu);
98
99         WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
100
101         smu_v11_0_send_msg_without_waiting(smu, (uint16_t)index);
102
103         ret = smu_v11_0_wait_for_response(smu);
104
105         if (ret)
106                 pr_err("Failed to send message 0x%x, response 0x%x\n", index,
107                        ret);
108
109         return ret;
110
111 }
112
113 static int
114 smu_v11_0_send_msg_with_param(struct smu_context *smu, uint16_t msg,
115                               uint32_t param)
116 {
117
118         struct amdgpu_device *adev = smu->adev;
119         int ret = 0, index = 0;
120
121         index = smu_msg_get_index(smu, msg);
122         if (index < 0)
123                 return index;
124
125         ret = smu_v11_0_wait_for_response(smu);
126         if (ret)
127                 pr_err("Failed to send message 0x%x, response 0x%x, param 0x%x\n",
128                        index, ret, param);
129
130         WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_90, 0);
131
132         WREG32_SOC15(MP1, 0, mmMP1_SMN_C2PMSG_82, param);
133
134         smu_v11_0_send_msg_without_waiting(smu, (uint16_t)index);
135
136         ret = smu_v11_0_wait_for_response(smu);
137         if (ret)
138                 pr_err("Failed to send message 0x%x, response 0x%x param 0x%x\n",
139                        index, ret, param);
140
141         return ret;
142 }
143
144 static int smu_v11_0_init_microcode(struct smu_context *smu)
145 {
146         struct amdgpu_device *adev = smu->adev;
147         const char *chip_name;
148         char fw_name[30];
149         int err = 0;
150         const struct smc_firmware_header_v1_0 *hdr;
151         const struct common_firmware_header *header;
152         struct amdgpu_firmware_info *ucode = NULL;
153
154         switch (adev->asic_type) {
155         case CHIP_VEGA20:
156                 chip_name = "vega20";
157                 break;
158         case CHIP_NAVI10:
159                 chip_name = "navi10";
160                 break;
161         default:
162                 BUG();
163         }
164
165         snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_smc.bin", chip_name);
166
167         err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
168         if (err)
169                 goto out;
170         err = amdgpu_ucode_validate(adev->pm.fw);
171         if (err)
172                 goto out;
173
174         hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
175         amdgpu_ucode_print_smc_hdr(&hdr->header);
176         adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
177
178         if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
179                 ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
180                 ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
181                 ucode->fw = adev->pm.fw;
182                 header = (const struct common_firmware_header *)ucode->fw->data;
183                 adev->firmware.fw_size +=
184                         ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
185         }
186
187 out:
188         if (err) {
189                 DRM_ERROR("smu_v11_0: Failed to load firmware \"%s\"\n",
190                           fw_name);
191                 release_firmware(adev->pm.fw);
192                 adev->pm.fw = NULL;
193         }
194         return err;
195 }
196
197 static int smu_v11_0_load_microcode(struct smu_context *smu)
198 {
199         struct amdgpu_device *adev = smu->adev;
200         const uint32_t *src;
201         const struct smc_firmware_header_v1_0 *hdr;
202         uint32_t addr_start = MP1_SRAM;
203         uint32_t i;
204         uint32_t mp1_fw_flags;
205
206         hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
207         src = (const uint32_t *)(adev->pm.fw->data +
208                 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
209
210         for (i = 1; i < MP1_SMC_SIZE/4 - 1; i++) {
211                 WREG32_PCIE(addr_start, src[i]);
212                 addr_start += 4;
213         }
214
215         WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
216                 1 & MP1_SMN_PUB_CTRL__RESET_MASK);
217         WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
218                 1 & ~MP1_SMN_PUB_CTRL__RESET_MASK);
219
220         for (i = 0; i < adev->usec_timeout; i++) {
221                 mp1_fw_flags = RREG32_PCIE(MP1_Public |
222                         (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
223                 if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
224                         MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
225                         break;
226                 udelay(1);
227         }
228
229         if (i == adev->usec_timeout)
230                 return -ETIME;
231
232         return 0;
233 }
234
235 static int smu_v11_0_check_fw_status(struct smu_context *smu)
236 {
237         struct amdgpu_device *adev = smu->adev;
238         uint32_t mp1_fw_flags;
239
240         mp1_fw_flags = RREG32_PCIE(MP1_Public |
241                                    (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
242
243         if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
244             MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
245                 return 0;
246
247         return -EIO;
248 }
249
250 static int smu_v11_0_check_fw_version(struct smu_context *smu)
251 {
252         uint32_t if_version = 0xff, smu_version = 0xff;
253         uint16_t smu_major;
254         uint8_t smu_minor, smu_debug;
255         int ret = 0;
256
257         ret = smu_get_smc_version(smu, &if_version, &smu_version);
258         if (ret)
259                 return ret;
260
261         smu_major = (smu_version >> 16) & 0xffff;
262         smu_minor = (smu_version >> 8) & 0xff;
263         smu_debug = (smu_version >> 0) & 0xff;
264
265         pr_info("SMU Driver IF Version = 0x%08x, SMU FW Version = 0x%08x (%d.%d.%d)\n",
266                 if_version, smu_version, smu_major, smu_minor, smu_debug);
267
268         if (if_version != smu->smc_if_version) {
269                 pr_err("SMU driver if version not matched\n");
270                 ret = -EINVAL;
271         }
272
273         return ret;
274 }
275
276 static int smu_v11_0_set_pptable_v2_0(struct smu_context *smu, void **table, uint32_t *size)
277 {
278         struct amdgpu_device *adev = smu->adev;
279         uint32_t ppt_offset_bytes;
280         const struct smc_firmware_header_v2_0 *v2;
281
282         v2 = (const struct smc_firmware_header_v2_0 *) adev->pm.fw->data;
283
284         ppt_offset_bytes = le32_to_cpu(v2->ppt_offset_bytes);
285         *size = le32_to_cpu(v2->ppt_size_bytes);
286         *table = (uint8_t *)v2 + ppt_offset_bytes;
287
288         return 0;
289 }
290
291 static int smu_v11_0_set_pptable_v2_1(struct smu_context *smu, void **table, uint32_t *size, uint32_t pptable_id)
292 {
293         struct amdgpu_device *adev = smu->adev;
294         const struct smc_firmware_header_v2_1 *v2_1;
295         struct smc_soft_pptable_entry *entries;
296         uint32_t pptable_count = 0;
297         int i = 0;
298
299         v2_1 = (const struct smc_firmware_header_v2_1 *) adev->pm.fw->data;
300         entries = (struct smc_soft_pptable_entry *)
301                 ((uint8_t *)v2_1 + le32_to_cpu(v2_1->pptable_entry_offset));
302         pptable_count = le32_to_cpu(v2_1->pptable_count);
303         for (i = 0; i < pptable_count; i++) {
304                 if (le32_to_cpu(entries[i].id) == pptable_id) {
305                         *table = ((uint8_t *)v2_1 + le32_to_cpu(entries[i].ppt_offset_bytes));
306                         *size = le32_to_cpu(entries[i].ppt_size_bytes);
307                         break;
308                 }
309         }
310
311         if (i == pptable_count)
312                 return -EINVAL;
313
314         return 0;
315 }
316
317 static int smu_v11_0_setup_pptable(struct smu_context *smu)
318 {
319         struct amdgpu_device *adev = smu->adev;
320         const struct smc_firmware_header_v1_0 *hdr;
321         int ret, index;
322         uint32_t size;
323         uint8_t frev, crev;
324         void *table;
325         uint16_t version_major, version_minor;
326
327         hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
328         version_major = le16_to_cpu(hdr->header.header_version_major);
329         version_minor = le16_to_cpu(hdr->header.header_version_minor);
330         if (version_major == 2 && smu->smu_table.boot_values.pp_table_id > 0) {
331                 switch (version_minor) {
332                 case 0:
333                         ret = smu_v11_0_set_pptable_v2_0(smu, &table, &size);
334                         break;
335                 case 1:
336                         ret = smu_v11_0_set_pptable_v2_1(smu, &table, &size,
337                                                          smu->smu_table.boot_values.pp_table_id);
338                         break;
339                 default:
340                         ret = -EINVAL;
341                         break;
342                 }
343                 if (ret)
344                         return ret;
345
346         } else {
347                 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
348                                                     powerplayinfo);
349
350                 ret = smu_get_atom_data_table(smu, index, (uint16_t *)&size, &frev, &crev,
351                                               (uint8_t **)&table);
352                 if (ret)
353                         return ret;
354         }
355
356         if (!smu->smu_table.power_play_table)
357                 smu->smu_table.power_play_table = table;
358         if (!smu->smu_table.power_play_table_size)
359                 smu->smu_table.power_play_table_size = size;
360
361         return 0;
362 }
363
364 static int smu_v11_0_init_dpm_context(struct smu_context *smu)
365 {
366         struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
367
368         if (smu_dpm->dpm_context || smu_dpm->dpm_context_size != 0)
369                 return -EINVAL;
370
371         return smu_alloc_dpm_context(smu);
372 }
373
374 static int smu_v11_0_fini_dpm_context(struct smu_context *smu)
375 {
376         struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
377
378         if (!smu_dpm->dpm_context || smu_dpm->dpm_context_size == 0)
379                 return -EINVAL;
380
381         kfree(smu_dpm->dpm_context);
382         kfree(smu_dpm->golden_dpm_context);
383         kfree(smu_dpm->dpm_current_power_state);
384         kfree(smu_dpm->dpm_request_power_state);
385         smu_dpm->dpm_context = NULL;
386         smu_dpm->golden_dpm_context = NULL;
387         smu_dpm->dpm_context_size = 0;
388         smu_dpm->dpm_current_power_state = NULL;
389         smu_dpm->dpm_request_power_state = NULL;
390
391         return 0;
392 }
393
394 static int smu_v11_0_init_smc_tables(struct smu_context *smu)
395 {
396         struct smu_table_context *smu_table = &smu->smu_table;
397         struct smu_table *tables = NULL;
398         int ret = 0;
399
400         if (smu_table->tables || smu_table->table_count == 0)
401                 return -EINVAL;
402
403         tables = kcalloc(SMU_TABLE_COUNT, sizeof(struct smu_table),
404                          GFP_KERNEL);
405         if (!tables)
406                 return -ENOMEM;
407
408         smu_table->tables = tables;
409
410         smu_tables_init(smu, tables);
411
412         ret = smu_v11_0_init_dpm_context(smu);
413         if (ret)
414                 return ret;
415
416         return 0;
417 }
418
419 static int smu_v11_0_fini_smc_tables(struct smu_context *smu)
420 {
421         struct smu_table_context *smu_table = &smu->smu_table;
422         int ret = 0;
423
424         if (!smu_table->tables || smu_table->table_count == 0)
425                 return -EINVAL;
426
427         kfree(smu_table->tables);
428         smu_table->tables = NULL;
429         smu_table->table_count = 0;
430
431         ret = smu_v11_0_fini_dpm_context(smu);
432         if (ret)
433                 return ret;
434         return 0;
435 }
436
437 static int smu_v11_0_init_power(struct smu_context *smu)
438 {
439         struct smu_power_context *smu_power = &smu->smu_power;
440
441         if (!smu->pm_enabled)
442                 return 0;
443         if (smu_power->power_context || smu_power->power_context_size != 0)
444                 return -EINVAL;
445
446         smu_power->power_context = kzalloc(sizeof(struct smu_11_0_dpm_context),
447                                            GFP_KERNEL);
448         if (!smu_power->power_context)
449                 return -ENOMEM;
450         smu_power->power_context_size = sizeof(struct smu_11_0_dpm_context);
451
452         smu->metrics_time = 0;
453         smu->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
454         if (!smu->metrics_table) {
455                 kfree(smu_power->power_context);
456                 return -ENOMEM;
457         }
458
459         return 0;
460 }
461
462 static int smu_v11_0_fini_power(struct smu_context *smu)
463 {
464         struct smu_power_context *smu_power = &smu->smu_power;
465
466         if (!smu->pm_enabled)
467                 return 0;
468         if (!smu_power->power_context || smu_power->power_context_size == 0)
469                 return -EINVAL;
470
471         kfree(smu->metrics_table);
472         kfree(smu_power->power_context);
473         smu->metrics_table = NULL;
474         smu_power->power_context = NULL;
475         smu_power->power_context_size = 0;
476
477         return 0;
478 }
479
480 int smu_v11_0_get_vbios_bootup_values(struct smu_context *smu)
481 {
482         int ret, index;
483         uint16_t size;
484         uint8_t frev, crev;
485         struct atom_common_table_header *header;
486         struct atom_firmware_info_v3_3 *v_3_3;
487         struct atom_firmware_info_v3_1 *v_3_1;
488
489         index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
490                                             firmwareinfo);
491
492         ret = smu_get_atom_data_table(smu, index, &size, &frev, &crev,
493                                       (uint8_t **)&header);
494         if (ret)
495                 return ret;
496
497         if (header->format_revision != 3) {
498                 pr_err("unknown atom_firmware_info version! for smu11\n");
499                 return -EINVAL;
500         }
501
502         switch (header->content_revision) {
503         case 0:
504         case 1:
505         case 2:
506                 v_3_1 = (struct atom_firmware_info_v3_1 *)header;
507                 smu->smu_table.boot_values.revision = v_3_1->firmware_revision;
508                 smu->smu_table.boot_values.gfxclk = v_3_1->bootup_sclk_in10khz;
509                 smu->smu_table.boot_values.uclk = v_3_1->bootup_mclk_in10khz;
510                 smu->smu_table.boot_values.socclk = 0;
511                 smu->smu_table.boot_values.dcefclk = 0;
512                 smu->smu_table.boot_values.vddc = v_3_1->bootup_vddc_mv;
513                 smu->smu_table.boot_values.vddci = v_3_1->bootup_vddci_mv;
514                 smu->smu_table.boot_values.mvddc = v_3_1->bootup_mvddc_mv;
515                 smu->smu_table.boot_values.vdd_gfx = v_3_1->bootup_vddgfx_mv;
516                 smu->smu_table.boot_values.cooling_id = v_3_1->coolingsolution_id;
517                 smu->smu_table.boot_values.pp_table_id = 0;
518                 break;
519         case 3:
520         default:
521                 v_3_3 = (struct atom_firmware_info_v3_3 *)header;
522                 smu->smu_table.boot_values.revision = v_3_3->firmware_revision;
523                 smu->smu_table.boot_values.gfxclk = v_3_3->bootup_sclk_in10khz;
524                 smu->smu_table.boot_values.uclk = v_3_3->bootup_mclk_in10khz;
525                 smu->smu_table.boot_values.socclk = 0;
526                 smu->smu_table.boot_values.dcefclk = 0;
527                 smu->smu_table.boot_values.vddc = v_3_3->bootup_vddc_mv;
528                 smu->smu_table.boot_values.vddci = v_3_3->bootup_vddci_mv;
529                 smu->smu_table.boot_values.mvddc = v_3_3->bootup_mvddc_mv;
530                 smu->smu_table.boot_values.vdd_gfx = v_3_3->bootup_vddgfx_mv;
531                 smu->smu_table.boot_values.cooling_id = v_3_3->coolingsolution_id;
532                 smu->smu_table.boot_values.pp_table_id = v_3_3->pplib_pptable_id;
533         }
534
535         return 0;
536 }
537
538 static int smu_v11_0_get_clk_info_from_vbios(struct smu_context *smu)
539 {
540         int ret, index;
541         struct amdgpu_device *adev = smu->adev;
542         struct atom_get_smu_clock_info_parameters_v3_1 input = {0};
543         struct atom_get_smu_clock_info_output_parameters_v3_1 *output;
544
545         input.clk_id = SMU11_SYSPLL0_SOCCLK_ID;
546         input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
547         index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
548                                             getsmuclockinfo);
549
550         ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
551                                         (uint32_t *)&input);
552         if (ret)
553                 return -EINVAL;
554
555         output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
556         smu->smu_table.boot_values.socclk = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
557
558         memset(&input, 0, sizeof(input));
559         input.clk_id = SMU11_SYSPLL0_DCEFCLK_ID;
560         input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
561         index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
562                                             getsmuclockinfo);
563
564         ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
565                                         (uint32_t *)&input);
566         if (ret)
567                 return -EINVAL;
568
569         output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
570         smu->smu_table.boot_values.dcefclk = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
571
572         memset(&input, 0, sizeof(input));
573         input.clk_id = SMU11_SYSPLL0_ECLK_ID;
574         input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
575         index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
576                                             getsmuclockinfo);
577
578         ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
579                                         (uint32_t *)&input);
580         if (ret)
581                 return -EINVAL;
582
583         output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
584         smu->smu_table.boot_values.eclk = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
585
586         memset(&input, 0, sizeof(input));
587         input.clk_id = SMU11_SYSPLL0_VCLK_ID;
588         input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
589         index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
590                                             getsmuclockinfo);
591
592         ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
593                                         (uint32_t *)&input);
594         if (ret)
595                 return -EINVAL;
596
597         output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
598         smu->smu_table.boot_values.vclk = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
599
600         memset(&input, 0, sizeof(input));
601         input.clk_id = SMU11_SYSPLL0_DCLK_ID;
602         input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
603         index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
604                                             getsmuclockinfo);
605
606         ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
607                                         (uint32_t *)&input);
608         if (ret)
609                 return -EINVAL;
610
611         output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
612         smu->smu_table.boot_values.dclk = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
613
614         return 0;
615 }
616
617 static int smu_v11_0_notify_memory_pool_location(struct smu_context *smu)
618 {
619         struct smu_table_context *smu_table = &smu->smu_table;
620         struct smu_table *memory_pool = &smu_table->memory_pool;
621         int ret = 0;
622         uint64_t address;
623         uint32_t address_low, address_high;
624
625         if (memory_pool->size == 0 || memory_pool->cpu_addr == NULL)
626                 return ret;
627
628         address = (uintptr_t)memory_pool->cpu_addr;
629         address_high = (uint32_t)upper_32_bits(address);
630         address_low  = (uint32_t)lower_32_bits(address);
631
632         ret = smu_send_smc_msg_with_param(smu,
633                                           SMU_MSG_SetSystemVirtualDramAddrHigh,
634                                           address_high);
635         if (ret)
636                 return ret;
637         ret = smu_send_smc_msg_with_param(smu,
638                                           SMU_MSG_SetSystemVirtualDramAddrLow,
639                                           address_low);
640         if (ret)
641                 return ret;
642
643         address = memory_pool->mc_address;
644         address_high = (uint32_t)upper_32_bits(address);
645         address_low  = (uint32_t)lower_32_bits(address);
646
647         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrHigh,
648                                           address_high);
649         if (ret)
650                 return ret;
651         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrLow,
652                                           address_low);
653         if (ret)
654                 return ret;
655         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramSize,
656                                           (uint32_t)memory_pool->size);
657         if (ret)
658                 return ret;
659
660         return ret;
661 }
662
663 static int smu_v11_0_check_pptable(struct smu_context *smu)
664 {
665         int ret;
666
667         ret = smu_check_powerplay_table(smu);
668         return ret;
669 }
670
671 static int smu_v11_0_parse_pptable(struct smu_context *smu)
672 {
673         int ret;
674
675         struct smu_table_context *table_context = &smu->smu_table;
676         struct smu_table *table = &table_context->tables[SMU_TABLE_PPTABLE];
677
678         if (table_context->driver_pptable)
679                 return -EINVAL;
680
681         table_context->driver_pptable = kzalloc(table->size, GFP_KERNEL);
682
683         if (!table_context->driver_pptable)
684                 return -ENOMEM;
685
686         ret = smu_store_powerplay_table(smu);
687         if (ret)
688                 return -EINVAL;
689
690         ret = smu_append_powerplay_table(smu);
691
692         return ret;
693 }
694
695 static int smu_v11_0_populate_smc_pptable(struct smu_context *smu)
696 {
697         int ret;
698
699         ret = smu_set_default_dpm_table(smu);
700
701         return ret;
702 }
703
704 static int smu_v11_0_write_pptable(struct smu_context *smu)
705 {
706         struct smu_table_context *table_context = &smu->smu_table;
707         int ret = 0;
708
709         ret = smu_update_table(smu, SMU_TABLE_PPTABLE,
710                                table_context->driver_pptable, true);
711
712         return ret;
713 }
714
715 static int smu_v11_0_write_watermarks_table(struct smu_context *smu)
716 {
717         int ret = 0;
718         struct smu_table_context *smu_table = &smu->smu_table;
719         struct smu_table *table = NULL;
720
721         table = &smu_table->tables[SMU_TABLE_WATERMARKS];
722         if (!table)
723                 return -EINVAL;
724
725         if (!table->cpu_addr)
726                 return -EINVAL;
727
728         ret = smu_update_table(smu, SMU_TABLE_WATERMARKS, table->cpu_addr,
729                                 true);
730
731         return ret;
732 }
733
734 static int smu_v11_0_set_deep_sleep_dcefclk(struct smu_context *smu, uint32_t clk)
735 {
736         int ret;
737
738         ret = smu_send_smc_msg_with_param(smu,
739                                           SMU_MSG_SetMinDeepSleepDcefclk, clk);
740         if (ret)
741                 pr_err("SMU11 attempt to set divider for DCEFCLK Failed!");
742
743         return ret;
744 }
745
746 static int smu_v11_0_set_min_dcef_deep_sleep(struct smu_context *smu)
747 {
748         struct smu_table_context *table_context = &smu->smu_table;
749
750         if (!smu->pm_enabled)
751                 return 0;
752         if (!table_context)
753                 return -EINVAL;
754
755         return smu_set_deep_sleep_dcefclk(smu,
756                                           table_context->boot_values.dcefclk / 100);
757 }
758
759 static int smu_v11_0_set_tool_table_location(struct smu_context *smu)
760 {
761         int ret = 0;
762         struct smu_table *tool_table = &smu->smu_table.tables[SMU_TABLE_PMSTATUSLOG];
763
764         if (tool_table->mc_address) {
765                 ret = smu_send_smc_msg_with_param(smu,
766                                 SMU_MSG_SetToolsDramAddrHigh,
767                                 upper_32_bits(tool_table->mc_address));
768                 if (!ret)
769                         ret = smu_send_smc_msg_with_param(smu,
770                                 SMU_MSG_SetToolsDramAddrLow,
771                                 lower_32_bits(tool_table->mc_address));
772         }
773
774         return ret;
775 }
776
777 static int smu_v11_0_init_display(struct smu_context *smu)
778 {
779         int ret = 0;
780
781         if (!smu->pm_enabled)
782                 return ret;
783         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, 0);
784         return ret;
785 }
786
787 static int smu_v11_0_update_feature_enable_state(struct smu_context *smu, uint32_t feature_id, bool enabled)
788 {
789         uint32_t feature_low = 0, feature_high = 0;
790         int ret = 0;
791
792         if (!smu->pm_enabled)
793                 return ret;
794         if (feature_id >= 0 && feature_id < 31)
795                 feature_low = (1 << feature_id);
796         else if (feature_id > 31 && feature_id < 63)
797                 feature_high = (1 << feature_id);
798         else
799                 return -EINVAL;
800
801         if (enabled) {
802                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_EnableSmuFeaturesLow,
803                                                   feature_low);
804                 if (ret)
805                         return ret;
806                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_EnableSmuFeaturesHigh,
807                                                   feature_high);
808                 if (ret)
809                         return ret;
810
811         } else {
812                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DisableSmuFeaturesLow,
813                                                   feature_low);
814                 if (ret)
815                         return ret;
816                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_DisableSmuFeaturesHigh,
817                                                   feature_high);
818                 if (ret)
819                         return ret;
820
821         }
822
823         return ret;
824 }
825
826 static int smu_v11_0_set_allowed_mask(struct smu_context *smu)
827 {
828         struct smu_feature *feature = &smu->smu_feature;
829         int ret = 0;
830         uint32_t feature_mask[2];
831
832         mutex_lock(&feature->mutex);
833         if (bitmap_empty(feature->allowed, SMU_FEATURE_MAX) || feature->feature_num < 64)
834                 goto failed;
835
836         bitmap_copy((unsigned long *)feature_mask, feature->allowed, 64);
837
838         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskHigh,
839                                           feature_mask[1]);
840         if (ret)
841                 goto failed;
842
843         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskLow,
844                                           feature_mask[0]);
845         if (ret)
846                 goto failed;
847
848 failed:
849         mutex_unlock(&feature->mutex);
850         return ret;
851 }
852
853 static int smu_v11_0_get_enabled_mask(struct smu_context *smu,
854                                       uint32_t *feature_mask, uint32_t num)
855 {
856         uint32_t feature_mask_high = 0, feature_mask_low = 0;
857         int ret = 0;
858
859         if (!feature_mask || num < 2)
860                 return -EINVAL;
861
862         ret = smu_send_smc_msg(smu, SMU_MSG_GetEnabledSmuFeaturesHigh);
863         if (ret)
864                 return ret;
865         ret = smu_read_smc_arg(smu, &feature_mask_high);
866         if (ret)
867                 return ret;
868
869         ret = smu_send_smc_msg(smu, SMU_MSG_GetEnabledSmuFeaturesLow);
870         if (ret)
871                 return ret;
872         ret = smu_read_smc_arg(smu, &feature_mask_low);
873         if (ret)
874                 return ret;
875
876         feature_mask[0] = feature_mask_low;
877         feature_mask[1] = feature_mask_high;
878
879         return ret;
880 }
881
882 static int smu_v11_0_system_features_control(struct smu_context *smu,
883                                              bool en)
884 {
885         struct smu_feature *feature = &smu->smu_feature;
886         uint32_t feature_mask[2];
887         int ret = 0;
888
889         if (smu->pm_enabled) {
890                 ret = smu_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
891                                              SMU_MSG_DisableAllSmuFeatures));
892                 if (ret)
893                         return ret;
894         }
895
896         ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
897         if (ret)
898                 return ret;
899
900         bitmap_copy(feature->enabled, (unsigned long *)&feature_mask,
901                     feature->feature_num);
902         bitmap_copy(feature->supported, (unsigned long *)&feature_mask,
903                     feature->feature_num);
904
905         return ret;
906 }
907
908 static int smu_v11_0_notify_display_change(struct smu_context *smu)
909 {
910         int ret = 0;
911
912         if (!smu->pm_enabled)
913                 return ret;
914         if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT) &&
915             smu->adev->gmc.vram_type == AMDGPU_VRAM_TYPE_HBM)
916                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1);
917
918         return ret;
919 }
920
921 static int
922 smu_v11_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,
923                                     enum smu_clk_type clock_select)
924 {
925         int ret = 0;
926
927         if (!smu->pm_enabled)
928                 return ret;
929         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
930                                           smu_clk_get_index(smu, clock_select) << 16);
931         if (ret) {
932                 pr_err("[GetMaxSustainableClock] Failed to get max DC clock from SMC!");
933                 return ret;
934         }
935
936         ret = smu_read_smc_arg(smu, clock);
937         if (ret)
938                 return ret;
939
940         if (*clock != 0)
941                 return 0;
942
943         /* if DC limit is zero, return AC limit */
944         ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetMaxDpmFreq,
945                                           smu_clk_get_index(smu, clock_select) << 16);
946         if (ret) {
947                 pr_err("[GetMaxSustainableClock] failed to get max AC clock from SMC!");
948                 return ret;
949         }
950
951         ret = smu_read_smc_arg(smu, clock);
952
953         return ret;
954 }
955
956 static int smu_v11_0_init_max_sustainable_clocks(struct smu_context *smu)
957 {
958         struct smu_11_0_max_sustainable_clocks *max_sustainable_clocks;
959         int ret = 0;
960
961         max_sustainable_clocks = kzalloc(sizeof(struct smu_11_0_max_sustainable_clocks),
962                                          GFP_KERNEL);
963         smu->smu_table.max_sustainable_clocks = (void *)max_sustainable_clocks;
964
965         max_sustainable_clocks->uclock = smu->smu_table.boot_values.uclk / 100;
966         max_sustainable_clocks->soc_clock = smu->smu_table.boot_values.socclk / 100;
967         max_sustainable_clocks->dcef_clock = smu->smu_table.boot_values.dcefclk / 100;
968         max_sustainable_clocks->display_clock = 0xFFFFFFFF;
969         max_sustainable_clocks->phy_clock = 0xFFFFFFFF;
970         max_sustainable_clocks->pixel_clock = 0xFFFFFFFF;
971
972         if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
973                 ret = smu_v11_0_get_max_sustainable_clock(smu,
974                                                           &(max_sustainable_clocks->uclock),
975                                                           SMU_UCLK);
976                 if (ret) {
977                         pr_err("[%s] failed to get max UCLK from SMC!",
978                                __func__);
979                         return ret;
980                 }
981         }
982
983         if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
984                 ret = smu_v11_0_get_max_sustainable_clock(smu,
985                                                           &(max_sustainable_clocks->soc_clock),
986                                                           SMU_SOCCLK);
987                 if (ret) {
988                         pr_err("[%s] failed to get max SOCCLK from SMC!",
989                                __func__);
990                         return ret;
991                 }
992         }
993
994         if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
995                 ret = smu_v11_0_get_max_sustainable_clock(smu,
996                                                           &(max_sustainable_clocks->dcef_clock),
997                                                           SMU_DCEFCLK);
998                 if (ret) {
999                         pr_err("[%s] failed to get max DCEFCLK from SMC!",
1000                                __func__);
1001                         return ret;
1002                 }
1003
1004                 ret = smu_v11_0_get_max_sustainable_clock(smu,
1005                                                           &(max_sustainable_clocks->display_clock),
1006                                                           SMU_DISPCLK);
1007                 if (ret) {
1008                         pr_err("[%s] failed to get max DISPCLK from SMC!",
1009                                __func__);
1010                         return ret;
1011                 }
1012                 ret = smu_v11_0_get_max_sustainable_clock(smu,
1013                                                           &(max_sustainable_clocks->phy_clock),
1014                                                           SMU_PHYCLK);
1015                 if (ret) {
1016                         pr_err("[%s] failed to get max PHYCLK from SMC!",
1017                                __func__);
1018                         return ret;
1019                 }
1020                 ret = smu_v11_0_get_max_sustainable_clock(smu,
1021                                                           &(max_sustainable_clocks->pixel_clock),
1022                                                           SMU_PIXCLK);
1023                 if (ret) {
1024                         pr_err("[%s] failed to get max PIXCLK from SMC!",
1025                                __func__);
1026                         return ret;
1027                 }
1028         }
1029
1030         if (max_sustainable_clocks->soc_clock < max_sustainable_clocks->uclock)
1031                 max_sustainable_clocks->uclock = max_sustainable_clocks->soc_clock;
1032
1033         return 0;
1034 }
1035
1036 static int smu_v11_0_get_power_limit(struct smu_context *smu,
1037                                      uint32_t *limit,
1038                                      bool get_default)
1039 {
1040         int ret = 0;
1041
1042         if (get_default) {
1043                 mutex_lock(&smu->mutex);
1044                 *limit = smu->default_power_limit;
1045                 if (smu->od_enabled) {
1046                         *limit *= (100 + smu->smu_table.TDPODLimit);
1047                         *limit /= 100;
1048                 }
1049                 mutex_unlock(&smu->mutex);
1050         } else {
1051                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetPptLimit,
1052                         smu_power_get_index(smu, SMU_POWER_SOURCE_AC) << 16);
1053                 if (ret) {
1054                         pr_err("[%s] get PPT limit failed!", __func__);
1055                         return ret;
1056                 }
1057                 smu_read_smc_arg(smu, limit);
1058                 smu->power_limit = *limit;
1059         }
1060
1061         return ret;
1062 }
1063
1064 static int smu_v11_0_set_power_limit(struct smu_context *smu, uint32_t n)
1065 {
1066         uint32_t max_power_limit;
1067         int ret = 0;
1068
1069         if (n == 0)
1070                 n = smu->default_power_limit;
1071
1072         max_power_limit = smu->default_power_limit;
1073
1074         if (smu->od_enabled) {
1075                 max_power_limit *= (100 + smu->smu_table.TDPODLimit);
1076                 max_power_limit /= 100;
1077         }
1078
1079         if (smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT))
1080                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n);
1081         if (ret) {
1082                 pr_err("[%s] Set power limit Failed!", __func__);
1083                 return ret;
1084         }
1085
1086         return ret;
1087 }
1088
1089 static int smu_v11_0_get_current_clk_freq(struct smu_context *smu,
1090                                           enum smu_clk_type clk_id,
1091                                           uint32_t *value)
1092 {
1093         int ret = 0;
1094         uint32_t freq;
1095
1096         if (clk_id >= SMU_CLK_COUNT || !value)
1097                 return -EINVAL;
1098
1099         /* if don't has GetDpmClockFreq Message, try get current clock by SmuMetrics_t */
1100         if (smu_msg_get_index(smu, SMU_MSG_GetDpmClockFreq) == 0)
1101                 ret =  smu_get_current_clk_freq_by_table(smu, clk_id, &freq);
1102         else {
1103                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDpmClockFreq,
1104                                                   (smu_clk_get_index(smu, clk_id) << 16));
1105                 if (ret)
1106                         return ret;
1107
1108                 ret = smu_read_smc_arg(smu, &freq);
1109                 if (ret)
1110                         return ret;
1111         }
1112
1113         freq *= 100;
1114         *value = freq;
1115
1116         return ret;
1117 }
1118
1119 static int smu_v11_0_get_thermal_range(struct smu_context *smu,
1120                                 struct PP_TemperatureRange *range)
1121 {
1122         PPTable_t *pptable = smu->smu_table.driver_pptable;
1123         memcpy(range, &SMU7ThermalWithDelayPolicy[0], sizeof(struct PP_TemperatureRange));
1124
1125         range->max = pptable->TedgeLimit *
1126                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1127         range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE) *
1128                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1129         range->hotspot_crit_max = pptable->ThotspotLimit *
1130                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1131         range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
1132                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1133         range->mem_crit_max = pptable->ThbmLimit *
1134                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1135         range->mem_emergency_max = (pptable->ThbmLimit + CTF_OFFSET_HBM)*
1136                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1137
1138         return 0;
1139 }
1140
1141 static int smu_v11_0_set_thermal_range(struct smu_context *smu,
1142                         struct PP_TemperatureRange *range)
1143 {
1144         struct amdgpu_device *adev = smu->adev;
1145         int low = SMU11_THERMAL_MINIMUM_ALERT_TEMP *
1146                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1147         int high = SMU11_THERMAL_MAXIMUM_ALERT_TEMP *
1148                 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1149         uint32_t val;
1150
1151         if (low < range->min)
1152                 low = range->min;
1153         if (high > range->max)
1154                 high = range->max;
1155
1156         if (low > high)
1157                 return -EINVAL;
1158
1159         val = RREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL);
1160         val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);
1161         val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);
1162         val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
1163         val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low / PP_TEMPERATURE_UNITS_PER_CENTIGRADES));
1164         val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);
1165
1166         WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_CTRL, val);
1167
1168         return 0;
1169 }
1170
1171 static int smu_v11_0_enable_thermal_alert(struct smu_context *smu)
1172 {
1173         struct amdgpu_device *adev = smu->adev;
1174         uint32_t val = 0;
1175
1176         val |= (1 << THM_THERMAL_INT_ENA__THERM_INTH_CLR__SHIFT);
1177         val |= (1 << THM_THERMAL_INT_ENA__THERM_INTL_CLR__SHIFT);
1178         val |= (1 << THM_THERMAL_INT_ENA__THERM_TRIGGER_CLR__SHIFT);
1179
1180         WREG32_SOC15(THM, 0, mmTHM_THERMAL_INT_ENA, val);
1181
1182         return 0;
1183 }
1184
1185 static int smu_v11_0_start_thermal_control(struct smu_context *smu)
1186 {
1187         int ret = 0;
1188         struct PP_TemperatureRange range = {
1189                 TEMP_RANGE_MIN,
1190                 TEMP_RANGE_MAX,
1191                 TEMP_RANGE_MAX,
1192                 TEMP_RANGE_MIN,
1193                 TEMP_RANGE_MAX,
1194                 TEMP_RANGE_MAX,
1195                 TEMP_RANGE_MIN,
1196                 TEMP_RANGE_MAX,
1197                 TEMP_RANGE_MAX};
1198         struct amdgpu_device *adev = smu->adev;
1199
1200         if (!smu->pm_enabled)
1201                 return ret;
1202         smu_v11_0_get_thermal_range(smu, &range);
1203
1204         if (smu->smu_table.thermal_controller_type) {
1205                 ret = smu_v11_0_set_thermal_range(smu, &range);
1206                 if (ret)
1207                         return ret;
1208
1209                 ret = smu_v11_0_enable_thermal_alert(smu);
1210                 if (ret)
1211                         return ret;
1212                 ret = smu_set_thermal_fan_table(smu);
1213                 if (ret)
1214                         return ret;
1215         }
1216
1217         adev->pm.dpm.thermal.min_temp = range.min;
1218         adev->pm.dpm.thermal.max_temp = range.max;
1219         adev->pm.dpm.thermal.max_edge_emergency_temp = range.edge_emergency_max;
1220         adev->pm.dpm.thermal.min_hotspot_temp = range.hotspot_min;
1221         adev->pm.dpm.thermal.max_hotspot_crit_temp = range.hotspot_crit_max;
1222         adev->pm.dpm.thermal.max_hotspot_emergency_temp = range.hotspot_emergency_max;
1223         adev->pm.dpm.thermal.min_mem_temp = range.mem_min;
1224         adev->pm.dpm.thermal.max_mem_crit_temp = range.mem_crit_max;
1225         adev->pm.dpm.thermal.max_mem_emergency_temp = range.mem_emergency_max;
1226
1227         return ret;
1228 }
1229
1230 static int smu_v11_0_get_metrics_table(struct smu_context *smu,
1231                 SmuMetrics_t *metrics_table)
1232 {
1233         int ret = 0;
1234
1235         if (!smu->metrics_time || time_after(jiffies, smu->metrics_time + HZ / 1000)) {
1236                 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS,
1237                                 (void *)metrics_table, false);
1238                 if (ret) {
1239                         pr_info("Failed to export SMU metrics table!\n");
1240                         return ret;
1241                 }
1242                 memcpy(smu->metrics_table, metrics_table, sizeof(SmuMetrics_t));
1243                 smu->metrics_time = jiffies;
1244         } else
1245                 memcpy(metrics_table, smu->metrics_table, sizeof(SmuMetrics_t));
1246
1247         return ret;
1248 }
1249
1250 static int smu_v11_0_thermal_get_temperature(struct smu_context *smu,
1251                                              enum amd_pp_sensors sensor,
1252                                              uint32_t *value)
1253 {
1254         struct amdgpu_device *adev = smu->adev;
1255         SmuMetrics_t metrics;
1256         uint32_t temp = 0;
1257         int ret = 0;
1258
1259         if (!value)
1260                 return -EINVAL;
1261
1262         ret = smu_v11_0_get_metrics_table(smu, &metrics);
1263         if (ret)
1264                 return ret;
1265
1266         switch (sensor) {
1267         case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1268                 temp = RREG32_SOC15(THM, 0, mmCG_MULT_THERMAL_STATUS);
1269                 temp = (temp & CG_MULT_THERMAL_STATUS__CTF_TEMP_MASK) >>
1270                                 CG_MULT_THERMAL_STATUS__CTF_TEMP__SHIFT;
1271
1272                 temp = temp & 0x1ff;
1273                 temp *= SMU11_TEMPERATURE_UNITS_PER_CENTIGRADES;
1274
1275                 *value = temp;
1276                 break;
1277         case AMDGPU_PP_SENSOR_EDGE_TEMP:
1278                 *value = metrics.TemperatureEdge *
1279                         PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1280                 break;
1281         case AMDGPU_PP_SENSOR_MEM_TEMP:
1282                 *value = metrics.TemperatureHBM *
1283                         PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1284                 break;
1285         default:
1286                 pr_err("Invalid sensor for retrieving temp\n");
1287                 return -EINVAL;
1288         }
1289
1290         return 0;
1291 }
1292
1293 static uint16_t convert_to_vddc(uint8_t vid)
1294 {
1295         return (uint16_t) ((6200 - (vid * 25)) / SMU11_VOLTAGE_SCALE);
1296 }
1297
1298 static int smu_v11_0_get_gfx_vdd(struct smu_context *smu, uint32_t *value)
1299 {
1300         struct amdgpu_device *adev = smu->adev;
1301         uint32_t vdd = 0, val_vid = 0;
1302
1303         if (!value)
1304                 return -EINVAL;
1305         val_vid = (RREG32_SOC15(SMUIO, 0, mmSMUSVI0_TEL_PLANE0) &
1306                 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR_MASK) >>
1307                 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR__SHIFT;
1308
1309         vdd = (uint32_t)convert_to_vddc((uint8_t)val_vid);
1310
1311         *value = vdd;
1312
1313         return 0;
1314
1315 }
1316
1317 static int smu_v11_0_read_sensor(struct smu_context *smu,
1318                                  enum amd_pp_sensors sensor,
1319                                  void *data, uint32_t *size)
1320 {
1321         int ret = 0;
1322         switch (sensor) {
1323         case AMDGPU_PP_SENSOR_GFX_MCLK:
1324                 ret = smu_get_current_clk_freq(smu, SMU_UCLK, (uint32_t *)data);
1325                 *size = 4;
1326                 break;
1327         case AMDGPU_PP_SENSOR_GFX_SCLK:
1328                 ret = smu_get_current_clk_freq(smu, SMU_GFXCLK, (uint32_t *)data);
1329                 *size = 4;
1330                 break;
1331         case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1332         case AMDGPU_PP_SENSOR_EDGE_TEMP:
1333         case AMDGPU_PP_SENSOR_MEM_TEMP:
1334                 ret = smu_v11_0_thermal_get_temperature(smu, sensor, (uint32_t *)data);
1335                 *size = 4;
1336                 break;
1337         case AMDGPU_PP_SENSOR_VDDGFX:
1338                 ret = smu_v11_0_get_gfx_vdd(smu, (uint32_t *)data);
1339                 *size = 4;
1340                 break;
1341         case AMDGPU_PP_SENSOR_MIN_FAN_RPM:
1342                 *(uint32_t *)data = 0;
1343                 *size = 4;
1344                 break;
1345         default:
1346                 ret = smu_common_read_sensor(smu, sensor, data, size);
1347                 break;
1348         }
1349
1350         /* try get sensor data by asic */
1351         if (ret)
1352                 ret = smu_asic_read_sensor(smu, sensor, data, size);
1353
1354         if (ret)
1355                 *size = 0;
1356
1357         return ret;
1358 }
1359
1360 static int
1361 smu_v11_0_display_clock_voltage_request(struct smu_context *smu,
1362                                         struct pp_display_clock_request
1363                                         *clock_req)
1364 {
1365         enum amd_pp_clock_type clk_type = clock_req->clock_type;
1366         int ret = 0;
1367         enum smu_clk_type clk_select = 0;
1368         uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
1369
1370         if (!smu->pm_enabled)
1371                 return -EINVAL;
1372         if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
1373                 switch (clk_type) {
1374                 case amd_pp_dcef_clock:
1375                         clk_select = SMU_DCEFCLK;
1376                         break;
1377                 case amd_pp_disp_clock:
1378                         clk_select = SMU_DISPCLK;
1379                         break;
1380                 case amd_pp_pixel_clock:
1381                         clk_select = SMU_PIXCLK;
1382                         break;
1383                 case amd_pp_phy_clock:
1384                         clk_select = SMU_PHYCLK;
1385                         break;
1386                 default:
1387                         pr_info("[%s] Invalid Clock Type!", __func__);
1388                         ret = -EINVAL;
1389                         break;
1390                 }
1391
1392                 if (ret)
1393                         goto failed;
1394
1395                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinByFreq,
1396                         (smu_clk_get_index(smu, clk_select) << 16) | clk_freq);
1397         }
1398
1399 failed:
1400         return ret;
1401 }
1402
1403 static int
1404 smu_v11_0_set_watermarks_for_clock_ranges(struct smu_context *smu, struct
1405                                           dm_pp_wm_sets_with_clock_ranges_soc15
1406                                           *clock_ranges)
1407 {
1408         int ret = 0;
1409         struct smu_table *watermarks = &smu->smu_table.tables[SMU_TABLE_WATERMARKS];
1410         void *table = watermarks->cpu_addr;
1411
1412         if (!smu->disable_watermark &&
1413             smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) &&
1414             smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
1415                 smu_set_watermarks_table(smu, table, clock_ranges);
1416                 smu->watermarks_bitmap |= WATERMARKS_EXIST;
1417                 smu->watermarks_bitmap &= ~WATERMARKS_LOADED;
1418         }
1419
1420         return ret;
1421 }
1422
1423 static int smu_v11_0_gfx_off_control(struct smu_context *smu, bool enable)
1424 {
1425         int ret = 0;
1426         struct amdgpu_device *adev = smu->adev;
1427
1428         switch (adev->asic_type) {
1429         case CHIP_VEGA20:
1430                 break;
1431         case CHIP_NAVI10:
1432                 if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))
1433                         return 0;
1434                 mutex_lock(&smu->mutex);
1435                 if (enable)
1436                         ret = smu_send_smc_msg(smu, SMU_MSG_AllowGfxOff);
1437                 else
1438                         ret = smu_send_smc_msg(smu, SMU_MSG_DisallowGfxOff);
1439                 mutex_unlock(&smu->mutex);
1440                 break;
1441         default:
1442                 break;
1443         }
1444
1445         return ret;
1446 }
1447
1448
1449 static int smu_v11_0_get_clock_ranges(struct smu_context *smu,
1450                                       uint32_t *clock,
1451                                       enum smu_clk_type clock_select,
1452                                       bool max)
1453 {
1454         int ret;
1455         *clock = 0;
1456         if (max) {
1457                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetMaxDpmFreq,
1458                                 smu_clk_get_index(smu, clock_select) << 16);
1459                 if (ret) {
1460                         pr_err("[GetClockRanges] Failed to get max clock from SMC!\n");
1461                         return ret;
1462                 }
1463                 smu_read_smc_arg(smu, clock);
1464         } else {
1465                 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetMinDpmFreq,
1466                                 smu_clk_get_index(smu, clock_select) << 16);
1467                 if (ret) {
1468                         pr_err("[GetClockRanges] Failed to get min clock from SMC!\n");
1469                         return ret;
1470                 }
1471                 smu_read_smc_arg(smu, clock);
1472         }
1473
1474         return 0;
1475 }
1476
1477 static uint32_t smu_v11_0_dpm_get_sclk(struct smu_context *smu, bool low)
1478 {
1479         uint32_t gfx_clk;
1480         int ret;
1481
1482         if (!smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
1483                 pr_err("[GetSclks]: gfxclk dpm not enabled!\n");
1484                 return -EPERM;
1485         }
1486
1487         if (low) {
1488                 ret = smu_v11_0_get_clock_ranges(smu, &gfx_clk, SMU_GFXCLK, false);
1489                 if (ret) {
1490                         pr_err("[GetSclks]: fail to get min SMU_GFXCLK\n");
1491                         return ret;
1492                 }
1493         } else {
1494                 ret = smu_v11_0_get_clock_ranges(smu, &gfx_clk, SMU_GFXCLK, true);
1495                 if (ret) {
1496                         pr_err("[GetSclks]: fail to get max SMU_GFXCLK\n");
1497                         return ret;
1498                 }
1499         }
1500
1501         return (gfx_clk * 100);
1502 }
1503
1504 static uint32_t smu_v11_0_dpm_get_mclk(struct smu_context *smu, bool low)
1505 {
1506         uint32_t mem_clk;
1507         int ret;
1508
1509         if (!smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
1510                 pr_err("[GetMclks]: memclk dpm not enabled!\n");
1511                 return -EPERM;
1512         }
1513
1514         if (low) {
1515                 ret = smu_v11_0_get_clock_ranges(smu, &mem_clk, SMU_UCLK, false);
1516                 if (ret) {
1517                         pr_err("[GetMclks]: fail to get min SMU_UCLK\n");
1518                         return ret;
1519                 }
1520         } else {
1521                 ret = smu_v11_0_get_clock_ranges(smu, &mem_clk, SMU_GFXCLK, true);
1522                 if (ret) {
1523                         pr_err("[GetMclks]: fail to get max SMU_UCLK\n");
1524                         return ret;
1525                 }
1526         }
1527
1528         return (mem_clk * 100);
1529 }
1530
1531 static int smu_v11_0_set_od8_default_settings(struct smu_context *smu,
1532                                               bool initialize)
1533 {
1534         struct smu_table_context *table_context = &smu->smu_table;
1535         struct smu_table *table = &table_context->tables[SMU_TABLE_OVERDRIVE];
1536         int ret;
1537
1538         /**
1539          * TODO: Enable overdrive for navi10, that replies on smc/pptable
1540          * support.
1541          */
1542         if (smu->adev->asic_type == CHIP_NAVI10)
1543                 return 0;
1544
1545         if (initialize) {
1546                 if (table_context->overdrive_table)
1547                         return -EINVAL;
1548
1549                 table_context->overdrive_table = kzalloc(table->size, GFP_KERNEL);
1550
1551                 if (!table_context->overdrive_table)
1552                         return -ENOMEM;
1553
1554                 ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE,
1555                                        table_context->overdrive_table, false);
1556                 if (ret) {
1557                         pr_err("Failed to export over drive table!\n");
1558                         return ret;
1559                 }
1560
1561                 smu_set_default_od8_settings(smu);
1562         }
1563
1564         ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE,
1565                                table_context->overdrive_table, true);
1566         if (ret) {
1567                 pr_err("Failed to import over drive table!\n");
1568                 return ret;
1569         }
1570
1571         return 0;
1572 }
1573
1574 static int smu_v11_0_update_od8_settings(struct smu_context *smu,
1575                                         uint32_t index,
1576                                         uint32_t value)
1577 {
1578         struct smu_table_context *table_context = &smu->smu_table;
1579         int ret;
1580
1581         ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE,
1582                                table_context->overdrive_table, false);
1583         if (ret) {
1584                 pr_err("Failed to export over drive table!\n");
1585                 return ret;
1586         }
1587
1588         smu_update_specified_od8_value(smu, index, value);
1589
1590         ret = smu_update_table(smu, SMU_TABLE_OVERDRIVE,
1591                                table_context->overdrive_table, true);
1592         if (ret) {
1593                 pr_err("Failed to import over drive table!\n");
1594                 return ret;
1595         }
1596
1597         return 0;
1598 }
1599
1600 static int smu_v11_0_get_current_rpm(struct smu_context *smu,
1601                                      uint32_t *current_rpm)
1602 {
1603         int ret;
1604
1605         ret = smu_send_smc_msg(smu, SMU_MSG_GetCurrentRpm);
1606
1607         if (ret) {
1608                 pr_err("Attempt to get current RPM from SMC Failed!\n");
1609                 return ret;
1610         }
1611
1612         smu_read_smc_arg(smu, current_rpm);
1613
1614         return 0;
1615 }
1616
1617 static uint32_t
1618 smu_v11_0_get_fan_control_mode(struct smu_context *smu)
1619 {
1620         if (!smu_feature_is_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT))
1621                 return AMD_FAN_CTRL_MANUAL;
1622         else
1623                 return AMD_FAN_CTRL_AUTO;
1624 }
1625
1626 static int
1627 smu_v11_0_smc_fan_control(struct smu_context *smu, bool start)
1628 {
1629         int ret = 0;
1630
1631         if (smu_feature_is_supported(smu, SMU_FEATURE_FAN_CONTROL_BIT))
1632                 return 0;
1633
1634         ret = smu_feature_set_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT, start);
1635         if (ret)
1636                 pr_err("[%s]%s smc FAN CONTROL feature failed!",
1637                        __func__, (start ? "Start" : "Stop"));
1638
1639         return ret;
1640 }
1641
1642 static int
1643 smu_v11_0_set_fan_static_mode(struct smu_context *smu, uint32_t mode)
1644 {
1645         struct amdgpu_device *adev = smu->adev;
1646
1647         WREG32_SOC15(THM, 0, mmCG_FDO_CTRL2,
1648                      REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL2),
1649                                    CG_FDO_CTRL2, TMIN, 0));
1650         WREG32_SOC15(THM, 0, mmCG_FDO_CTRL2,
1651                      REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL2),
1652                                    CG_FDO_CTRL2, FDO_PWM_MODE, mode));
1653
1654         return 0;
1655 }
1656
1657 static int
1658 smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)
1659 {
1660         struct amdgpu_device *adev = smu->adev;
1661         uint32_t duty100;
1662         uint32_t duty;
1663         uint64_t tmp64;
1664         bool stop = 0;
1665
1666         if (speed > 100)
1667                 speed = 100;
1668
1669         if (smu_v11_0_smc_fan_control(smu, stop))
1670                 return -EINVAL;
1671         duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
1672                                 CG_FDO_CTRL1, FMAX_DUTY100);
1673         if (!duty100)
1674                 return -EINVAL;
1675
1676         tmp64 = (uint64_t)speed * duty100;
1677         do_div(tmp64, 100);
1678         duty = (uint32_t)tmp64;
1679
1680         WREG32_SOC15(THM, 0, mmCG_FDO_CTRL0,
1681                      REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL0),
1682                                    CG_FDO_CTRL0, FDO_STATIC_DUTY, duty));
1683
1684         return smu_v11_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC);
1685 }
1686
1687 static int
1688 smu_v11_0_set_fan_control_mode(struct smu_context *smu,
1689                                uint32_t mode)
1690 {
1691         int ret = 0;
1692         bool start = 1;
1693         bool stop  = 0;
1694
1695         switch (mode) {
1696         case AMD_FAN_CTRL_NONE:
1697                 ret = smu_v11_0_set_fan_speed_percent(smu, 100);
1698                 break;
1699         case AMD_FAN_CTRL_MANUAL:
1700                 ret = smu_v11_0_smc_fan_control(smu, stop);
1701                 break;
1702         case AMD_FAN_CTRL_AUTO:
1703                 ret = smu_v11_0_smc_fan_control(smu, start);
1704                 break;
1705         default:
1706                 break;
1707         }
1708
1709         if (ret) {
1710                 pr_err("[%s]Set fan control mode failed!", __func__);
1711                 return -EINVAL;
1712         }
1713
1714         return ret;
1715 }
1716
1717 static int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
1718                                        uint32_t speed)
1719 {
1720         struct amdgpu_device *adev = smu->adev;
1721         int ret;
1722         uint32_t tach_period, crystal_clock_freq;
1723         bool stop = 0;
1724
1725         if (!speed)
1726                 return -EINVAL;
1727
1728         mutex_lock(&(smu->mutex));
1729         ret = smu_v11_0_smc_fan_control(smu, stop);
1730         if (ret)
1731                 goto set_fan_speed_rpm_failed;
1732
1733         crystal_clock_freq = amdgpu_asic_get_xclk(adev);
1734         tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
1735         WREG32_SOC15(THM, 0, mmCG_TACH_CTRL,
1736                      REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_TACH_CTRL),
1737                                    CG_TACH_CTRL, TARGET_PERIOD,
1738                                    tach_period));
1739
1740         ret = smu_v11_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC_RPM);
1741
1742 set_fan_speed_rpm_failed:
1743         mutex_unlock(&(smu->mutex));
1744         return ret;
1745 }
1746
1747 #define XGMI_STATE_D0 1
1748 #define XGMI_STATE_D3 0
1749
1750 static int smu_v11_0_set_xgmi_pstate(struct smu_context *smu,
1751                                      uint32_t pstate)
1752 {
1753         int ret = 0;
1754         mutex_lock(&(smu->mutex));
1755         ret = smu_send_smc_msg_with_param(smu,
1756                                           SMU_MSG_SetXgmiMode,
1757                                           pstate ? XGMI_STATE_D0 : XGMI_STATE_D3);
1758         mutex_unlock(&(smu->mutex));
1759         return ret;
1760 }
1761
1762 static const struct smu_funcs smu_v11_0_funcs = {
1763         .init_microcode = smu_v11_0_init_microcode,
1764         .load_microcode = smu_v11_0_load_microcode,
1765         .check_fw_status = smu_v11_0_check_fw_status,
1766         .check_fw_version = smu_v11_0_check_fw_version,
1767         .send_smc_msg = smu_v11_0_send_msg,
1768         .send_smc_msg_with_param = smu_v11_0_send_msg_with_param,
1769         .read_smc_arg = smu_v11_0_read_arg,
1770         .setup_pptable = smu_v11_0_setup_pptable,
1771         .init_smc_tables = smu_v11_0_init_smc_tables,
1772         .fini_smc_tables = smu_v11_0_fini_smc_tables,
1773         .init_power = smu_v11_0_init_power,
1774         .fini_power = smu_v11_0_fini_power,
1775         .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
1776         .get_clk_info_from_vbios = smu_v11_0_get_clk_info_from_vbios,
1777         .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
1778         .check_pptable = smu_v11_0_check_pptable,
1779         .parse_pptable = smu_v11_0_parse_pptable,
1780         .populate_smc_pptable = smu_v11_0_populate_smc_pptable,
1781         .write_pptable = smu_v11_0_write_pptable,
1782         .write_watermarks_table = smu_v11_0_write_watermarks_table,
1783         .set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
1784         .set_tool_table_location = smu_v11_0_set_tool_table_location,
1785         .init_display = smu_v11_0_init_display,
1786         .set_allowed_mask = smu_v11_0_set_allowed_mask,
1787         .get_enabled_mask = smu_v11_0_get_enabled_mask,
1788         .system_features_control = smu_v11_0_system_features_control,
1789         .update_feature_enable_state = smu_v11_0_update_feature_enable_state,
1790         .notify_display_change = smu_v11_0_notify_display_change,
1791         .get_power_limit = smu_v11_0_get_power_limit,
1792         .set_power_limit = smu_v11_0_set_power_limit,
1793         .get_current_clk_freq = smu_v11_0_get_current_clk_freq,
1794         .init_max_sustainable_clocks = smu_v11_0_init_max_sustainable_clocks,
1795         .start_thermal_control = smu_v11_0_start_thermal_control,
1796         .read_sensor = smu_v11_0_read_sensor,
1797         .set_deep_sleep_dcefclk = smu_v11_0_set_deep_sleep_dcefclk,
1798         .display_clock_voltage_request = smu_v11_0_display_clock_voltage_request,
1799         .set_watermarks_for_clock_ranges = smu_v11_0_set_watermarks_for_clock_ranges,
1800         .get_sclk = smu_v11_0_dpm_get_sclk,
1801         .get_mclk = smu_v11_0_dpm_get_mclk,
1802         .set_od8_default_settings = smu_v11_0_set_od8_default_settings,
1803         .update_od8_settings = smu_v11_0_update_od8_settings,
1804         .get_current_rpm = smu_v11_0_get_current_rpm,
1805         .get_fan_control_mode = smu_v11_0_get_fan_control_mode,
1806         .set_fan_control_mode = smu_v11_0_set_fan_control_mode,
1807         .set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
1808         .set_fan_speed_rpm = smu_v11_0_set_fan_speed_rpm,
1809         .set_xgmi_pstate = smu_v11_0_set_xgmi_pstate,
1810         .gfx_off_control = smu_v11_0_gfx_off_control,
1811 };
1812
1813 void smu_v11_0_set_smu_funcs(struct smu_context *smu)
1814 {
1815         struct amdgpu_device *adev = smu->adev;
1816
1817         smu->funcs = &smu_v11_0_funcs;
1818         switch (adev->asic_type) {
1819         case CHIP_VEGA20:
1820                 vega20_set_ppt_funcs(smu);
1821                 break;
1822         case CHIP_NAVI10:
1823                 navi10_set_ppt_funcs(smu);
1824                 break;
1825         default:
1826                 pr_warn("Unknown asic for smu11\n");
1827         }
1828 }