2 * Copyright 2023 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 SWSMU_CODE_LAYER_L3
31 #include "amdgpu_smu.h"
32 #include "atomfirmware.h"
33 #include "amdgpu_atomfirmware.h"
34 #include "amdgpu_atombios.h"
35 #include "smu_v14_0.h"
36 #include "soc15_common.h"
38 #include "amdgpu_ras.h"
41 #include "asic_reg/mp/mp_14_0_0_offset.h"
42 #include "asic_reg/mp/mp_14_0_0_sh_mask.h"
45 * DO NOT use these for err/warn/info/debug messages.
46 * Use dev_err, dev_warn, dev_info and dev_dbg instead.
47 * They are more MGPU friendly.
54 MODULE_FIRMWARE("amdgpu/smu_14_0_2.bin");
56 int smu_v14_0_init_microcode(struct smu_context *smu)
58 struct amdgpu_device *adev = smu->adev;
60 char ucode_prefix[15];
62 const struct smc_firmware_header_v1_0 *hdr;
63 const struct common_firmware_header *header;
64 struct amdgpu_firmware_info *ucode = NULL;
66 /* doesn't need to load smu firmware in IOV mode */
67 if (amdgpu_sriov_vf(adev))
70 amdgpu_ucode_ip_version_decode(adev, MP1_HWIP, ucode_prefix, sizeof(ucode_prefix));
72 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s.bin", ucode_prefix);
74 err = amdgpu_ucode_request(adev, &adev->pm.fw, fw_name);
78 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
79 amdgpu_ucode_print_smc_hdr(&hdr->header);
80 adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
82 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
83 ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
84 ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
85 ucode->fw = adev->pm.fw;
86 header = (const struct common_firmware_header *)ucode->fw->data;
87 adev->firmware.fw_size +=
88 ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
93 amdgpu_ucode_release(&adev->pm.fw);
97 void smu_v14_0_fini_microcode(struct smu_context *smu)
99 struct amdgpu_device *adev = smu->adev;
101 amdgpu_ucode_release(&adev->pm.fw);
102 adev->pm.fw_version = 0;
105 int smu_v14_0_load_microcode(struct smu_context *smu)
108 struct amdgpu_device *adev = smu->adev;
110 const struct smc_firmware_header_v1_0 *hdr;
111 uint32_t addr_start = MP1_SRAM;
113 uint32_t smc_fw_size;
114 uint32_t mp1_fw_flags;
116 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
117 src = (const uint32_t *)(adev->pm.fw->data +
118 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
119 smc_fw_size = hdr->header.ucode_size_bytes;
121 for (i = 1; i < smc_fw_size/4 - 1; i++) {
122 WREG32_PCIE(addr_start, src[i]);
126 WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
127 1 & MP1_SMN_PUB_CTRL__LX3_RESET_MASK);
128 WREG32_PCIE(MP1_Public | (smnMP1_PUB_CTRL & 0xffffffff),
129 1 & ~MP1_SMN_PUB_CTRL__LX3_RESET_MASK);
131 for (i = 0; i < adev->usec_timeout; i++) {
132 mp1_fw_flags = RREG32_PCIE(MP1_Public |
133 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
134 if ((mp1_fw_flags & MP1_CRU1_MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
135 MP1_CRU1_MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
140 if (i == adev->usec_timeout)
148 int smu_v14_0_init_pptable_microcode(struct smu_context *smu)
150 struct amdgpu_device *adev = smu->adev;
151 struct amdgpu_firmware_info *ucode = NULL;
152 uint32_t size = 0, pptable_id = 0;
156 /* doesn't need to load smu firmware in IOV mode */
157 if (amdgpu_sriov_vf(adev))
160 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
163 if (!adev->scpm_enabled)
166 /* override pptable_id from driver parameter */
167 if (amdgpu_smu_pptable_id >= 0) {
168 pptable_id = amdgpu_smu_pptable_id;
169 dev_info(adev->dev, "override pptable id %d\n", pptable_id);
171 pptable_id = smu->smu_table.boot_values.pp_table_id;
174 /* "pptable_id == 0" means vbios carries the pptable. */
178 ret = smu_v14_0_get_pptable_from_firmware(smu, &table, &size, pptable_id);
182 smu->pptable_firmware.data = table;
183 smu->pptable_firmware.size = size;
185 ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_PPTABLE];
186 ucode->ucode_id = AMDGPU_UCODE_ID_PPTABLE;
187 ucode->fw = &smu->pptable_firmware;
188 adev->firmware.fw_size +=
189 ALIGN(smu->pptable_firmware.size, PAGE_SIZE);
194 int smu_v14_0_check_fw_status(struct smu_context *smu)
196 struct amdgpu_device *adev = smu->adev;
197 uint32_t mp1_fw_flags;
199 mp1_fw_flags = RREG32_PCIE(MP1_Public |
200 (smnMP1_FIRMWARE_FLAGS & 0xffffffff));
202 if ((mp1_fw_flags & MP1_CRU1_MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) >>
203 MP1_CRU1_MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED__SHIFT)
209 int smu_v14_0_check_fw_version(struct smu_context *smu)
211 struct amdgpu_device *adev = smu->adev;
212 uint32_t if_version = 0xff, smu_version = 0xff;
213 uint8_t smu_program, smu_major, smu_minor, smu_debug;
216 ret = smu_cmn_get_smc_version(smu, &if_version, &smu_version);
220 smu_program = (smu_version >> 24) & 0xff;
221 smu_major = (smu_version >> 16) & 0xff;
222 smu_minor = (smu_version >> 8) & 0xff;
223 smu_debug = (smu_version >> 0) & 0xff;
225 adev->pm.fw_version = smu_version;
227 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
228 case IP_VERSION(14, 0, 2):
229 smu->smc_driver_if_version = SMU14_DRIVER_IF_VERSION_SMU_V14_0_2;
231 case IP_VERSION(14, 0, 0):
232 smu->smc_driver_if_version = SMU14_DRIVER_IF_VERSION_SMU_V14_0_0;
235 dev_err(adev->dev, "smu unsupported IP version: 0x%x.\n",
236 amdgpu_ip_version(adev, MP1_HWIP, 0));
237 smu->smc_driver_if_version = SMU14_DRIVER_IF_VERSION_INV;
242 dev_dbg(smu->adev->dev, "smu fw reported program %d, version = 0x%08x (%d.%d.%d)\n",
243 smu_program, smu_version, smu_major, smu_minor, smu_debug);
246 * 1. if_version mismatch is not critical as our fw is designed
247 * to be backward compatible.
248 * 2. New fw usually brings some optimizations. But that's visible
249 * only on the paired driver.
250 * Considering above, we just leave user a verbal message instead
251 * of halt driver loading.
253 if (if_version != smu->smc_driver_if_version) {
254 dev_info(adev->dev, "smu driver if version = 0x%08x, smu fw if version = 0x%08x, "
255 "smu fw program = %d, smu fw version = 0x%08x (%d.%d.%d)\n",
256 smu->smc_driver_if_version, if_version,
257 smu_program, smu_version, smu_major, smu_minor, smu_debug);
258 dev_info(adev->dev, "SMU driver if version not matched\n");
264 static int smu_v14_0_set_pptable_v2_0(struct smu_context *smu, void **table, uint32_t *size)
266 struct amdgpu_device *adev = smu->adev;
267 uint32_t ppt_offset_bytes;
268 const struct smc_firmware_header_v2_0 *v2;
270 v2 = (const struct smc_firmware_header_v2_0 *) adev->pm.fw->data;
272 ppt_offset_bytes = le32_to_cpu(v2->ppt_offset_bytes);
273 *size = le32_to_cpu(v2->ppt_size_bytes);
274 *table = (uint8_t *)v2 + ppt_offset_bytes;
279 static int smu_v14_0_set_pptable_v2_1(struct smu_context *smu, void **table,
280 uint32_t *size, uint32_t pptable_id)
282 struct amdgpu_device *adev = smu->adev;
283 const struct smc_firmware_header_v2_1 *v2_1;
284 struct smc_soft_pptable_entry *entries;
285 uint32_t pptable_count = 0;
288 v2_1 = (const struct smc_firmware_header_v2_1 *) adev->pm.fw->data;
289 entries = (struct smc_soft_pptable_entry *)
290 ((uint8_t *)v2_1 + le32_to_cpu(v2_1->pptable_entry_offset));
291 pptable_count = le32_to_cpu(v2_1->pptable_count);
292 for (i = 0; i < pptable_count; i++) {
293 if (le32_to_cpu(entries[i].id) == pptable_id) {
294 *table = ((uint8_t *)v2_1 + le32_to_cpu(entries[i].ppt_offset_bytes));
295 *size = le32_to_cpu(entries[i].ppt_size_bytes);
300 if (i == pptable_count)
306 static int smu_v14_0_get_pptable_from_vbios(struct smu_context *smu, void **table, uint32_t *size)
308 struct amdgpu_device *adev = smu->adev;
309 uint16_t atom_table_size;
313 dev_info(adev->dev, "use vbios provided pptable\n");
314 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
317 ret = amdgpu_atombios_get_data_table(adev, index, &atom_table_size, &frev, &crev,
323 *size = atom_table_size;
328 int smu_v14_0_get_pptable_from_firmware(struct smu_context *smu,
333 const struct smc_firmware_header_v1_0 *hdr;
334 struct amdgpu_device *adev = smu->adev;
335 uint16_t version_major, version_minor;
338 hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
342 dev_info(adev->dev, "use driver provided pptable %d\n", pptable_id);
344 version_major = le16_to_cpu(hdr->header.header_version_major);
345 version_minor = le16_to_cpu(hdr->header.header_version_minor);
346 if (version_major != 2) {
347 dev_err(adev->dev, "Unsupported smu firmware version %d.%d\n",
348 version_major, version_minor);
352 switch (version_minor) {
354 ret = smu_v14_0_set_pptable_v2_0(smu, table, size);
357 ret = smu_v14_0_set_pptable_v2_1(smu, table, size, pptable_id);
367 int smu_v14_0_setup_pptable(struct smu_context *smu)
369 struct amdgpu_device *adev = smu->adev;
370 uint32_t size = 0, pptable_id = 0;
374 /* override pptable_id from driver parameter */
375 if (amdgpu_smu_pptable_id >= 0) {
376 pptable_id = amdgpu_smu_pptable_id;
377 dev_info(adev->dev, "override pptable id %d\n", pptable_id);
379 pptable_id = smu->smu_table.boot_values.pp_table_id;
382 /* force using vbios pptable in sriov mode */
383 if ((amdgpu_sriov_vf(adev) || !pptable_id) && (amdgpu_emu_mode != 1))
384 ret = smu_v14_0_get_pptable_from_vbios(smu, &table, &size);
386 ret = smu_v14_0_get_pptable_from_firmware(smu, &table, &size, pptable_id);
391 if (!smu->smu_table.power_play_table)
392 smu->smu_table.power_play_table = table;
393 if (!smu->smu_table.power_play_table_size)
394 smu->smu_table.power_play_table_size = size;
399 int smu_v14_0_init_smc_tables(struct smu_context *smu)
401 struct smu_table_context *smu_table = &smu->smu_table;
402 struct smu_table *tables = smu_table->tables;
405 smu_table->driver_pptable =
406 kzalloc(tables[SMU_TABLE_PPTABLE].size, GFP_KERNEL);
407 if (!smu_table->driver_pptable) {
412 smu_table->max_sustainable_clocks =
413 kzalloc(sizeof(struct smu_14_0_max_sustainable_clocks), GFP_KERNEL);
414 if (!smu_table->max_sustainable_clocks) {
419 if (tables[SMU_TABLE_OVERDRIVE].size) {
420 smu_table->overdrive_table =
421 kzalloc(tables[SMU_TABLE_OVERDRIVE].size, GFP_KERNEL);
422 if (!smu_table->overdrive_table) {
427 smu_table->boot_overdrive_table =
428 kzalloc(tables[SMU_TABLE_OVERDRIVE].size, GFP_KERNEL);
429 if (!smu_table->boot_overdrive_table) {
435 smu_table->combo_pptable =
436 kzalloc(tables[SMU_TABLE_COMBO_PPTABLE].size, GFP_KERNEL);
437 if (!smu_table->combo_pptable) {
445 kfree(smu_table->boot_overdrive_table);
447 kfree(smu_table->overdrive_table);
449 kfree(smu_table->max_sustainable_clocks);
451 kfree(smu_table->driver_pptable);
456 int smu_v14_0_fini_smc_tables(struct smu_context *smu)
458 struct smu_table_context *smu_table = &smu->smu_table;
459 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
461 kfree(smu_table->gpu_metrics_table);
462 kfree(smu_table->combo_pptable);
463 kfree(smu_table->boot_overdrive_table);
464 kfree(smu_table->overdrive_table);
465 kfree(smu_table->max_sustainable_clocks);
466 kfree(smu_table->driver_pptable);
467 smu_table->gpu_metrics_table = NULL;
468 smu_table->combo_pptable = NULL;
469 smu_table->boot_overdrive_table = NULL;
470 smu_table->overdrive_table = NULL;
471 smu_table->max_sustainable_clocks = NULL;
472 smu_table->driver_pptable = NULL;
473 kfree(smu_table->hardcode_pptable);
474 smu_table->hardcode_pptable = NULL;
476 kfree(smu_table->ecc_table);
477 kfree(smu_table->metrics_table);
478 kfree(smu_table->watermarks_table);
479 smu_table->ecc_table = NULL;
480 smu_table->metrics_table = NULL;
481 smu_table->watermarks_table = NULL;
482 smu_table->metrics_time = 0;
484 kfree(smu_dpm->dpm_context);
485 kfree(smu_dpm->golden_dpm_context);
486 kfree(smu_dpm->dpm_current_power_state);
487 kfree(smu_dpm->dpm_request_power_state);
488 smu_dpm->dpm_context = NULL;
489 smu_dpm->golden_dpm_context = NULL;
490 smu_dpm->dpm_context_size = 0;
491 smu_dpm->dpm_current_power_state = NULL;
492 smu_dpm->dpm_request_power_state = NULL;
497 int smu_v14_0_init_power(struct smu_context *smu)
499 struct smu_power_context *smu_power = &smu->smu_power;
501 if (smu_power->power_context || smu_power->power_context_size != 0)
504 smu_power->power_context = kzalloc(sizeof(struct smu_14_0_dpm_context),
506 if (!smu_power->power_context)
508 smu_power->power_context_size = sizeof(struct smu_14_0_dpm_context);
513 int smu_v14_0_fini_power(struct smu_context *smu)
515 struct smu_power_context *smu_power = &smu->smu_power;
517 if (!smu_power->power_context || smu_power->power_context_size == 0)
520 kfree(smu_power->power_context);
521 smu_power->power_context = NULL;
522 smu_power->power_context_size = 0;
527 int smu_v14_0_get_vbios_bootup_values(struct smu_context *smu)
532 struct atom_common_table_header *header;
533 struct atom_firmware_info_v3_4 *v_3_4;
534 struct atom_firmware_info_v3_3 *v_3_3;
535 struct atom_firmware_info_v3_1 *v_3_1;
536 struct atom_smu_info_v3_6 *smu_info_v3_6;
537 struct atom_smu_info_v4_0 *smu_info_v4_0;
539 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
542 ret = amdgpu_atombios_get_data_table(smu->adev, index, &size, &frev, &crev,
543 (uint8_t **)&header);
547 if (header->format_revision != 3) {
548 dev_err(smu->adev->dev, "unknown atom_firmware_info version! for smu14\n");
552 switch (header->content_revision) {
556 v_3_1 = (struct atom_firmware_info_v3_1 *)header;
557 smu->smu_table.boot_values.revision = v_3_1->firmware_revision;
558 smu->smu_table.boot_values.gfxclk = v_3_1->bootup_sclk_in10khz;
559 smu->smu_table.boot_values.uclk = v_3_1->bootup_mclk_in10khz;
560 smu->smu_table.boot_values.socclk = 0;
561 smu->smu_table.boot_values.dcefclk = 0;
562 smu->smu_table.boot_values.vddc = v_3_1->bootup_vddc_mv;
563 smu->smu_table.boot_values.vddci = v_3_1->bootup_vddci_mv;
564 smu->smu_table.boot_values.mvddc = v_3_1->bootup_mvddc_mv;
565 smu->smu_table.boot_values.vdd_gfx = v_3_1->bootup_vddgfx_mv;
566 smu->smu_table.boot_values.cooling_id = v_3_1->coolingsolution_id;
567 smu->smu_table.boot_values.pp_table_id = 0;
570 v_3_3 = (struct atom_firmware_info_v3_3 *)header;
571 smu->smu_table.boot_values.revision = v_3_3->firmware_revision;
572 smu->smu_table.boot_values.gfxclk = v_3_3->bootup_sclk_in10khz;
573 smu->smu_table.boot_values.uclk = v_3_3->bootup_mclk_in10khz;
574 smu->smu_table.boot_values.socclk = 0;
575 smu->smu_table.boot_values.dcefclk = 0;
576 smu->smu_table.boot_values.vddc = v_3_3->bootup_vddc_mv;
577 smu->smu_table.boot_values.vddci = v_3_3->bootup_vddci_mv;
578 smu->smu_table.boot_values.mvddc = v_3_3->bootup_mvddc_mv;
579 smu->smu_table.boot_values.vdd_gfx = v_3_3->bootup_vddgfx_mv;
580 smu->smu_table.boot_values.cooling_id = v_3_3->coolingsolution_id;
581 smu->smu_table.boot_values.pp_table_id = v_3_3->pplib_pptable_id;
585 v_3_4 = (struct atom_firmware_info_v3_4 *)header;
586 smu->smu_table.boot_values.revision = v_3_4->firmware_revision;
587 smu->smu_table.boot_values.gfxclk = v_3_4->bootup_sclk_in10khz;
588 smu->smu_table.boot_values.uclk = v_3_4->bootup_mclk_in10khz;
589 smu->smu_table.boot_values.socclk = 0;
590 smu->smu_table.boot_values.dcefclk = 0;
591 smu->smu_table.boot_values.vddc = v_3_4->bootup_vddc_mv;
592 smu->smu_table.boot_values.vddci = v_3_4->bootup_vddci_mv;
593 smu->smu_table.boot_values.mvddc = v_3_4->bootup_mvddc_mv;
594 smu->smu_table.boot_values.vdd_gfx = v_3_4->bootup_vddgfx_mv;
595 smu->smu_table.boot_values.cooling_id = v_3_4->coolingsolution_id;
596 smu->smu_table.boot_values.pp_table_id = v_3_4->pplib_pptable_id;
600 smu->smu_table.boot_values.format_revision = header->format_revision;
601 smu->smu_table.boot_values.content_revision = header->content_revision;
603 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
605 if (!amdgpu_atombios_get_data_table(smu->adev, index, &size, &frev, &crev,
606 (uint8_t **)&header)) {
608 if ((frev == 3) && (crev == 6)) {
609 smu_info_v3_6 = (struct atom_smu_info_v3_6 *)header;
611 smu->smu_table.boot_values.socclk = smu_info_v3_6->bootup_socclk_10khz;
612 smu->smu_table.boot_values.vclk = smu_info_v3_6->bootup_vclk_10khz;
613 smu->smu_table.boot_values.dclk = smu_info_v3_6->bootup_dclk_10khz;
614 smu->smu_table.boot_values.fclk = smu_info_v3_6->bootup_fclk_10khz;
615 } else if ((frev == 3) && (crev == 1)) {
617 } else if ((frev == 4) && (crev == 0)) {
618 smu_info_v4_0 = (struct atom_smu_info_v4_0 *)header;
620 smu->smu_table.boot_values.socclk = smu_info_v4_0->bootup_socclk_10khz;
621 smu->smu_table.boot_values.dcefclk = smu_info_v4_0->bootup_dcefclk_10khz;
622 smu->smu_table.boot_values.vclk = smu_info_v4_0->bootup_vclk0_10khz;
623 smu->smu_table.boot_values.dclk = smu_info_v4_0->bootup_dclk0_10khz;
624 smu->smu_table.boot_values.fclk = smu_info_v4_0->bootup_fclk_10khz;
626 dev_warn(smu->adev->dev, "Unexpected and unhandled version: %d.%d\n",
627 (uint32_t)frev, (uint32_t)crev);
635 int smu_v14_0_notify_memory_pool_location(struct smu_context *smu)
637 struct smu_table_context *smu_table = &smu->smu_table;
638 struct smu_table *memory_pool = &smu_table->memory_pool;
641 uint32_t address_low, address_high;
643 if (memory_pool->size == 0 || memory_pool->cpu_addr == NULL)
646 address = memory_pool->mc_address;
647 address_high = (uint32_t)upper_32_bits(address);
648 address_low = (uint32_t)lower_32_bits(address);
650 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrHigh,
654 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramAddrLow,
658 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_DramLogSetDramSize,
659 (uint32_t)memory_pool->size, NULL);
666 int smu_v14_0_set_driver_table_location(struct smu_context *smu)
668 struct smu_table *driver_table = &smu->smu_table.driver_table;
671 if (driver_table->mc_address) {
672 ret = smu_cmn_send_smc_msg_with_param(smu,
673 SMU_MSG_SetDriverDramAddrHigh,
674 upper_32_bits(driver_table->mc_address),
677 ret = smu_cmn_send_smc_msg_with_param(smu,
678 SMU_MSG_SetDriverDramAddrLow,
679 lower_32_bits(driver_table->mc_address),
686 int smu_v14_0_set_tool_table_location(struct smu_context *smu)
689 struct smu_table *tool_table = &smu->smu_table.tables[SMU_TABLE_PMSTATUSLOG];
691 if (tool_table->mc_address) {
692 ret = smu_cmn_send_smc_msg_with_param(smu,
693 SMU_MSG_SetToolsDramAddrHigh,
694 upper_32_bits(tool_table->mc_address),
697 ret = smu_cmn_send_smc_msg_with_param(smu,
698 SMU_MSG_SetToolsDramAddrLow,
699 lower_32_bits(tool_table->mc_address),
706 int smu_v14_0_set_allowed_mask(struct smu_context *smu)
708 struct smu_feature *feature = &smu->smu_feature;
710 uint32_t feature_mask[2];
712 if (bitmap_empty(feature->allowed, SMU_FEATURE_MAX) ||
713 feature->feature_num < 64)
716 bitmap_to_arr32(feature_mask, feature->allowed, 64);
718 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetAllowedFeaturesMaskHigh,
719 feature_mask[1], NULL);
723 return smu_cmn_send_smc_msg_with_param(smu,
724 SMU_MSG_SetAllowedFeaturesMaskLow,
729 int smu_v14_0_gfx_off_control(struct smu_context *smu, bool enable)
732 struct amdgpu_device *adev = smu->adev;
734 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
735 case IP_VERSION(14, 0, 2):
736 case IP_VERSION(14, 0, 0):
737 if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))
740 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_AllowGfxOff, NULL);
742 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_DisallowGfxOff, NULL);
751 int smu_v14_0_system_features_control(struct smu_context *smu,
754 return smu_cmn_send_smc_msg(smu, (en ? SMU_MSG_EnableAllSmuFeatures :
755 SMU_MSG_DisableAllSmuFeatures), NULL);
758 int smu_v14_0_notify_display_change(struct smu_context *smu)
762 if (!smu->pm_enabled)
765 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT) &&
766 smu->adev->gmc.vram_type == AMDGPU_VRAM_TYPE_HBM)
767 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetUclkFastSwitch, 1, NULL);
772 int smu_v14_0_get_current_power_limit(struct smu_context *smu,
773 uint32_t *power_limit)
778 if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT))
781 power_src = smu_cmn_to_asic_specific_index(smu,
782 CMN2ASIC_MAPPING_PWR,
783 smu->adev->pm.ac_power ?
784 SMU_POWER_SOURCE_AC :
785 SMU_POWER_SOURCE_DC);
789 ret = smu_cmn_send_smc_msg_with_param(smu,
794 dev_err(smu->adev->dev, "[%s] get PPT limit failed!", __func__);
799 int smu_v14_0_set_power_limit(struct smu_context *smu,
800 enum smu_ppt_limit_type limit_type,
805 if (limit_type != SMU_DEFAULT_PPT_LIMIT)
808 if (!smu_cmn_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
809 dev_err(smu->adev->dev, "Setting new power limit is not supported!\n");
813 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetPptLimit, limit, NULL);
815 dev_err(smu->adev->dev, "[%s] Set power limit Failed!\n", __func__);
819 smu->current_power_limit = limit;
824 static int smu_v14_0_set_irq_state(struct amdgpu_device *adev,
825 struct amdgpu_irq_src *source,
827 enum amdgpu_interrupt_state state)
832 case AMDGPU_IRQ_STATE_DISABLE:
836 /* For MP1 SW irqs */
837 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL);
838 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT_CTRL, INT_MASK, 1);
839 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL, val);
842 case AMDGPU_IRQ_STATE_ENABLE:
846 /* For MP1 SW irqs */
847 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT);
848 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, ID, 0xFE);
849 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT, VALID, 0);
850 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT, val);
852 val = RREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL);
853 val = REG_SET_FIELD(val, MP1_SMN_IH_SW_INT_CTRL, INT_MASK, 0);
854 WREG32_SOC15(MP1, 0, regMP1_SMN_IH_SW_INT_CTRL, val);
864 static int smu_v14_0_irq_process(struct amdgpu_device *adev,
865 struct amdgpu_irq_src *source,
866 struct amdgpu_iv_entry *entry)
873 static const struct amdgpu_irq_src_funcs smu_v14_0_irq_funcs = {
874 .set = smu_v14_0_set_irq_state,
875 .process = smu_v14_0_irq_process,
878 int smu_v14_0_register_irq_handler(struct smu_context *smu)
880 struct amdgpu_device *adev = smu->adev;
881 struct amdgpu_irq_src *irq_src = &smu->irq_source;
884 if (amdgpu_sriov_vf(adev))
887 irq_src->num_types = 1;
888 irq_src->funcs = &smu_v14_0_irq_funcs;
892 ret = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_MP1,
893 SMU_IH_INTERRUPT_ID_TO_DRIVER,
901 static int smu_v14_0_wait_for_reset_complete(struct smu_context *smu,
906 dev_dbg(smu->adev->dev, "waiting for smu reset complete\n");
907 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_GfxDriverResetRecovery, NULL);
912 int smu_v14_0_wait_for_event(struct smu_context *smu, enum smu_event_type event,
918 case SMU_EVENT_RESET_COMPLETE:
919 ret = smu_v14_0_wait_for_reset_complete(smu, event_arg);
928 int smu_v14_0_get_dpm_ultimate_freq(struct smu_context *smu, enum smu_clk_type clk_type,
929 uint32_t *min, uint32_t *max)
931 int ret = 0, clk_id = 0;
933 uint32_t clock_limit;
935 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type)) {
939 clock_limit = smu->smu_table.boot_values.uclk;
943 clock_limit = smu->smu_table.boot_values.gfxclk;
946 clock_limit = smu->smu_table.boot_values.socclk;
953 /* clock in Mhz unit */
955 *min = clock_limit / 100;
957 *max = clock_limit / 100;
962 clk_id = smu_cmn_to_asic_specific_index(smu,
963 CMN2ASIC_MAPPING_CLK,
969 param = (clk_id & 0xffff) << 16;
972 if (smu->adev->pm.ac_power)
973 ret = smu_cmn_send_smc_msg_with_param(smu,
974 SMU_MSG_GetMaxDpmFreq,
978 ret = smu_cmn_send_smc_msg_with_param(smu,
979 SMU_MSG_GetDcModeMaxDpmFreq,
987 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GetMinDpmFreq, param, min);
996 int smu_v14_0_set_soft_freq_limited_range(struct smu_context *smu,
997 enum smu_clk_type clk_type,
1001 int ret = 0, clk_id = 0;
1004 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1007 clk_id = smu_cmn_to_asic_specific_index(smu,
1008 CMN2ASIC_MAPPING_CLK,
1014 param = (uint32_t)((clk_id << 16) | (max & 0xffff));
1015 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxByFreq,
1022 param = (uint32_t)((clk_id << 16) | (min & 0xffff));
1023 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMinByFreq,
1033 int smu_v14_0_set_hard_freq_limited_range(struct smu_context *smu,
1034 enum smu_clk_type clk_type,
1038 int ret = 0, clk_id = 0;
1041 if (min <= 0 && max <= 0)
1044 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1047 clk_id = smu_cmn_to_asic_specific_index(smu,
1048 CMN2ASIC_MAPPING_CLK,
1054 param = (uint32_t)((clk_id << 16) | (max & 0xffff));
1055 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMaxByFreq,
1062 param = (uint32_t)((clk_id << 16) | (min & 0xffff));
1063 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinByFreq,
1072 int smu_v14_0_set_performance_level(struct smu_context *smu,
1073 enum amd_dpm_forced_level level)
1075 struct smu_14_0_dpm_context *dpm_context =
1076 smu->smu_dpm.dpm_context;
1077 struct smu_14_0_dpm_table *gfx_table =
1078 &dpm_context->dpm_tables.gfx_table;
1079 struct smu_14_0_dpm_table *mem_table =
1080 &dpm_context->dpm_tables.uclk_table;
1081 struct smu_14_0_dpm_table *soc_table =
1082 &dpm_context->dpm_tables.soc_table;
1083 struct smu_14_0_dpm_table *vclk_table =
1084 &dpm_context->dpm_tables.vclk_table;
1085 struct smu_14_0_dpm_table *dclk_table =
1086 &dpm_context->dpm_tables.dclk_table;
1087 struct smu_14_0_dpm_table *fclk_table =
1088 &dpm_context->dpm_tables.fclk_table;
1089 struct smu_umd_pstate_table *pstate_table =
1091 struct amdgpu_device *adev = smu->adev;
1092 uint32_t sclk_min = 0, sclk_max = 0;
1093 uint32_t mclk_min = 0, mclk_max = 0;
1094 uint32_t socclk_min = 0, socclk_max = 0;
1095 uint32_t vclk_min = 0, vclk_max = 0;
1096 uint32_t dclk_min = 0, dclk_max = 0;
1097 uint32_t fclk_min = 0, fclk_max = 0;
1101 case AMD_DPM_FORCED_LEVEL_HIGH:
1102 sclk_min = sclk_max = gfx_table->max;
1103 mclk_min = mclk_max = mem_table->max;
1104 socclk_min = socclk_max = soc_table->max;
1105 vclk_min = vclk_max = vclk_table->max;
1106 dclk_min = dclk_max = dclk_table->max;
1107 fclk_min = fclk_max = fclk_table->max;
1109 case AMD_DPM_FORCED_LEVEL_LOW:
1110 sclk_min = sclk_max = gfx_table->min;
1111 mclk_min = mclk_max = mem_table->min;
1112 socclk_min = socclk_max = soc_table->min;
1113 vclk_min = vclk_max = vclk_table->min;
1114 dclk_min = dclk_max = dclk_table->min;
1115 fclk_min = fclk_max = fclk_table->min;
1117 case AMD_DPM_FORCED_LEVEL_AUTO:
1118 sclk_min = gfx_table->min;
1119 sclk_max = gfx_table->max;
1120 mclk_min = mem_table->min;
1121 mclk_max = mem_table->max;
1122 socclk_min = soc_table->min;
1123 socclk_max = soc_table->max;
1124 vclk_min = vclk_table->min;
1125 vclk_max = vclk_table->max;
1126 dclk_min = dclk_table->min;
1127 dclk_max = dclk_table->max;
1128 fclk_min = fclk_table->min;
1129 fclk_max = fclk_table->max;
1131 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
1132 sclk_min = sclk_max = pstate_table->gfxclk_pstate.standard;
1133 mclk_min = mclk_max = pstate_table->uclk_pstate.standard;
1134 socclk_min = socclk_max = pstate_table->socclk_pstate.standard;
1135 vclk_min = vclk_max = pstate_table->vclk_pstate.standard;
1136 dclk_min = dclk_max = pstate_table->dclk_pstate.standard;
1137 fclk_min = fclk_max = pstate_table->fclk_pstate.standard;
1139 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
1140 sclk_min = sclk_max = pstate_table->gfxclk_pstate.min;
1142 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
1143 mclk_min = mclk_max = pstate_table->uclk_pstate.min;
1145 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
1146 sclk_min = sclk_max = pstate_table->gfxclk_pstate.peak;
1147 mclk_min = mclk_max = pstate_table->uclk_pstate.peak;
1148 socclk_min = socclk_max = pstate_table->socclk_pstate.peak;
1149 vclk_min = vclk_max = pstate_table->vclk_pstate.peak;
1150 dclk_min = dclk_max = pstate_table->dclk_pstate.peak;
1151 fclk_min = fclk_max = pstate_table->fclk_pstate.peak;
1153 case AMD_DPM_FORCED_LEVEL_MANUAL:
1154 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
1157 dev_err(adev->dev, "Invalid performance level %d\n", level);
1161 if (sclk_min && sclk_max) {
1162 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1169 pstate_table->gfxclk_pstate.curr.min = sclk_min;
1170 pstate_table->gfxclk_pstate.curr.max = sclk_max;
1173 if (mclk_min && mclk_max) {
1174 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1181 pstate_table->uclk_pstate.curr.min = mclk_min;
1182 pstate_table->uclk_pstate.curr.max = mclk_max;
1185 if (socclk_min && socclk_max) {
1186 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1193 pstate_table->socclk_pstate.curr.min = socclk_min;
1194 pstate_table->socclk_pstate.curr.max = socclk_max;
1197 if (vclk_min && vclk_max) {
1198 for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
1199 if (adev->vcn.harvest_config & (1 << i))
1201 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1202 i ? SMU_VCLK1 : SMU_VCLK,
1208 pstate_table->vclk_pstate.curr.min = vclk_min;
1209 pstate_table->vclk_pstate.curr.max = vclk_max;
1212 if (dclk_min && dclk_max) {
1213 for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
1214 if (adev->vcn.harvest_config & (1 << i))
1216 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1217 i ? SMU_DCLK1 : SMU_DCLK,
1223 pstate_table->dclk_pstate.curr.min = dclk_min;
1224 pstate_table->dclk_pstate.curr.max = dclk_max;
1227 if (fclk_min && fclk_max) {
1228 ret = smu_v14_0_set_soft_freq_limited_range(smu,
1235 pstate_table->fclk_pstate.curr.min = fclk_min;
1236 pstate_table->fclk_pstate.curr.max = fclk_max;
1242 int smu_v14_0_set_power_source(struct smu_context *smu,
1243 enum smu_power_src_type power_src)
1247 pwr_source = smu_cmn_to_asic_specific_index(smu,
1248 CMN2ASIC_MAPPING_PWR,
1249 (uint32_t)power_src);
1253 return smu_cmn_send_smc_msg_with_param(smu,
1254 SMU_MSG_NotifyPowerSource,
1259 static int smu_v14_0_get_dpm_freq_by_index(struct smu_context *smu,
1260 enum smu_clk_type clk_type,
1264 int ret = 0, clk_id = 0;
1270 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1273 clk_id = smu_cmn_to_asic_specific_index(smu,
1274 CMN2ASIC_MAPPING_CLK,
1279 param = (uint32_t)(((clk_id & 0xffff) << 16) | (level & 0xffff));
1281 ret = smu_cmn_send_smc_msg_with_param(smu,
1282 SMU_MSG_GetDpmFreqByIndex,
1288 *value = *value & 0x7fffffff;
1293 static int smu_v14_0_get_dpm_level_count(struct smu_context *smu,
1294 enum smu_clk_type clk_type,
1299 ret = smu_v14_0_get_dpm_freq_by_index(smu, clk_type, 0xff, value);
1304 static int smu_v14_0_get_fine_grained_status(struct smu_context *smu,
1305 enum smu_clk_type clk_type,
1306 bool *is_fine_grained_dpm)
1308 int ret = 0, clk_id = 0;
1312 if (!is_fine_grained_dpm)
1315 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type))
1318 clk_id = smu_cmn_to_asic_specific_index(smu,
1319 CMN2ASIC_MAPPING_CLK,
1324 param = (uint32_t)(((clk_id & 0xffff) << 16) | 0xff);
1326 ret = smu_cmn_send_smc_msg_with_param(smu,
1327 SMU_MSG_GetDpmFreqByIndex,
1334 * BIT31: 1 - Fine grained DPM, 0 - Dicrete DPM
1335 * now, we un-support it
1337 *is_fine_grained_dpm = value & 0x80000000;
1342 int smu_v14_0_set_single_dpm_table(struct smu_context *smu,
1343 enum smu_clk_type clk_type,
1344 struct smu_14_0_dpm_table *single_dpm_table)
1350 ret = smu_v14_0_get_dpm_level_count(smu,
1352 &single_dpm_table->count);
1354 dev_err(smu->adev->dev, "[%s] failed to get dpm levels!\n", __func__);
1358 ret = smu_v14_0_get_fine_grained_status(smu,
1360 &single_dpm_table->is_fine_grained);
1362 dev_err(smu->adev->dev, "[%s] failed to get fine grained status!\n", __func__);
1366 for (i = 0; i < single_dpm_table->count; i++) {
1367 ret = smu_v14_0_get_dpm_freq_by_index(smu,
1372 dev_err(smu->adev->dev, "[%s] failed to get dpm freq by index!\n", __func__);
1376 single_dpm_table->dpm_levels[i].value = clk;
1377 single_dpm_table->dpm_levels[i].enabled = true;
1380 single_dpm_table->min = clk;
1381 else if (i == single_dpm_table->count - 1)
1382 single_dpm_table->max = clk;
1388 int smu_v14_0_set_vcn_enable(struct smu_context *smu,
1391 struct amdgpu_device *adev = smu->adev;
1394 for (i = 0; i < adev->vcn.num_vcn_inst; i++) {
1395 if (adev->vcn.harvest_config & (1 << i))
1398 ret = smu_cmn_send_smc_msg_with_param(smu, enable ?
1399 SMU_MSG_PowerUpVcn : SMU_MSG_PowerDownVcn,
1408 int smu_v14_0_set_jpeg_enable(struct smu_context *smu,
1411 return smu_cmn_send_smc_msg_with_param(smu, enable ?
1412 SMU_MSG_PowerUpJpeg : SMU_MSG_PowerDownJpeg,
1416 int smu_v14_0_run_btc(struct smu_context *smu)
1420 res = smu_cmn_send_smc_msg(smu, SMU_MSG_RunDcBtc, NULL);
1422 dev_err(smu->adev->dev, "RunDcBtc failed!\n");
1427 int smu_v14_0_gpo_control(struct smu_context *smu,
1432 res = smu_cmn_send_smc_msg_with_param(smu,
1437 dev_err(smu->adev->dev, "SetGpoAllow %d failed!\n", enablement);
1442 int smu_v14_0_deep_sleep_control(struct smu_context *smu,
1445 struct amdgpu_device *adev = smu->adev;
1448 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_GFXCLK_BIT)) {
1449 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_GFXCLK_BIT, enablement);
1451 dev_err(adev->dev, "Failed to %s GFXCLK DS!\n", enablement ? "enable" : "disable");
1456 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_UCLK_BIT)) {
1457 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_UCLK_BIT, enablement);
1459 dev_err(adev->dev, "Failed to %s UCLK DS!\n", enablement ? "enable" : "disable");
1464 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_FCLK_BIT)) {
1465 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_FCLK_BIT, enablement);
1467 dev_err(adev->dev, "Failed to %s FCLK DS!\n", enablement ? "enable" : "disable");
1472 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_SOCCLK_BIT)) {
1473 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_SOCCLK_BIT, enablement);
1475 dev_err(adev->dev, "Failed to %s SOCCLK DS!\n", enablement ? "enable" : "disable");
1480 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_LCLK_BIT)) {
1481 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_LCLK_BIT, enablement);
1483 dev_err(adev->dev, "Failed to %s LCLK DS!\n", enablement ? "enable" : "disable");
1488 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_VCN_BIT)) {
1489 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_VCN_BIT, enablement);
1491 dev_err(adev->dev, "Failed to %s VCN DS!\n", enablement ? "enable" : "disable");
1496 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_MP0CLK_BIT)) {
1497 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_MP0CLK_BIT, enablement);
1499 dev_err(adev->dev, "Failed to %s MP0/MPIOCLK DS!\n", enablement ? "enable" : "disable");
1504 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_DS_MP1CLK_BIT)) {
1505 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_DS_MP1CLK_BIT, enablement);
1507 dev_err(adev->dev, "Failed to %s MP1CLK DS!\n", enablement ? "enable" : "disable");
1515 int smu_v14_0_gfx_ulv_control(struct smu_context *smu,
1520 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_GFX_ULV_BIT))
1521 ret = smu_cmn_feature_set_enabled(smu, SMU_FEATURE_GFX_ULV_BIT, enablement);
1526 int smu_v14_0_baco_set_armd3_sequence(struct smu_context *smu,
1527 enum smu_baco_seq baco_seq)
1529 struct smu_baco_context *smu_baco = &smu->smu_baco;
1532 ret = smu_cmn_send_smc_msg_with_param(smu,
1539 if (baco_seq == BACO_SEQ_BAMACO ||
1540 baco_seq == BACO_SEQ_BACO)
1541 smu_baco->state = SMU_BACO_STATE_ENTER;
1543 smu_baco->state = SMU_BACO_STATE_EXIT;
1548 bool smu_v14_0_baco_is_support(struct smu_context *smu)
1550 struct smu_baco_context *smu_baco = &smu->smu_baco;
1552 if (amdgpu_sriov_vf(smu->adev) ||
1553 !smu_baco->platform_support)
1556 /* return true if ASIC is in BACO state already */
1557 if (smu_v14_0_baco_get_state(smu) == SMU_BACO_STATE_ENTER)
1560 if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_BACO_BIT) &&
1561 !smu_cmn_feature_is_enabled(smu, SMU_FEATURE_BACO_BIT))
1567 enum smu_baco_state smu_v14_0_baco_get_state(struct smu_context *smu)
1569 struct smu_baco_context *smu_baco = &smu->smu_baco;
1571 return smu_baco->state;
1574 int smu_v14_0_baco_set_state(struct smu_context *smu,
1575 enum smu_baco_state state)
1577 struct smu_baco_context *smu_baco = &smu->smu_baco;
1578 struct amdgpu_device *adev = smu->adev;
1581 if (smu_v14_0_baco_get_state(smu) == state)
1584 if (state == SMU_BACO_STATE_ENTER) {
1585 ret = smu_cmn_send_smc_msg_with_param(smu,
1587 smu_baco->maco_support ?
1588 BACO_SEQ_BAMACO : BACO_SEQ_BACO,
1591 ret = smu_cmn_send_smc_msg(smu,
1597 /* clear vbios scratch 6 and 7 for coming asic reinit */
1598 WREG32(adev->bios_scratch_reg_offset + 6, 0);
1599 WREG32(adev->bios_scratch_reg_offset + 7, 0);
1603 smu_baco->state = state;
1608 int smu_v14_0_baco_enter(struct smu_context *smu)
1612 ret = smu_v14_0_baco_set_state(smu,
1613 SMU_BACO_STATE_ENTER);
1622 int smu_v14_0_baco_exit(struct smu_context *smu)
1624 return smu_v14_0_baco_set_state(smu,
1625 SMU_BACO_STATE_EXIT);
1628 int smu_v14_0_set_gfx_power_up_by_imu(struct smu_context *smu)
1632 index = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_MSG,
1633 SMU_MSG_EnableGfxImu);
1634 /* Param 1 to tell PMFW to enable GFXOFF feature */
1635 return smu_cmn_send_msg_without_waiting(smu, index, 1);
1638 int smu_v14_0_set_default_dpm_tables(struct smu_context *smu)
1640 struct smu_table_context *smu_table = &smu->smu_table;
1642 return smu_cmn_update_table(smu, SMU_TABLE_DPMCLOCKS, 0,
1643 smu_table->clocks_table, false);
1646 int smu_v14_0_od_edit_dpm_table(struct smu_context *smu,
1647 enum PP_OD_DPM_TABLE_COMMAND type,
1648 long input[], uint32_t size)
1650 struct smu_dpm_context *smu_dpm = &(smu->smu_dpm);
1653 /* Only allowed in manual mode */
1654 if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
1658 case PP_OD_EDIT_SCLK_VDDC_TABLE:
1660 dev_err(smu->adev->dev, "Input parameter number not correct\n");
1664 if (input[0] == 0) {
1665 if (input[1] < smu->gfx_default_hard_min_freq) {
1666 dev_warn(smu->adev->dev,
1667 "Fine grain setting minimum sclk (%ld) MHz is less than the minimum allowed (%d) MHz\n",
1668 input[1], smu->gfx_default_hard_min_freq);
1671 smu->gfx_actual_hard_min_freq = input[1];
1672 } else if (input[0] == 1) {
1673 if (input[1] > smu->gfx_default_soft_max_freq) {
1674 dev_warn(smu->adev->dev,
1675 "Fine grain setting maximum sclk (%ld) MHz is greater than the maximum allowed (%d) MHz\n",
1676 input[1], smu->gfx_default_soft_max_freq);
1679 smu->gfx_actual_soft_max_freq = input[1];
1684 case PP_OD_RESTORE_DEFAULT_TABLE:
1686 dev_err(smu->adev->dev, "Input parameter number not correct\n");
1689 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
1690 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
1692 case PP_OD_COMMIT_DPM_TABLE:
1694 dev_err(smu->adev->dev, "Input parameter number not correct\n");
1697 if (smu->gfx_actual_hard_min_freq > smu->gfx_actual_soft_max_freq) {
1698 dev_err(smu->adev->dev,
1699 "The setting minimum sclk (%d) MHz is greater than the setting maximum sclk (%d) MHz\n",
1700 smu->gfx_actual_hard_min_freq,
1701 smu->gfx_actual_soft_max_freq);
1705 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinGfxClk,
1706 smu->gfx_actual_hard_min_freq,
1709 dev_err(smu->adev->dev, "Set hard min sclk failed!");
1713 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxGfxClk,
1714 smu->gfx_actual_soft_max_freq,
1717 dev_err(smu->adev->dev, "Set soft max sclk failed!");