|
5 | 5 |
|
6 | 6 | #include "aie2_pci.h" |
7 | 7 |
|
| 8 | +#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE |
| 9 | +#include <linux/amd-pmf-io.h> |
| 10 | +#endif |
| 11 | + |
8 | 12 | #define SMU_RESULT_OK 1 |
9 | 13 |
|
10 | 14 | /* SMU commands */ |
@@ -51,6 +55,22 @@ static int aie2_smu_exec(struct amdxdna_dev_hdl *ndev, u32 reg_cmd, |
51 | 55 | return 0; |
52 | 56 | } |
53 | 57 |
|
| 58 | +#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE |
| 59 | +static int aie2_smu_get_npu_metrics(struct amdxdna_dev_hdl *ndev) |
| 60 | +{ |
| 61 | + struct amd_pmf_npu_metrics data; |
| 62 | + int ret; |
| 63 | + |
| 64 | + /* Get NPU metrics from the PMF interface */ |
| 65 | + ret = amd_pmf_get_npu_data(&data); |
| 66 | + if (ret) |
| 67 | + return ret; |
| 68 | + |
| 69 | + memcpy(&ndev->npu_metrics_info, &data, sizeof(data)); |
| 70 | + return 0; |
| 71 | +} |
| 72 | +#endif |
| 73 | + |
54 | 74 | int npu1_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level) |
55 | 75 | { |
56 | 76 | u32 freq; |
@@ -109,11 +129,28 @@ int npu4_set_dpm(struct amdxdna_dev_hdl *ndev, u32 dpm_level) |
109 | 129 |
|
110 | 130 | int aie2_smu_get_mpnpu_clock_freq(struct amdxdna_dev_hdl *ndev) |
111 | 131 | { |
| 132 | + |
| 133 | +#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE |
| 134 | + int ret = aie2_smu_get_npu_metrics(ndev); |
| 135 | + if (ret) |
| 136 | + return -EINVAL; |
| 137 | + |
| 138 | + return ndev->npu_metrics_info.mpnpuclk_freq; |
| 139 | +#endif |
112 | 140 | return ndev->npuclk_freq; |
113 | 141 | } |
114 | 142 |
|
115 | 143 | int aie2_smu_get_hclock_freq(struct amdxdna_dev_hdl *ndev) |
116 | 144 | { |
| 145 | + |
| 146 | +#if KERNEL_VERSION(6, 18, 0) > LINUX_VERSION_CODE |
| 147 | + int ret = aie2_smu_get_npu_metrics(ndev); |
| 148 | + if (ret) |
| 149 | + return -EINVAL; |
| 150 | + |
| 151 | + return ndev->npu_metrics_info.npuclk_freq; |
| 152 | +#endif |
| 153 | + |
117 | 154 | return ndev->hclk_freq; |
118 | 155 | } |
119 | 156 |
|
|
0 commit comments