2 * Copyright 2016 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.
24 #include <linux/pci.h>
27 #include "vega10_inc.h"
28 #include "soc15_common.h"
29 #include "vega10_smumgr.h"
30 #include "vega10_hwmgr.h"
31 #include "vega10_ppsmc.h"
32 #include "smu9_driver_if.h"
33 #include "smu9_smumgr.h"
34 #include "ppatomctrl.h"
38 static int vega10_copy_table_from_smc(struct pp_hwmgr *hwmgr,
39 uint8_t *table, int16_t table_id)
41 struct vega10_smumgr *priv = hwmgr->smu_backend;
42 struct amdgpu_device *adev = hwmgr->adev;
44 PP_ASSERT_WITH_CODE(table_id < MAX_SMU_TABLE,
45 "Invalid SMU Table ID!", return -EINVAL);
46 PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].version != 0,
47 "Invalid SMU Table version!", return -EINVAL);
48 PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
49 "Invalid SMU Table Length!", return -EINVAL);
50 smum_send_msg_to_smc_with_parameter(hwmgr,
51 PPSMC_MSG_SetDriverDramAddrHigh,
52 upper_32_bits(priv->smu_tables.entry[table_id].mc_addr),
54 smum_send_msg_to_smc_with_parameter(hwmgr,
55 PPSMC_MSG_SetDriverDramAddrLow,
56 lower_32_bits(priv->smu_tables.entry[table_id].mc_addr),
58 smum_send_msg_to_smc_with_parameter(hwmgr,
59 PPSMC_MSG_TransferTableSmu2Dram,
60 priv->smu_tables.entry[table_id].table_id,
64 amdgpu_asic_flush_hdp(adev, NULL);
66 memcpy(table, priv->smu_tables.entry[table_id].table,
67 priv->smu_tables.entry[table_id].size);
72 static int vega10_copy_table_to_smc(struct pp_hwmgr *hwmgr,
73 uint8_t *table, int16_t table_id)
75 struct vega10_smumgr *priv = hwmgr->smu_backend;
76 struct amdgpu_device *adev = hwmgr->adev;
78 /* under sriov, vbios or hypervisor driver
79 * has already copy table to smc so here only skip it
84 PP_ASSERT_WITH_CODE(table_id < MAX_SMU_TABLE,
85 "Invalid SMU Table ID!", return -EINVAL);
86 PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].version != 0,
87 "Invalid SMU Table version!", return -EINVAL);
88 PP_ASSERT_WITH_CODE(priv->smu_tables.entry[table_id].size != 0,
89 "Invalid SMU Table Length!", return -EINVAL);
91 memcpy(priv->smu_tables.entry[table_id].table, table,
92 priv->smu_tables.entry[table_id].size);
94 amdgpu_asic_flush_hdp(adev, NULL);
96 smum_send_msg_to_smc_with_parameter(hwmgr,
97 PPSMC_MSG_SetDriverDramAddrHigh,
98 upper_32_bits(priv->smu_tables.entry[table_id].mc_addr),
100 smum_send_msg_to_smc_with_parameter(hwmgr,
101 PPSMC_MSG_SetDriverDramAddrLow,
102 lower_32_bits(priv->smu_tables.entry[table_id].mc_addr),
104 smum_send_msg_to_smc_with_parameter(hwmgr,
105 PPSMC_MSG_TransferTableDram2Smu,
106 priv->smu_tables.entry[table_id].table_id,
112 int vega10_enable_smc_features(struct pp_hwmgr *hwmgr,
113 bool enable, uint32_t feature_mask)
115 int msg = enable ? PPSMC_MSG_EnableSmuFeatures :
116 PPSMC_MSG_DisableSmuFeatures;
118 /* VF has no permission to change smu feature due
119 * to security concern even under pp one vf mode
120 * it still can't do it. For vega10, the smu in
121 * vbios will enable the appropriate features.
126 return smum_send_msg_to_smc_with_parameter(hwmgr,
127 msg, feature_mask, NULL);
130 int vega10_get_enabled_smc_features(struct pp_hwmgr *hwmgr,
131 uint64_t *features_enabled)
133 uint32_t enabled_features;
135 if (features_enabled == NULL)
138 smum_send_msg_to_smc(hwmgr,
139 PPSMC_MSG_GetEnabledSmuFeatures,
141 *features_enabled = enabled_features;
146 static bool vega10_is_dpm_running(struct pp_hwmgr *hwmgr)
148 uint64_t features_enabled = 0;
150 vega10_get_enabled_smc_features(hwmgr, &features_enabled);
152 if (features_enabled & SMC_DPM_FEATURES)
158 static int vega10_set_tools_address(struct pp_hwmgr *hwmgr)
160 struct vega10_smumgr *priv = hwmgr->smu_backend;
162 if (priv->smu_tables.entry[TOOLSTABLE].mc_addr) {
163 smum_send_msg_to_smc_with_parameter(hwmgr,
164 PPSMC_MSG_SetToolsDramAddrHigh,
165 upper_32_bits(priv->smu_tables.entry[TOOLSTABLE].mc_addr),
167 smum_send_msg_to_smc_with_parameter(hwmgr,
168 PPSMC_MSG_SetToolsDramAddrLow,
169 lower_32_bits(priv->smu_tables.entry[TOOLSTABLE].mc_addr),
175 static int vega10_verify_smc_interface(struct pp_hwmgr *hwmgr)
177 uint32_t smc_driver_if_version;
178 struct amdgpu_device *adev = hwmgr->adev;
182 PP_ASSERT_WITH_CODE(!smum_send_msg_to_smc(hwmgr,
183 PPSMC_MSG_GetDriverIfVersion,
184 &smc_driver_if_version),
185 "Attempt to get SMC IF Version Number Failed!",
188 dev_id = adev->pdev->device;
189 rev_id = adev->pdev->revision;
191 if (!((dev_id == 0x687f) &&
194 (rev_id == 0xc3)))) {
195 if (smc_driver_if_version != SMU9_DRIVER_IF_VERSION) {
196 pr_err("Your firmware(0x%x) doesn't match SMU9_DRIVER_IF_VERSION(0x%x). Please update your firmware!\n",
197 smc_driver_if_version, SMU9_DRIVER_IF_VERSION);
205 static int vega10_smu_init(struct pp_hwmgr *hwmgr)
207 struct vega10_smumgr *priv;
208 unsigned long tools_size;
210 struct cgs_firmware_info info = {0};
212 ret = cgs_get_firmware_info(hwmgr->device,
215 if (ret || !info.kptr)
218 priv = kzalloc(sizeof(struct vega10_smumgr), GFP_KERNEL);
223 hwmgr->smu_backend = priv;
225 /* allocate space for pptable */
226 ret = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev,
229 AMDGPU_GEM_DOMAIN_VRAM,
230 &priv->smu_tables.entry[PPTABLE].handle,
231 &priv->smu_tables.entry[PPTABLE].mc_addr,
232 &priv->smu_tables.entry[PPTABLE].table);
236 priv->smu_tables.entry[PPTABLE].version = 0x01;
237 priv->smu_tables.entry[PPTABLE].size = sizeof(PPTable_t);
238 priv->smu_tables.entry[PPTABLE].table_id = TABLE_PPTABLE;
240 /* allocate space for watermarks table */
241 ret = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev,
242 sizeof(Watermarks_t),
244 AMDGPU_GEM_DOMAIN_VRAM,
245 &priv->smu_tables.entry[WMTABLE].handle,
246 &priv->smu_tables.entry[WMTABLE].mc_addr,
247 &priv->smu_tables.entry[WMTABLE].table);
252 priv->smu_tables.entry[WMTABLE].version = 0x01;
253 priv->smu_tables.entry[WMTABLE].size = sizeof(Watermarks_t);
254 priv->smu_tables.entry[WMTABLE].table_id = TABLE_WATERMARKS;
256 /* allocate space for AVFS table */
257 ret = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev,
260 AMDGPU_GEM_DOMAIN_VRAM,
261 &priv->smu_tables.entry[AVFSTABLE].handle,
262 &priv->smu_tables.entry[AVFSTABLE].mc_addr,
263 &priv->smu_tables.entry[AVFSTABLE].table);
268 priv->smu_tables.entry[AVFSTABLE].version = 0x01;
269 priv->smu_tables.entry[AVFSTABLE].size = sizeof(AvfsTable_t);
270 priv->smu_tables.entry[AVFSTABLE].table_id = TABLE_AVFS;
272 tools_size = 0x19000;
274 ret = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev,
277 AMDGPU_GEM_DOMAIN_VRAM,
278 &priv->smu_tables.entry[TOOLSTABLE].handle,
279 &priv->smu_tables.entry[TOOLSTABLE].mc_addr,
280 &priv->smu_tables.entry[TOOLSTABLE].table);
283 priv->smu_tables.entry[TOOLSTABLE].version = 0x01;
284 priv->smu_tables.entry[TOOLSTABLE].size = tools_size;
285 priv->smu_tables.entry[TOOLSTABLE].table_id = TABLE_PMSTATUSLOG;
288 /* allocate space for AVFS Fuse table */
289 ret = amdgpu_bo_create_kernel((struct amdgpu_device *)hwmgr->adev,
290 sizeof(AvfsFuseOverride_t),
292 AMDGPU_GEM_DOMAIN_VRAM,
293 &priv->smu_tables.entry[AVFSFUSETABLE].handle,
294 &priv->smu_tables.entry[AVFSFUSETABLE].mc_addr,
295 &priv->smu_tables.entry[AVFSFUSETABLE].table);
299 priv->smu_tables.entry[AVFSFUSETABLE].version = 0x01;
300 priv->smu_tables.entry[AVFSFUSETABLE].size = sizeof(AvfsFuseOverride_t);
301 priv->smu_tables.entry[AVFSFUSETABLE].table_id = TABLE_AVFS_FUSE_OVERRIDE;
307 if (priv->smu_tables.entry[TOOLSTABLE].table)
308 amdgpu_bo_free_kernel(&priv->smu_tables.entry[TOOLSTABLE].handle,
309 &priv->smu_tables.entry[TOOLSTABLE].mc_addr,
310 &priv->smu_tables.entry[TOOLSTABLE].table);
312 amdgpu_bo_free_kernel(&priv->smu_tables.entry[AVFSTABLE].handle,
313 &priv->smu_tables.entry[AVFSTABLE].mc_addr,
314 &priv->smu_tables.entry[AVFSTABLE].table);
316 amdgpu_bo_free_kernel(&priv->smu_tables.entry[WMTABLE].handle,
317 &priv->smu_tables.entry[WMTABLE].mc_addr,
318 &priv->smu_tables.entry[WMTABLE].table);
320 amdgpu_bo_free_kernel(&priv->smu_tables.entry[PPTABLE].handle,
321 &priv->smu_tables.entry[PPTABLE].mc_addr,
322 &priv->smu_tables.entry[PPTABLE].table);
324 kfree(hwmgr->smu_backend);
329 static int vega10_smu_fini(struct pp_hwmgr *hwmgr)
331 struct vega10_smumgr *priv = hwmgr->smu_backend;
334 amdgpu_bo_free_kernel(&priv->smu_tables.entry[PPTABLE].handle,
335 &priv->smu_tables.entry[PPTABLE].mc_addr,
336 &priv->smu_tables.entry[PPTABLE].table);
337 amdgpu_bo_free_kernel(&priv->smu_tables.entry[WMTABLE].handle,
338 &priv->smu_tables.entry[WMTABLE].mc_addr,
339 &priv->smu_tables.entry[WMTABLE].table);
340 amdgpu_bo_free_kernel(&priv->smu_tables.entry[AVFSTABLE].handle,
341 &priv->smu_tables.entry[AVFSTABLE].mc_addr,
342 &priv->smu_tables.entry[AVFSTABLE].table);
343 if (priv->smu_tables.entry[TOOLSTABLE].table)
344 amdgpu_bo_free_kernel(&priv->smu_tables.entry[TOOLSTABLE].handle,
345 &priv->smu_tables.entry[TOOLSTABLE].mc_addr,
346 &priv->smu_tables.entry[TOOLSTABLE].table);
347 amdgpu_bo_free_kernel(&priv->smu_tables.entry[AVFSFUSETABLE].handle,
348 &priv->smu_tables.entry[AVFSFUSETABLE].mc_addr,
349 &priv->smu_tables.entry[AVFSFUSETABLE].table);
350 kfree(hwmgr->smu_backend);
351 hwmgr->smu_backend = NULL;
356 static int vega10_start_smu(struct pp_hwmgr *hwmgr)
358 if (!smu9_is_smc_ram_running(hwmgr))
361 PP_ASSERT_WITH_CODE(!vega10_verify_smc_interface(hwmgr),
362 "Failed to verify SMC interface!",
365 vega10_set_tools_address(hwmgr);
370 static int vega10_smc_table_manager(struct pp_hwmgr *hwmgr, uint8_t *table,
371 uint16_t table_id, bool rw)
376 ret = vega10_copy_table_from_smc(hwmgr, table, table_id);
378 ret = vega10_copy_table_to_smc(hwmgr, table, table_id);
383 const struct pp_smumgr_func vega10_smu_funcs = {
384 .name = "vega10_smu",
385 .smu_init = &vega10_smu_init,
386 .smu_fini = &vega10_smu_fini,
387 .start_smu = &vega10_start_smu,
388 .request_smu_load_specific_fw = NULL,
389 .send_msg_to_smc = &smu9_send_msg_to_smc,
390 .send_msg_to_smc_with_parameter = &smu9_send_msg_to_smc_with_parameter,
391 .download_pptable_settings = NULL,
392 .upload_pptable_settings = NULL,
393 .is_dpm_running = vega10_is_dpm_running,
394 .get_argument = smu9_get_argument,
395 .smc_table_manager = vega10_smc_table_manager,