platform/x86/amd/pmf: Refactor NPU metrics for platform extensibility

Refactor the NPU metrics retrieval code to use a switch-case structure
based on CPU ID, preparing the driver for supporting additional
platforms with different metrics table formats.

This change restructures amd_pmf_get_smu_metrics() to handle
platform-specific metrics retrieval paths. The existing logic for
1AH_M20H and 1AH_M60H platforms is preserved within the switch-case
block.

No functional changes.

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Co-developed-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
Signed-off-by: Patil Rajesh Reddy <Patil.Reddy@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Link: https://patch.msgid.link/20260723111534.1940925-7-Shyam-sundar.S-k@amd.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Shyam Sundar S K 2026-07-23 16:45:33 +05:30 committed by Ilpo Järvinen
parent 9f29ec1f46
commit 17f3e140d0
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31

View File

@ -136,29 +136,34 @@ static int amd_pmf_get_smu_metrics(struct amd_pmf_dev *dev, struct amd_pmf_npu_m
if (ret)
return ret;
ret = amd_pmf_set_dram_addr(dev, true);
if (ret)
return ret;
switch (dev->cpu_id) {
case PCI_DEVICE_ID_AMD_1AH_M20H_ROOT:
case PCI_DEVICE_ID_AMD_1AH_M60H_ROOT:
ret = amd_pmf_set_dram_addr(dev, true);
if (ret)
return ret;
memset(dev->buf, 0, dev->mtable_size);
memset(dev->buf, 0, dev->mtable_size);
/* Send SMU command to get NPU metrics */
ret = amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, SET_CMD, METRICS_TABLE_ID, NULL);
if (ret) {
dev_err(dev->dev, "SMU command failed to get NPU metrics: %d\n", ret);
return ret;
/* Send SMU command to get NPU metrics */
ret = amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, SET_CMD, METRICS_TABLE_ID, NULL);
if (ret) {
dev_err(dev->dev, "SMU command failed to get NPU metrics: %d\n", ret);
return ret;
}
memcpy(&dev->m_table_v2, dev->buf, dev->mtable_size);
data->npuclk_freq = dev->m_table_v2.npuclk_freq;
for (i = 0; i < ARRAY_SIZE(data->npu_busy); i++)
data->npu_busy[i] = dev->m_table_v2.npu_busy[i];
data->npu_power = dev->m_table_v2.npu_power;
data->mpnpuclk_freq = dev->m_table_v2.mpnpuclk_freq;
data->npu_reads = dev->m_table_v2.npu_reads;
data->npu_writes = dev->m_table_v2.npu_writes;
break;
}
memcpy(&dev->m_table_v2, dev->buf, dev->mtable_size);
data->npuclk_freq = dev->m_table_v2.npuclk_freq;
for (i = 0; i < ARRAY_SIZE(data->npu_busy); i++)
data->npu_busy[i] = dev->m_table_v2.npu_busy[i];
data->npu_power = dev->m_table_v2.npu_power;
data->mpnpuclk_freq = dev->m_table_v2.mpnpuclk_freq;
data->npu_reads = dev->m_table_v2.npu_reads;
data->npu_writes = dev->m_table_v2.npu_writes;
return 0;
}