2 * Copyright 2020 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/firmware.h>
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/reboot.h>
28 #define SMU_13_0_PARTIAL_PPTABLE
29 #define SWSMU_CODE_LAYER_L3
32 #include "amdgpu_smu.h"
33 #include "atomfirmware.h"
34 #include "amdgpu_atomfirmware.h"
35 #include "amdgpu_atombios.h"
36 #include "smu_v13_0.h"
37 #include "soc15_common.h"
39 #include "amdgpu_ras.h"
42 #include "asic_reg/thm/thm_13_0_2_offset.h"
43 #include "asic_reg/thm/thm_13_0_2_sh_mask.h"
44 #include "asic_reg/mp/mp_13_0_2_offset.h"
45 #include "asic_reg/mp/mp_13_0_2_sh_mask.h"
46 #include "asic_reg/smuio/smuio_13_0_2_offset.h"
47 #include "asic_reg/smuio/smuio_13_0_2_sh_mask.h"
50 * DO NOT use these for err/warn/info/debug messages.
51 * Use dev_err, dev_warn, dev_info and dev_dbg instead.
52 * They are more MGPU friendly.
59 MODULE_FIRMWARE("amdgpu/aldebaran_smc.bin");
61 #define SMU13_VOLTAGE_SCALE 4
63 #define SMU13_MODE1_RESET_WAIT_TIME_IN_MS 500 //500ms
65 #define LINK_WIDTH_MAX 6
66 #define LINK_SPEED_MAX 3
68 #define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
69 #define PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK 0x00000070L
70 #define PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT 0x4
71 #define smnPCIE_LC_SPEED_CNTL 0x11140290
72 #define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK 0xC000
73 #define PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT 0xE
75 static const int link_width[] = {0, 1, 2, 4, 8, 12, 16};
76 static const int link_speed[] = {25, 50, 80, 160};
78 int smu_v13_0_init_microcode(struct smu_context *smu)
80 struct amdgpu_device *adev = smu->adev;
81 const char *chip_name;
84 const struct smc_firmware_header_v1_0 *hdr;
85 const struct common_firmware_header *header;
86 struct amdgpu_firmware_info *ucode = NULL;
88 switch (adev->asic_type) {
90 chip_name = "aldebaran";
93 dev_err(adev->dev, "Unsupported ASIC type %d\n", adev->asic_type);
97 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_smc.bin", chip_name);
99 err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
102 err = amdgpu_ucode_validate(adev->pm.fw);
106 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
107 amdgpu_ucode_print_smc_hdr(&hdr->header);
108 adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
110 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
111 ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
112 ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
113 ucode->fw = adev->pm.fw;
114 header = (const struct common_firmware_header *)ucode->fw->data;
115 adev->firmware.fw_size +=
116 ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
121 DRM_ERROR("smu_v13_0: Failed to load firmware \"%s\"\n",
123 release_firmware(adev->pm.fw);
129 void smu_v13_0_fini_microcode(struct smu_context *smu)
131 struct amdgpu_device *adev = smu->adev;
133 release_firmware(adev->pm.fw);
135 adev->pm.fw_version = 0;
138 int smu_v13_0_load_microcode(struct smu_context *smu)
141 struct amdgpu_device *adev = smu->adev;
143 const struct smc_firmware_header_v1_0 *hdr;
144 uint32_t addr_start = MP1_SRAM;
146 uint32_t smc_fw_size;
147 uint32_t mp1_fw_flags;
149 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
150 src = (const uint32_t *)(adev->pm.fw->data +
151 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
152 smc_fw_size = hdr->header.ucode_size_bytes;
154 for (i = 1; i < smc_fw_size/4 - 1; i++) {
155 WREG32_PCIE(addr_start, src[i]);
159 WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
160 1 & MP1_SMN_PUB_CTRL__RESET_MASK);
161 WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
162 1 & ~MP1_SMN_PUB_CTRL__RESET_MASK);
164 for (i = 0; i < adev->usec_timeout; i++) {
165 mp1_fw_flags = RREG32_PCIE(MP1_Public |
166 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
167 if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
168 MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
173 if (i == adev->usec_timeout)
179 int smu_v13_0_check_fw_status(struct smu_context *smu)
181 struct amdgpu_device *adev = smu->adev;
182 uint32_t mp1_fw_flags;
184 mp1_fw_flags = RREG32_PCIE(MP1_Public |
185 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
187 if ((mp1_fw_flags & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
188 MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
194 int smu_v13_0_check_fw_version(struct smu_context *smu)
196 uint32_t if_version = 0xff, smu_version = 0xff;
198 uint8_t smu_minor, smu_debug;
201 ret = smu_cmn_get_smc_version(smu, &if_version, &smu_version);
205 smu_major = (smu_version >> 16) & 0xffff;
206 smu_minor = (smu_version >> 8) & 0xff;
207 smu_debug = (smu_version >> 0) & 0xff;
209 switch (smu->adev->asic_type) {
211 smu->smc_driver_if_version = SMU13_DRIVER_IF_VERSION_ALDE;
214 dev_err(smu->adev->dev, "smu unsupported asic type:%d.\n", smu->adev->asic_type);
215 smu->smc_driver_if_version = SMU13_DRIVER_IF_VERSION_INV;
219 dev_info(smu->adev->dev, "smu fw reported version = 0x%08x (%d.%d.%d)\n",
220 smu_version, smu_major, smu_minor, smu_debug);
223 * 1. if_version mismatch is not critical as our fw is designed
224 * to be backward compatible.
225 * 2. New fw usually brings some optimizations. But that's visible
226 * only on the paired driver.
227 * Considering above, we just leave user a warning message instead
228 * of halt driver loading.
230 if (if_version != smu->smc_driver_if_version) {
231 dev_info(smu->adev->dev, "smu driver if version = 0x%08x, smu fw if version = 0x%08x, "
232 "smu fw version = 0x%08x (%d.%d.%d)\n",
233 smu->smc_driver_if_version, if_version,
234 smu_version, smu_major, smu_minor, smu_debug);
235 dev_warn(smu->adev->dev, "SMU driver if version not matched\n");
241 static int smu_v13_0_set_pptable_v2_1(struct smu_context *smu, void **table,
242 uint32_t *size, uint32_t pptable_id)
244 struct amdgpu_device *adev = smu->adev;
245 const struct smc_firmware_header_v2_1 *v2_1;
246 struct smc_soft_pptable_entry *entries;
247 uint32_t pptable_count = 0;
250 v2_1 = (const struct smc_firmware_header_v2_1 *) adev->pm.fw->data;
251 entries = (struct smc_soft_pptable_entry *)
252 ((uint8_t *)v2_1 + le32_to_cpu(v2_1->pptable_entry_offset));
253 pptable_count = le32_to_cpu(v2_1->pptable_count);
254 for (i = 0; i < pptable_count; i++) {
255 if (le32_to_cpu(entries[i].id) == pptable_id) {
256 *table = ((uint8_t *)v2_1 + le32_to_cpu(entries[i].ppt_offset_bytes));
257 *size = le32_to_cpu(entries[i].ppt_size_bytes);
262 if (i == pptable_count)
268 int smu_v13_0_setup_pptable(struct smu_context *smu)
270 struct amdgpu_device *adev = smu->adev;
271 const struct smc_firmware_header_v1_0 *hdr;
274 uint16_t atom_table_size;
277 uint16_t version_major, version_minor;
280 if (amdgpu_smu_pptable_id >= 0) {
281 smu->smu_table.boot_values.pp_table_id = amdgpu_smu_pptable_id;
282 dev_info(adev->dev, "override pptable id %d\n", amdgpu_smu_pptable_id);
285 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
286 version_major = le16_to_cpu(hdr->header.header_version_major);
287 version_minor = le16_to_cpu(hdr->header.header_version_minor);
288 if (version_major == 2 && smu->smu_table.boot_values.pp_table_id > 0) {
289 dev_info(adev->dev, "use driver provided pptable %d\n", smu->smu_table.boot_values.pp_table_id);
290 switch (version_minor) {
292 ret = smu_v13_0_set_pptable_v2_1(smu, &table, &size,
293 smu->smu_table.boot_values.pp_table_id);
303 dev_info(adev->dev, "use vbios provided pptable\n");
304 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
307 ret = amdgpu_atombios_get_data_table(adev, index, &atom_table_size, &frev, &crev,
311 size = atom_table_size;
314 if (!smu->smu_table.power_play_table)
315 smu->smu_table.power_play_table = table;
316 if (!smu->smu_table.power_play_table_size)
317 smu->smu_table.power_play_table_size = size;
322 int smu_v13_0_init_smc_tables(struct smu_context *smu)
324 struct smu_table_context *smu_table = &smu->smu_table;
325 struct smu_table *tables = smu_table->tables;
328 smu_table->driver_pptable =
329 kzalloc(tables[SMU_TABLE_PPTABLE].size, GFP_KERNEL);
330 if (!smu_table->driver_pptable) {
335 smu_table->max_sustainable_clocks =
336 kzalloc(sizeof(struct smu_13_0_max_sustainable_clocks), GFP_KERNEL);
337 if (!smu_table->max_sustainable_clocks) {
342 /* Aldebaran does not support OVERDRIVE */
343 if (tables[SMU_TABLE_OVERDRIVE].size) {
344 smu_table->overdrive_table =
345 kzalloc(tables[SMU_TABLE_OVERDRIVE].size, GFP_KERNEL);
346 if (!smu_table->overdrive_table) {
351 smu_table->boot_overdrive_table =
352 kzalloc(tables[SMU_TABLE_OVERDRIVE].size, GFP_KERNEL);
353 if (!smu_table->boot_overdrive_table) {
362 kfree(smu_table->overdrive_table);
364 kfree(smu_table->max_sustainable_clocks);
366 kfree(smu_table->driver_pptable);
371 int smu_v13_0_fini_smc_tables(struct smu_context *smu)
373 struct smu_table_context *smu_table = &smu->smu_table;
374 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
376 kfree(smu_table->gpu_metrics_table);
377 kfree(smu_table->boot_overdrive_table);
378 kfree(smu_table->overdrive_table);
379 kfree(smu_table->max_sustainable_clocks);
380 kfree(smu_table->driver_pptable);
381 smu_table->gpu_metrics_table = NULL;
382 smu_table->boot_overdrive_table = NULL;
383 smu_table->overdrive_table = NULL;
384 smu_table->max_sustainable_clocks = NULL;
385 smu_table->driver_pptable = NULL;
386 kfree(smu_table->hardcode_pptable);
387 smu_table->hardcode_pptable = NULL;
389 kfree(smu_table->metrics_table);
390 kfree(smu_table->watermarks_table);
391 smu_table->metrics_table = NULL;
392 smu_table->watermarks_table = NULL;
393 smu_table->metrics_time = 0;
395 kfree(smu_dpm->dpm_context);
396 kfree(smu_dpm->golden_dpm_context);
397 kfree(smu_dpm->dpm_current_power_state);
398 kfree(smu_dpm->dpm_request_power_state);
399 smu_dpm->dpm_context = NULL;
400 smu_dpm->golden_dpm_context = NULL;
401 smu_dpm->dpm_context_size = 0;
402 smu_dpm->dpm_current_power_state = NULL;
403 smu_dpm->dpm_request_power_state = NULL;
408 int smu_v13_0_init_power(struct smu_context *smu)
410 struct smu_power_context *smu_power = &smu->smu_power;
412 if (smu_power->power_context || smu_power->power_context_size != 0)
415 smu_power->power_context = kzalloc(sizeof(struct smu_13_0_dpm_context),
417 if (!smu_power->power_context)
419 smu_power->power_context_size = sizeof(struct smu_13_0_dpm_context);
424 int smu_v13_0_fini_power(struct smu_context *smu)
426 struct smu_power_context *smu_power = &smu->smu_power;
428 if (!smu_power->power_context || smu_power->power_context_size == 0)
431 kfree(smu_power->power_context);
432 smu_power->power_context = NULL;
433 smu_power->power_context_size = 0;
438 static int smu_v13_0_atom_get_smu_clockinfo(struct amdgpu_device *adev,
443 struct atom_get_smu_clock_info_parameters_v3_1 input = {0};
444 struct atom_get_smu_clock_info_output_parameters_v3_1 *output;
447 input.clk_id = clk_id;
448 input.syspll_id = syspll_id;
449 input.command = GET_SMU_CLOCK_INFO_V3_1_GET_CLOCK_FREQ;
450 index = get_index_into_master_table(atom_master_list_of_command_functions_v2_1,
453 ret = amdgpu_atom_execute_table(adev->mode_info.atom_context, index,
458 output = (struct atom_get_smu_clock_info_output_parameters_v3_1 *)&input;
459 *clk_freq = le32_to_cpu(output->atom_smu_outputclkfreq.smu_clock_freq_hz) / 10000;
464 int smu_v13_0_get_vbios_bootup_values(struct smu_context *smu)
469 struct atom_common_table_header *header;
470 struct atom_firmware_info_v3_4 *v_3_4;
471 struct atom_firmware_info_v3_3 *v_3_3;
472 struct atom_firmware_info_v3_1 *v_3_1;
474 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
477 ret = amdgpu_atombios_get_data_table(smu->adev, index, &size, &frev, &crev,
478 (uint8_t **)&header);
482 if (header->format_revision != 3) {
483 dev_err(smu->adev->dev, "unknown atom_firmware_info version! for smu13\n");
487 switch (header->content_revision) {
491 v_3_1 = (struct atom_firmware_info_v3_1 *)header;
492 smu->smu_table.boot_values.revision = v_3_1->firmware_revision;
493 smu->smu_table.boot_values.gfxclk = v_3_1->bootup_sclk_in10khz;
494 smu->smu_table.boot_values.uclk = v_3_1->bootup_mclk_in10khz;
495 smu->smu_table.boot_values.socclk = 0;
496 smu->smu_table.boot_values.dcefclk = 0;
497 smu->smu_table.boot_values.vddc = v_3_1->bootup_vddc_mv;
498 smu->smu_table.boot_values.vddci = v_3_1->bootup_vddci_mv;
499 smu->smu_table.boot_values.mvddc = v_3_1->bootup_mvddc_mv;
500 smu->smu_table.boot_values.vdd_gfx = v_3_1->bootup_vddgfx_mv;
501 smu->smu_table.boot_values.cooling_id = v_3_1->coolingsolution_id;
502 smu->smu_table.boot_values.pp_table_id = 0;
505 v_3_3 = (struct atom_firmware_info_v3_3 *)header;
506 smu->smu_table.boot_values.revision = v_3_3->firmware_revision;
507 smu->smu_table.boot_values.gfxclk = v_3_3->bootup_sclk_in10khz;
508 smu->smu_table.boot_values.uclk = v_3_3->bootup_mclk_in10khz;
509 smu->smu_table.boot_values.socclk = 0;
510 smu->smu_table.boot_values.dcefclk = 0;
511 smu->smu_table.boot_values.vddc = v_3_3->bootup_vddc_mv;
512 smu->smu_table.boot_values.vddci = v_3_3->bootup_vddci_mv;
513 smu->smu_table.boot_values.mvddc = v_3_3->bootup_mvddc_mv;
514 smu->smu_table.boot_values.vdd_gfx = v_3_3->bootup_vddgfx_mv;
515 smu->smu_table.boot_values.cooling_id = v_3_3->coolingsolution_id;
516 smu->smu_table.boot_values.pp_table_id = v_3_3->pplib_pptable_id;
520 v_3_4 = (struct atom_firmware_info_v3_4 *)header;
521 smu->smu_table.boot_values.revision = v_3_4->firmware_revision;
522 smu->smu_table.boot_values.gfxclk = v_3_4->bootup_sclk_in10khz;
523 smu->smu_table.boot_values.uclk = v_3_4->bootup_mclk_in10khz;
524 smu->smu_table.boot_values.socclk = 0;
525 smu->smu_table.boot_values.dcefclk = 0;
526 smu->smu_table.boot_values.vddc = v_3_4->bootup_vddc_mv;
527 smu->smu_table.boot_values.vddci = v_3_4->bootup_vddci_mv;
528 smu->smu_table.boot_values.mvddc = v_3_4->bootup_mvddc_mv;
529 smu->smu_table.boot_values.vdd_gfx = v_3_4->bootup_vddgfx_mv;
530 smu->smu_table.boot_values.cooling_id = v_3_4->coolingsolution_id;
531 smu->smu_table.boot_values.pp_table_id = v_3_4->pplib_pptable_id;
535 smu->smu_table.boot_values.format_revision = header->format_revision;
536 smu->smu_table.boot_values.content_revision = header->content_revision;
538 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
539 (uint8_t)SMU11_SYSPLL0_SOCCLK_ID,
541 &smu->smu_table.boot_values.socclk);
543 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
544 (uint8_t)SMU11_SYSPLL0_DCEFCLK_ID,
546 &smu->smu_table.boot_values.dcefclk);
548 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
549 (uint8_t)SMU11_SYSPLL0_ECLK_ID,
551 &smu->smu_table.boot_values.eclk);
553 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
554 (uint8_t)SMU11_SYSPLL0_VCLK_ID,
556 &smu->smu_table.boot_values.vclk);
558 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
559 (uint8_t)SMU11_SYSPLL0_DCLK_ID,
561 &smu->smu_table.boot_values.dclk);
563 if ((smu->smu_table.boot_values.format_revision == 3) &&
564 (smu->smu_table.boot_values.content_revision >= 2))
565 smu_v13_0_atom_get_smu_clockinfo(smu->adev,
566 (uint8_t)SMU11_SYSPLL1_0_FCLK_ID,
567 (uint8_t)SMU11_SYSPLL1_2_ID,
568 &smu->smu_table.boot_values.fclk);
574 int smu_v13_0_notify_memory_pool_location(struct smu_context *smu)
576 struct smu_table_context *smu_table = &smu->smu_table;
577 struct smu_table *memory_pool = &smu_table->memory_pool;
580 uint32_t address_low, address_high;
582 if (memory_pool->size == 0 || memory_pool->cpu_addr == NULL)
585 address = memory_pool->mc_address;
586 address_high = (uint32_t)upper_32_bits(address);
587 address_low = (uint32_t)lower_32_bits(address);
589 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrHigh,
593 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrLow,
597 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramSize,
598 (uint32_t)memory_pool->size, NULL);
605 int smu_v13_0_set_min_deep_sleep_dcefclk(struct smu_context *smu, uint32_t clk)
609 ret = smu_cmn_send_smc_msg_with_param(smu,
610 SMU_MSG_SetMinDeepSleepDcefclk, clk, NULL);
612 dev_err(smu->adev->dev, "SMU13 attempt to set divider for DCEFCLK Failed!");
617 int smu_v13_0_set_driver_table_location(struct smu_context *smu)
619 struct smu_table *driver_table = &smu->smu_table.driver_table;
622 if (driver_table->mc_address) {
623 ret = smu_cmn_send_smc_msg_with_param(smu,
624 SMU_MSG_SetDriverDramAddrHigh,
625 upper_32_bits(driver_table->mc_address),
628 ret = smu_cmn_send_smc_msg_with_param(smu,
629 SMU_MSG_SetDriverDramAddrLow,
630 lower_32_bits(driver_table->mc_address),
637 int smu_v13_0_set_tool_table_location(struct smu_context *smu)
640 struct smu_table *tool_table = &smu->smu_table.tables[SMU_TABLE_PMSTATUSLOG];
642 if (tool_table->mc_address) {
643 ret = smu_cmn_send_smc_msg_with_param(smu,
644 SMU_MSG_SetToolsDramAddrHigh,
645 upper_32_bits(tool_table->mc_address),
648 ret = smu_cmn_send_smc_msg_with_param(smu,
649 SMU_MSG_SetToolsDramAddrLow,
650 lower_32_bits(tool_table->mc_address),
657 int smu_v13_0_init_display_count(struct smu_context *smu, uint32_t count)
661 if (!smu->pm_enabled)
664 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_NumOfDisplays, count, NULL);
670 int smu_v13_0_set_allowed_mask(struct smu_context *smu)
672 struct smu_feature *feature = &smu->smu_feature;
674 uint32_t feature_mask[2];
676 mutex_lock(&feature->mutex);
677 if (bitmap_empty(feature->allowed, SMU_FEATURE_MAX) || feature->feature_num < 64)
680 bitmap_copy((unsigned long *)feature_mask, feature->allowed, 64);
682 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskHigh,
683 feature_mask[1], NULL);
687 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskLow,
688 feature_mask[0], NULL);
693 mutex_unlock(&feature->mutex);
697 int smu_v13_0_system_features_control(struct smu_context *smu,
700 struct smu_feature *feature = &smu->smu_feature;
701 uint32_t feature_mask[2];
704 ret = smu_cmn_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
705 SMU_MSG_DisableAllSmuFeatures), NULL);
709 bitmap_zero(feature->enabled, feature->feature_num);
710 bitmap_zero(feature->supported, feature->feature_num);
713 ret = smu_cmn_get_enabled_mask(smu, feature_mask, 2);
717 bitmap_copy(feature->enabled, (unsigned long *)&feature_mask,
718 feature->feature_num);
719 bitmap_copy(feature->supported, (unsigned long *)&feature_mask,
720 feature->feature_num);
726 int smu_v13_0_notify_display_change(struct smu_context *smu)
730 if (!smu->pm_enabled)
733 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT) &&
734 smu->adev->gmc.vram_type == AMDGPU_VRAM_TYPE_HBM)
735 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1, NULL);
741 smu_v13_0_get_max_sustainable_clock(struct smu_context *smu, uint32_t *clock,
742 enum smu_clk_type clock_select)
747 if ((smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG, SMU_MSG_GetDcModeMaxDpmFreq) < 0) ||
748 (smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG, SMU_MSG_GetMaxDpmFreq) < 0))
751 clk_id = smu_cmn_to_asic_specific_index(smu,
752 CMN2ASIC_MAPPING_CLK,
757 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GetDcModeMaxDpmFreq,
758 clk_id << 16, clock);
760 dev_err(smu->adev->dev, "[GetMaxSustainableClock] Failed to get max DC clock from SMC!");
767 /* if DC limit is zero, return AC limit */
768 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GetMaxDpmFreq,
769 clk_id << 16, clock);
771 dev_err(smu->adev->dev, "[GetMaxSustainableClock] failed to get max AC clock from SMC!");
778 int smu_v13_0_init_max_sustainable_clocks(struct smu_context *smu)
780 struct smu_13_0_max_sustainable_clocks *max_sustainable_clocks =
781 smu->smu_table.max_sustainable_clocks;
784 max_sustainable_clocks->uclock = smu->smu_table.boot_values.uclk / 100;
785 max_sustainable_clocks->soc_clock = smu->smu_table.boot_values.socclk / 100;
786 max_sustainable_clocks->dcef_clock = smu->smu_table.boot_values.dcefclk / 100;
787 max_sustainable_clocks->display_clock = 0xFFFFFFFF;
788 max_sustainable_clocks->phy_clock = 0xFFFFFFFF;
789 max_sustainable_clocks->pixel_clock = 0xFFFFFFFF;
791 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
792 ret = smu_v13_0_get_max_sustainable_clock(smu,
793 &(max_sustainable_clocks->uclock),
796 dev_err(smu->adev->dev, "[%s] failed to get max UCLK from SMC!",
802 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
803 ret = smu_v13_0_get_max_sustainable_clock(smu,
804 &(max_sustainable_clocks->soc_clock),
807 dev_err(smu->adev->dev, "[%s] failed to get max SOCCLK from SMC!",
813 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT)) {
814 ret = smu_v13_0_get_max_sustainable_clock(smu,
815 &(max_sustainable_clocks->dcef_clock),
818 dev_err(smu->adev->dev, "[%s] failed to get max DCEFCLK from SMC!",
823 ret = smu_v13_0_get_max_sustainable_clock(smu,
824 &(max_sustainable_clocks->display_clock),
827 dev_err(smu->adev->dev, "[%s] failed to get max DISPCLK from SMC!",
831 ret = smu_v13_0_get_max_sustainable_clock(smu,
832 &(max_sustainable_clocks->phy_clock),
835 dev_err(smu->adev->dev, "[%s] failed to get max PHYCLK from SMC!",
839 ret = smu_v13_0_get_max_sustainable_clock(smu,
840 &(max_sustainable_clocks->pixel_clock),
843 dev_err(smu->adev->dev, "[%s] failed to get max PIXCLK from SMC!",
849 if (max_sustainable_clocks->soc_clock < max_sustainable_clocks->uclock)
850 max_sustainable_clocks->uclock = max_sustainable_clocks->soc_clock;
855 int smu_v13_0_get_current_power_limit(struct smu_context *smu,
856 uint32_t *power_limit)
861 if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT))
864 power_src = smu_cmn_to_asic_specific_index(smu,
865 CMN2ASIC_MAPPING_PWR,
866 smu->adev->pm.ac_power ?
867 SMU_POWER_SOURCE_AC :
868 SMU_POWER_SOURCE_DC);
872 ret = smu_cmn_send_smc_msg_with_param(smu,
877 dev_err(smu->adev->dev, "[%s] get PPT limit failed!", __func__);
882 int smu_v13_0_set_power_limit(struct smu_context *smu, uint32_t n)
886 if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
887 dev_err(smu->adev->dev, "Setting new power limit is not supported!\n");
891 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, n, NULL);
893 dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__);
897 smu->current_power_limit = n;
902 int smu_v13_0_enable_thermal_alert(struct smu_context *smu)
904 if (smu->smu_table.thermal_controller_type)
905 return amdgpu_irq_get(smu->adev, &smu->irq_source, 0);
910 int smu_v13_0_disable_thermal_alert(struct smu_context *smu)
912 return amdgpu_irq_put(smu->adev, &smu->irq_source, 0);
915 static uint16_t convert_to_vddc(uint8_t vid)
917 return (uint16_t) ((6200 - (vid * 25)) / SMU13_VOLTAGE_SCALE);
920 int smu_v13_0_get_gfx_vdd(struct smu_context *smu, uint32_t *value)
922 struct amdgpu_device *adev = smu->adev;
923 uint32_t vdd = 0, val_vid = 0;
927 val_vid = (RREG32_SOC15(SMUIO, 0, regSMUSVI0_TEL_PLANE0) &
928 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR_MASK) >>
929 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR__SHIFT;
931 vdd = (uint32_t)convert_to_vddc((uint8_t)val_vid);
940 smu_v13_0_display_clock_voltage_request(struct smu_context *smu,
941 struct pp_display_clock_request
944 enum amd_pp_clock_type clk_type = clock_req->clock_type;
946 enum smu_clk_type clk_select = 0;
947 uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
949 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) ||
950 smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
952 case amd_pp_dcef_clock:
953 clk_select = SMU_DCEFCLK;
955 case amd_pp_disp_clock:
956 clk_select = SMU_DISPCLK;
958 case amd_pp_pixel_clock:
959 clk_select = SMU_PIXCLK;
961 case amd_pp_phy_clock:
962 clk_select = SMU_PHYCLK;
964 case amd_pp_mem_clock:
965 clk_select = SMU_UCLK;
968 dev_info(smu->adev->dev, "[%s] Invalid Clock Type!", __func__);
976 if (clk_select == SMU_UCLK && smu->disable_uclk_switch)
979 ret = smu_v13_0_set_hard_freq_limited_range(smu, clk_select, clk_freq, 0);
981 if(clk_select == SMU_UCLK)
982 smu->hard_min_uclk_req_from_dal = clk_freq;
989 uint32_t smu_v13_0_get_fan_control_mode(struct smu_context *smu)
991 if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT))
992 return AMD_FAN_CTRL_MANUAL;
994 return AMD_FAN_CTRL_AUTO;
998 smu_v13_0_auto_fan_control(struct smu_context *smu, bool auto_fan_control)
1002 if (!smu_cmn_feature_is_supported(smu, SMU_FEATURE_FAN_CONTROL_BIT))
1005 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_FAN_CONTROL_BIT, auto_fan_control);
1007 dev_err(smu->adev->dev, "[%s]%s smc FAN CONTROL feature failed!",
1008 __func__, (auto_fan_control ? "Start" : "Stop"));
1014 smu_v13_0_set_fan_static_mode(struct smu_context *smu, uint32_t mode)
1016 struct amdgpu_device *adev = smu->adev;
1018 WREG32_SOC15(THM, 0, regCG_FDO_CTRL2,
1019 REG_SET_FIELD(RREG32_SOC15(THM, 0, regCG_FDO_CTRL2),
1020 CG_FDO_CTRL2, TMIN, 0));
1021 WREG32_SOC15(THM, 0, regCG_FDO_CTRL2,
1022 REG_SET_FIELD(RREG32_SOC15(THM, 0, regCG_FDO_CTRL2),
1023 CG_FDO_CTRL2, FDO_PWM_MODE, mode));
1029 smu_v13_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)
1031 struct amdgpu_device *adev = smu->adev;
1032 uint32_t duty100, duty;
1038 if (smu_v13_0_auto_fan_control(smu, 0))
1041 duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, regCG_FDO_CTRL1),
1042 CG_FDO_CTRL1, FMAX_DUTY100);
1046 tmp64 = (uint64_t)speed * duty100;
1048 duty = (uint32_t)tmp64;
1050 WREG32_SOC15(THM, 0, regCG_FDO_CTRL0,
1051 REG_SET_FIELD(RREG32_SOC15(THM, 0, regCG_FDO_CTRL0),
1052 CG_FDO_CTRL0, FDO_STATIC_DUTY, duty));
1054 return smu_v13_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC);
1058 smu_v13_0_set_fan_control_mode(struct smu_context *smu,
1064 case AMD_FAN_CTRL_NONE:
1065 ret = smu_v13_0_set_fan_speed_percent(smu, 100);
1067 case AMD_FAN_CTRL_MANUAL:
1068 ret = smu_v13_0_auto_fan_control(smu, 0);
1070 case AMD_FAN_CTRL_AUTO:
1071 ret = smu_v13_0_auto_fan_control(smu, 1);
1078 dev_err(smu->adev->dev, "[%s]Set fan control mode failed!", __func__);
1085 int smu_v13_0_set_fan_speed_rpm(struct smu_context *smu,
1088 struct amdgpu_device *adev = smu->adev;
1090 uint32_t tach_period, crystal_clock_freq;
1095 ret = smu_v13_0_auto_fan_control(smu, 0);
1099 crystal_clock_freq = amdgpu_asic_get_xclk(adev);
1100 tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
1101 WREG32_SOC15(THM, 0, regCG_TACH_CTRL,
1102 REG_SET_FIELD(RREG32_SOC15(THM, 0, regCG_TACH_CTRL),
1103 CG_TACH_CTRL, TARGET_PERIOD,
1106 ret = smu_v13_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC_RPM);
1111 int smu_v13_0_set_xgmi_pstate(struct smu_context *smu,
1115 ret = smu_cmn_send_smc_msg_with_param(smu,
1116 SMU_MSG_SetXgmiMode,
1117 pstate ? XGMI_MODE_PSTATE_D0 : XGMI_MODE_PSTATE_D3,
1122 static int smu_v13_0_set_irq_state(struct amdgpu_device *adev,
1123 struct amdgpu_irq_src *source,
1125 enum amdgpu_interrupt_state state)
1127 struct smu_context *smu = &adev->smu;
1132 case AMDGPU_IRQ_STATE_DISABLE:
1134 val = RREG32_SOC15(THM, 0, regTHM_THERMAL_INT_CTRL);
1135 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTH_MASK, 1);
1136 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTL_MASK, 1);
1137 WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_CTRL, val);
1139 WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_ENA, 0);
1141 /* For MP1 SW irqs */
1142 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL);
1143 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT_CTRL, INT_MASK, 1);
1144 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL, val);
1147 case AMDGPU_IRQ_STATE_ENABLE:
1149 low = max(SMU_THERMAL_MINIMUM_ALERT_TEMP,
1150 smu->thermal_range.min / SMU_TEMPERATURE_UNITS_PER_CENTIGRADES);
1151 high = min(SMU_THERMAL_MAXIMUM_ALERT_TEMP,
1152 smu->thermal_range.software_shutdown_temp);
1154 val = RREG32_SOC15(THM, 0, regTHM_THERMAL_INT_CTRL);
1155 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, MAX_IH_CREDIT, 5);
1156 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_IH_HW_ENA, 1);
1157 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTH_MASK, 0);
1158 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, THERM_INTL_MASK, 0);
1159 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTH, (high & 0xff));
1160 val = REG_SET_FIELD(val, THM_THERMAL_INT_CTRL, DIG_THERM_INTL, (low & 0xff));
1161 val = val & (~THM_THERMAL_INT_CTRL__THERM_TRIGGER_MASK_MASK);
1162 WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_CTRL, val);
1164 val = (1 << THM_THERMAL_INT_ENA__THERM_INTH_CLR__SHIFT);
1165 val |= (1 << THM_THERMAL_INT_ENA__THERM_INTL_CLR__SHIFT);
1166 val |= (1 << THM_THERMAL_INT_ENA__THERM_TRIGGER_CLR__SHIFT);
1167 WREG32_SOC15(THM, 0, regTHM_THERMAL_INT_ENA, val);
1169 /* For MP1 SW irqs */
1170 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT);
1171 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, ID, 0xFE);
1172 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, VALID, 0);
1173 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT, val);
1175 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL);
1176 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT_CTRL, INT_MASK, 0);
1177 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL, val);
1187 static int smu_v13_0_ack_ac_dc_interrupt(struct smu_context *smu)
1189 return smu_cmn_send_smc_msg(smu,
1190 SMU_MSG_ReenableAcDcInterrupt,
1194 #define THM_11_0__SRCID__THM_DIG_THERM_L2H 0 /* ASIC_TEMP > CG_THERMAL_INT.DIG_THERM_INTH */
1195 #define THM_11_0__SRCID__THM_DIG_THERM_H2L 1 /* ASIC_TEMP < CG_THERMAL_INT.DIG_THERM_INTL */
1196 #define SMUIO_11_0__SRCID__SMUIO_GPIO19 83
1198 static int smu_v13_0_irq_process(struct amdgpu_device *adev,
1199 struct amdgpu_irq_src *source,
1200 struct amdgpu_iv_entry *entry)
1202 struct smu_context *smu = &adev->smu;
1203 uint32_t client_id = entry->client_id;
1204 uint32_t src_id = entry->src_id;
1206 * ctxid is used to distinguish different
1207 * events for SMCToHost interrupt.
1209 uint32_t ctxid = entry->src_data[0];
1212 if (client_id == SOC15_IH_CLIENTID_THM) {
1214 case THM_11_0__SRCID__THM_DIG_THERM_L2H:
1215 dev_emerg(adev->dev, "ERROR: GPU over temperature range(SW CTF) detected!\n");
1217 * SW CTF just occurred.
1218 * Try to do a graceful shutdown to prevent further damage.
1220 dev_emerg(adev->dev, "ERROR: System is going to shutdown due to GPU SW CTF!\n");
1221 orderly_poweroff(true);
1223 case THM_11_0__SRCID__THM_DIG_THERM_H2L:
1224 dev_emerg(adev->dev, "ERROR: GPU under temperature range detected\n");
1227 dev_emerg(adev->dev, "ERROR: GPU under temperature range unknown src id (%d)\n",
1231 } else if (client_id == SOC15_IH_CLIENTID_ROM_SMUIO) {
1232 dev_emerg(adev->dev, "ERROR: GPU HW Critical Temperature Fault(aka CTF) detected!\n");
1234 * HW CTF just occurred. Shutdown to prevent further damage.
1236 dev_emerg(adev->dev, "ERROR: System is going to shutdown due to GPU HW CTF!\n");
1237 orderly_poweroff(true);
1238 } else if (client_id == SOC15_IH_CLIENTID_MP1) {
1239 if (src_id == 0xfe) {
1240 /* ACK SMUToHost interrupt */
1241 data = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL);
1242 data = REG_SET_FIELD(data, MP1_SMN_IH_SW_INT_CTRL, INT_ACK, 1);
1243 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL, data);
1247 dev_dbg(adev->dev, "Switched to AC mode!\n");
1248 smu_v13_0_ack_ac_dc_interrupt(&adev->smu);
1251 dev_dbg(adev->dev, "Switched to DC mode!\n");
1252 smu_v13_0_ack_ac_dc_interrupt(&adev->smu);
1256 * Increment the throttle interrupt counter
1258 atomic64_inc(&smu->throttle_int_counter);
1260 if (!atomic_read(&adev->throttling_logging_enabled))
1263 if (__ratelimit(&adev->throttling_logging_rs))
1264 schedule_work(&smu->throttling_logging_work);
1274 static const struct amdgpu_irq_src_funcs smu_v13_0_irq_funcs =
1276 .set = smu_v13_0_set_irq_state,
1277 .process = smu_v13_0_irq_process,
1280 int smu_v13_0_register_irq_handler(struct smu_context *smu)
1282 struct amdgpu_device *adev = smu->adev;
1283 struct amdgpu_irq_src *irq_src = &smu->irq_source;
1286 irq_src->num_types = 1;
1287 irq_src->funcs = &smu_v13_0_irq_funcs;
1289 ret = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_THM,
1290 THM_11_0__SRCID__THM_DIG_THERM_L2H,
1295 ret = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_THM,
1296 THM_11_0__SRCID__THM_DIG_THERM_H2L,
1301 /* Register CTF(GPIO_19) interrupt */
1302 ret = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_ROM_SMUIO,
1303 SMUIO_11_0__SRCID__SMUIO_GPIO19,
1308 ret = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_MP1,
1317 int smu_v13_0_get_max_sustainable_clocks_by_dc(struct smu_context *smu,
1318 struct pp_smu_nv_clock_table *max_clocks)
1320 struct smu_table_context *table_context = &smu->smu_table;
1321 struct smu_13_0_max_sustainable_clocks *sustainable_clocks = NULL;
1323 if (!max_clocks || !table_context->max_sustainable_clocks)
1326 sustainable_clocks = table_context->max_sustainable_clocks;
1328 max_clocks->dcfClockInKhz =
1329 (unsigned int) sustainable_clocks->dcef_clock * 1000;
1330 max_clocks->displayClockInKhz =
1331 (unsigned int) sustainable_clocks->display_clock * 1000;
1332 max_clocks->phyClockInKhz =
1333 (unsigned int) sustainable_clocks->phy_clock * 1000;
1334 max_clocks->pixelClockInKhz =
1335 (unsigned int) sustainable_clocks->pixel_clock * 1000;
1336 max_clocks->uClockInKhz =
1337 (unsigned int) sustainable_clocks->uclock * 1000;
1338 max_clocks->socClockInKhz =
1339 (unsigned int) sustainable_clocks->soc_clock * 1000;
1340 max_clocks->dscClockInKhz = 0;
1341 max_clocks->dppClockInKhz = 0;
1342 max_clocks->fabricClockInKhz = 0;
1347 int smu_v13_0_set_azalia_d3_pme(struct smu_context *smu)
1351 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_BacoAudioD3PME, NULL);
1356 int smu_v13_0_mode1_reset(struct smu_context *smu)
1361 * PM FW support SMU_MSG_GfxDeviceDriverReset from 68.07
1363 smu_cmn_get_smc_version(smu, NULL, &smu_version);
1364 if (smu_version < 0x00440700)
1365 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_Mode1Reset, NULL);
1367 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GfxDeviceDriverReset, SMU_RESET_MODE_1, NULL);
1370 msleep(SMU13_MODE1_RESET_WAIT_TIME_IN_MS);
1375 static int smu_v13_0_wait_for_reset_complete(struct smu_context *smu,
1380 dev_dbg(smu->adev->dev, "waiting for smu reset complete\n");
1381 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_GfxDriverResetRecovery, NULL);
1386 int smu_v13_0_wait_for_event(struct smu_context *smu, enum smu_event_type event,
1392 case SMU_EVENT_RESET_COMPLETE:
1393 ret = smu_v13_0_wait_for_reset_complete(smu, event_arg);
1402 int smu_v13_0_mode2_reset(struct smu_context *smu)
1406 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GfxDeviceDriverReset,
1407 SMU_RESET_MODE_2, NULL);
1408 /*TODO: mode2 reset wait time should be shorter, add ASIC specific func if required */
1410 msleep(SMU13_MODE1_RESET_WAIT_TIME_IN_MS);
1415 int smu_v13_0_get_dpm_ultimate_freq(struct smu_context *smu, enum smu_clk_type clk_type,
1416 uint32_t *min, uint32_t *max)
1418 int ret = 0, clk_id = 0;
1420 uint32_t clock_limit;
1422 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type)) {
1426 clock_limit = smu->smu_table.boot_values.uclk;
1430 clock_limit = smu->smu_table.boot_values.gfxclk;
1433 clock_limit = smu->smu_table.boot_values.socclk;
1440 /* clock in Mhz unit */
1442 *min = clock_limit / 100;
1444 *max = clock_limit / 100;
1449 clk_id = smu_cmn_to_asic_specific_index(smu,
1450 CMN2ASIC_MAPPING_CLK,
1456 param = (clk_id & 0xffff) << 16;
1459 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GetMaxDpmFreq, param, max);
1465 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GetMinDpmFreq, param, min);
1474 int smu_v13_0_set_soft_freq_limited_range(struct smu_context *smu,
1475 enum smu_clk_type clk_type,
1479 struct amdgpu_device *adev = smu->adev;
1480 int ret = 0, clk_id = 0;
1483 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1486 clk_id = smu_cmn_to_asic_specific_index(smu,
1487 CMN2ASIC_MAPPING_CLK,
1492 if (clk_type == SMU_GFXCLK)
1493 amdgpu_gfx_off_ctrl(adev, false);
1496 param = (uint32_t)((clk_id << 16) | (max & 0xffff));
1497 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxByFreq,
1504 param = (uint32_t)((clk_id << 16) | (min & 0xffff));
1505 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMinByFreq,
1512 if (clk_type == SMU_GFXCLK)
1513 amdgpu_gfx_off_ctrl(adev, true);
1518 int smu_v13_0_set_hard_freq_limited_range(struct smu_context *smu,
1519 enum smu_clk_type clk_type,
1523 int ret = 0, clk_id = 0;
1526 if (min <= 0 && max <= 0)
1529 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1532 clk_id = smu_cmn_to_asic_specific_index(smu,
1533 CMN2ASIC_MAPPING_CLK,
1539 param = (uint32_t)((clk_id << 16) | (max & 0xffff));
1540 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMaxByFreq,
1547 param = (uint32_t)((clk_id << 16) | (min & 0xffff));
1548 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinByFreq,
1557 int smu_v13_0_set_performance_level(struct smu_context *smu,
1558 enum amd_dpm_forced_level level)
1560 struct smu_13_0_dpm_context *dpm_context =
1561 smu->smu_dpm.dpm_context;
1562 struct smu_13_0_dpm_table *gfx_table =
1563 &dpm_context->dpm_tables.gfx_table;
1564 struct smu_13_0_dpm_table *mem_table =
1565 &dpm_context->dpm_tables.uclk_table;
1566 struct smu_13_0_dpm_table *soc_table =
1567 &dpm_context->dpm_tables.soc_table;
1568 struct smu_umd_pstate_table *pstate_table =
1570 struct amdgpu_device *adev = smu->adev;
1571 uint32_t sclk_min = 0, sclk_max = 0;
1572 uint32_t mclk_min = 0, mclk_max = 0;
1573 uint32_t socclk_min = 0, socclk_max = 0;
1577 case AMD_DPM_FORCED_LEVEL_HIGH:
1578 sclk_min = sclk_max = gfx_table->max;
1579 mclk_min = mclk_max = mem_table->max;
1580 socclk_min = socclk_max = soc_table->max;
1582 case AMD_DPM_FORCED_LEVEL_LOW:
1583 sclk_min = sclk_max = gfx_table->min;
1584 mclk_min = mclk_max = mem_table->min;
1585 socclk_min = socclk_max = soc_table->min;
1587 case AMD_DPM_FORCED_LEVEL_AUTO:
1588 sclk_min = gfx_table->min;
1589 sclk_max = gfx_table->max;
1590 mclk_min = mem_table->min;
1591 mclk_max = mem_table->max;
1592 socclk_min = soc_table->min;
1593 socclk_max = soc_table->max;
1595 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
1596 sclk_min = sclk_max = pstate_table->gfxclk_pstate.standard;
1597 mclk_min = mclk_max = pstate_table->uclk_pstate.standard;
1598 socclk_min = socclk_max = pstate_table->socclk_pstate.standard;
1600 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
1601 sclk_min = sclk_max = pstate_table->gfxclk_pstate.min;
1603 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
1604 mclk_min = mclk_max = pstate_table->uclk_pstate.min;
1606 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
1607 sclk_min = sclk_max = pstate_table->gfxclk_pstate.peak;
1608 mclk_min = mclk_max = pstate_table->uclk_pstate.peak;
1609 socclk_min = socclk_max = pstate_table->socclk_pstate.peak;
1611 case AMD_DPM_FORCED_LEVEL_MANUAL:
1612 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
1615 dev_err(adev->dev, "Invalid performance level %d\n", level);
1619 mclk_min = mclk_max = 0;
1620 socclk_min = socclk_max = 0;
1622 if (sclk_min && sclk_max) {
1623 ret = smu_v13_0_set_soft_freq_limited_range(smu,
1630 pstate_table->gfxclk_pstate.curr.min = sclk_min;
1631 pstate_table->gfxclk_pstate.curr.max = sclk_max;
1634 if (mclk_min && mclk_max) {
1635 ret = smu_v13_0_set_soft_freq_limited_range(smu,
1642 pstate_table->uclk_pstate.curr.min = mclk_min;
1643 pstate_table->uclk_pstate.curr.max = mclk_max;
1646 if (socclk_min && socclk_max) {
1647 ret = smu_v13_0_set_soft_freq_limited_range(smu,
1654 pstate_table->socclk_pstate.curr.min = socclk_min;
1655 pstate_table->socclk_pstate.curr.max = socclk_max;
1661 int smu_v13_0_set_power_source(struct smu_context *smu,
1662 enum smu_power_src_type power_src)
1666 pwr_source = smu_cmn_to_asic_specific_index(smu,
1667 CMN2ASIC_MAPPING_PWR,
1668 (uint32_t)power_src);
1672 return smu_cmn_send_smc_msg_with_param(smu,
1673 SMU_MSG_NotifyPowerSource,
1678 int smu_v13_0_get_dpm_freq_by_index(struct smu_context *smu,
1679 enum smu_clk_type clk_type,
1683 int ret = 0, clk_id = 0;
1689 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1692 clk_id = smu_cmn_to_asic_specific_index(smu,
1693 CMN2ASIC_MAPPING_CLK,
1698 param = (uint32_t)(((clk_id & 0xffff) << 16) | (level & 0xffff));
1700 ret = smu_cmn_send_smc_msg_with_param(smu,
1701 SMU_MSG_GetDpmFreqByIndex,
1708 * BIT31: 0 - Fine grained DPM, 1 - Dicrete DPM
1709 * now, we un-support it
1711 *value = *value & 0x7fffffff;
1716 int smu_v13_0_get_dpm_level_count(struct smu_context *smu,
1717 enum smu_clk_type clk_type,
1722 ret = smu_v13_0_get_dpm_freq_by_index(smu, clk_type, 0xff, value);
1723 /* FW returns 0 based max level, increment by one */
1730 int smu_v13_0_set_single_dpm_table(struct smu_context *smu,
1731 enum smu_clk_type clk_type,
1732 struct smu_13_0_dpm_table *single_dpm_table)
1738 ret = smu_v13_0_get_dpm_level_count(smu,
1740 &single_dpm_table->count);
1742 dev_err(smu->adev->dev, "[%s] failed to get dpm levels!\n", __func__);
1746 for (i = 0; i < single_dpm_table->count; i++) {
1747 ret = smu_v13_0_get_dpm_freq_by_index(smu,
1752 dev_err(smu->adev->dev, "[%s] failed to get dpm freq by index!\n", __func__);
1756 single_dpm_table->dpm_levels[i].value = clk;
1757 single_dpm_table->dpm_levels[i].enabled = true;
1760 single_dpm_table->min = clk;
1761 else if (i == single_dpm_table->count - 1)
1762 single_dpm_table->max = clk;
1768 int smu_v13_0_get_dpm_level_range(struct smu_context *smu,
1769 enum smu_clk_type clk_type,
1770 uint32_t *min_value,
1771 uint32_t *max_value)
1773 uint32_t level_count = 0;
1776 if (!min_value && !max_value)
1780 /* by default, level 0 clock value as min value */
1781 ret = smu_v13_0_get_dpm_freq_by_index(smu,
1790 ret = smu_v13_0_get_dpm_level_count(smu,
1796 ret = smu_v13_0_get_dpm_freq_by_index(smu,
1807 int smu_v13_0_get_current_pcie_link_width_level(struct smu_context *smu)
1809 struct amdgpu_device *adev = smu->adev;
1811 return (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
1812 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
1813 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
1816 int smu_v13_0_get_current_pcie_link_width(struct smu_context *smu)
1818 uint32_t width_level;
1820 width_level = smu_v13_0_get_current_pcie_link_width_level(smu);
1821 if (width_level > LINK_WIDTH_MAX)
1824 return link_width[width_level];
1827 int smu_v13_0_get_current_pcie_link_speed_level(struct smu_context *smu)
1829 struct amdgpu_device *adev = smu->adev;
1831 return (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
1832 PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
1833 >> PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
1836 int smu_v13_0_get_current_pcie_link_speed(struct smu_context *smu)
1838 uint32_t speed_level;
1840 speed_level = smu_v13_0_get_current_pcie_link_speed_level(smu);
1841 if (speed_level > LINK_SPEED_MAX)
1844 return link_speed[speed_level];