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.
25 #include "vega10_inc.h"
26 #include "soc15_common.h"
27 #include "vega10_smumgr.h"
28 #include "vega10_hwmgr.h"
29 #include "vega10_ppsmc.h"
30 #include "smu9_driver_if.h"
31 #include "smu9_smumgr.h"
32 #include "ppatomctrl.h"
36 static int vega10_copy_table_from_smc(struct pp_hwmgr
*hwmgr
,
37 uint8_t *table
, int16_t table_id
)
39 struct vega10_smumgr
*priv
= hwmgr
->smu_backend
;
41 PP_ASSERT_WITH_CODE(table_id
< MAX_SMU_TABLE
,
42 "Invalid SMU Table ID!", return -EINVAL
);
43 PP_ASSERT_WITH_CODE(priv
->smu_tables
.entry
[table_id
].version
!= 0,
44 "Invalid SMU Table version!", return -EINVAL
);
45 PP_ASSERT_WITH_CODE(priv
->smu_tables
.entry
[table_id
].size
!= 0,
46 "Invalid SMU Table Length!", return -EINVAL
);
47 smu9_send_msg_to_smc_with_parameter(hwmgr
,
48 PPSMC_MSG_SetDriverDramAddrHigh
,
49 upper_32_bits(priv
->smu_tables
.entry
[table_id
].mc_addr
));
50 smu9_send_msg_to_smc_with_parameter(hwmgr
,
51 PPSMC_MSG_SetDriverDramAddrLow
,
52 lower_32_bits(priv
->smu_tables
.entry
[table_id
].mc_addr
));
53 smu9_send_msg_to_smc_with_parameter(hwmgr
,
54 PPSMC_MSG_TransferTableSmu2Dram
,
55 priv
->smu_tables
.entry
[table_id
].table_id
);
57 memcpy(table
, priv
->smu_tables
.entry
[table_id
].table
,
58 priv
->smu_tables
.entry
[table_id
].size
);
63 static int vega10_copy_table_to_smc(struct pp_hwmgr
*hwmgr
,
64 uint8_t *table
, int16_t table_id
)
66 struct vega10_smumgr
*priv
= hwmgr
->smu_backend
;
68 PP_ASSERT_WITH_CODE(table_id
< MAX_SMU_TABLE
,
69 "Invalid SMU Table ID!", return -EINVAL
);
70 PP_ASSERT_WITH_CODE(priv
->smu_tables
.entry
[table_id
].version
!= 0,
71 "Invalid SMU Table version!", return -EINVAL
);
72 PP_ASSERT_WITH_CODE(priv
->smu_tables
.entry
[table_id
].size
!= 0,
73 "Invalid SMU Table Length!", return -EINVAL
);
75 memcpy(priv
->smu_tables
.entry
[table_id
].table
, table
,
76 priv
->smu_tables
.entry
[table_id
].size
);
78 smu9_send_msg_to_smc_with_parameter(hwmgr
,
79 PPSMC_MSG_SetDriverDramAddrHigh
,
80 upper_32_bits(priv
->smu_tables
.entry
[table_id
].mc_addr
));
81 smu9_send_msg_to_smc_with_parameter(hwmgr
,
82 PPSMC_MSG_SetDriverDramAddrLow
,
83 lower_32_bits(priv
->smu_tables
.entry
[table_id
].mc_addr
));
84 smu9_send_msg_to_smc_with_parameter(hwmgr
,
85 PPSMC_MSG_TransferTableDram2Smu
,
86 priv
->smu_tables
.entry
[table_id
].table_id
);
91 static int vega10_get_smc_features(struct pp_hwmgr
*hwmgr
,
92 uint32_t *features_enabled
)
94 if (features_enabled
== NULL
)
97 smu9_send_msg_to_smc(hwmgr
, PPSMC_MSG_GetEnabledSmuFeatures
);
98 *features_enabled
= smu9_get_argument(hwmgr
);
103 static bool vega10_is_dpm_running(struct pp_hwmgr
*hwmgr
)
105 uint32_t features_enabled
= 0;
107 vega10_get_smc_features(hwmgr
, &features_enabled
);
109 if (features_enabled
& SMC_DPM_FEATURES
)
115 static int vega10_set_tools_address(struct pp_hwmgr
*hwmgr
)
117 struct vega10_smumgr
*priv
= hwmgr
->smu_backend
;
119 if (priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
) {
120 smu9_send_msg_to_smc_with_parameter(hwmgr
,
121 PPSMC_MSG_SetToolsDramAddrHigh
,
122 upper_32_bits(priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
));
123 smu9_send_msg_to_smc_with_parameter(hwmgr
,
124 PPSMC_MSG_SetToolsDramAddrLow
,
125 lower_32_bits(priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
));
130 static int vega10_verify_smc_interface(struct pp_hwmgr
*hwmgr
)
132 uint32_t smc_driver_if_version
;
133 struct amdgpu_device
*adev
= hwmgr
->adev
;
137 PP_ASSERT_WITH_CODE(!smu9_send_msg_to_smc(hwmgr
,
138 PPSMC_MSG_GetDriverIfVersion
),
139 "Attempt to get SMC IF Version Number Failed!",
141 smc_driver_if_version
= smu9_get_argument(hwmgr
);
143 dev_id
= adev
->pdev
->device
;
144 rev_id
= adev
->pdev
->revision
;
146 if (!((dev_id
== 0x687f) &&
149 (rev_id
== 0xc3)))) {
150 if (smc_driver_if_version
!= SMU9_DRIVER_IF_VERSION
) {
151 pr_err("Your firmware(0x%x) doesn't match SMU9_DRIVER_IF_VERSION(0x%x). Please update your firmware!\n",
152 smc_driver_if_version
, SMU9_DRIVER_IF_VERSION
);
160 static int vega10_smu_init(struct pp_hwmgr
*hwmgr
)
162 struct vega10_smumgr
*priv
;
163 unsigned long tools_size
;
165 struct cgs_firmware_info info
= {0};
167 ret
= cgs_get_firmware_info(hwmgr
->device
,
170 if (ret
|| !info
.kptr
)
173 priv
= kzalloc(sizeof(struct vega10_smumgr
), GFP_KERNEL
);
178 hwmgr
->smu_backend
= priv
;
180 /* allocate space for pptable */
181 ret
= amdgpu_bo_create_kernel((struct amdgpu_device
*)hwmgr
->adev
,
184 AMDGPU_GEM_DOMAIN_VRAM
,
185 &priv
->smu_tables
.entry
[PPTABLE
].handle
,
186 &priv
->smu_tables
.entry
[PPTABLE
].mc_addr
,
187 &priv
->smu_tables
.entry
[PPTABLE
].table
);
191 priv
->smu_tables
.entry
[PPTABLE
].version
= 0x01;
192 priv
->smu_tables
.entry
[PPTABLE
].size
= sizeof(PPTable_t
);
193 priv
->smu_tables
.entry
[PPTABLE
].table_id
= TABLE_PPTABLE
;
195 /* allocate space for watermarks table */
196 ret
= amdgpu_bo_create_kernel((struct amdgpu_device
*)hwmgr
->adev
,
197 sizeof(Watermarks_t
),
199 AMDGPU_GEM_DOMAIN_VRAM
,
200 &priv
->smu_tables
.entry
[WMTABLE
].handle
,
201 &priv
->smu_tables
.entry
[WMTABLE
].mc_addr
,
202 &priv
->smu_tables
.entry
[WMTABLE
].table
);
207 priv
->smu_tables
.entry
[WMTABLE
].version
= 0x01;
208 priv
->smu_tables
.entry
[WMTABLE
].size
= sizeof(Watermarks_t
);
209 priv
->smu_tables
.entry
[WMTABLE
].table_id
= TABLE_WATERMARKS
;
211 /* allocate space for AVFS table */
212 ret
= amdgpu_bo_create_kernel((struct amdgpu_device
*)hwmgr
->adev
,
215 AMDGPU_GEM_DOMAIN_VRAM
,
216 &priv
->smu_tables
.entry
[AVFSTABLE
].handle
,
217 &priv
->smu_tables
.entry
[AVFSTABLE
].mc_addr
,
218 &priv
->smu_tables
.entry
[AVFSTABLE
].table
);
223 priv
->smu_tables
.entry
[AVFSTABLE
].version
= 0x01;
224 priv
->smu_tables
.entry
[AVFSTABLE
].size
= sizeof(AvfsTable_t
);
225 priv
->smu_tables
.entry
[AVFSTABLE
].table_id
= TABLE_AVFS
;
227 tools_size
= 0x19000;
229 ret
= amdgpu_bo_create_kernel((struct amdgpu_device
*)hwmgr
->adev
,
232 AMDGPU_GEM_DOMAIN_VRAM
,
233 &priv
->smu_tables
.entry
[TOOLSTABLE
].handle
,
234 &priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
,
235 &priv
->smu_tables
.entry
[TOOLSTABLE
].table
);
238 priv
->smu_tables
.entry
[TOOLSTABLE
].version
= 0x01;
239 priv
->smu_tables
.entry
[TOOLSTABLE
].size
= tools_size
;
240 priv
->smu_tables
.entry
[TOOLSTABLE
].table_id
= TABLE_PMSTATUSLOG
;
243 /* allocate space for AVFS Fuse table */
244 ret
= amdgpu_bo_create_kernel((struct amdgpu_device
*)hwmgr
->adev
,
245 sizeof(AvfsFuseOverride_t
),
247 AMDGPU_GEM_DOMAIN_VRAM
,
248 &priv
->smu_tables
.entry
[AVFSFUSETABLE
].handle
,
249 &priv
->smu_tables
.entry
[AVFSFUSETABLE
].mc_addr
,
250 &priv
->smu_tables
.entry
[AVFSFUSETABLE
].table
);
254 priv
->smu_tables
.entry
[AVFSFUSETABLE
].version
= 0x01;
255 priv
->smu_tables
.entry
[AVFSFUSETABLE
].size
= sizeof(AvfsFuseOverride_t
);
256 priv
->smu_tables
.entry
[AVFSFUSETABLE
].table_id
= TABLE_AVFS_FUSE_OVERRIDE
;
262 if (priv
->smu_tables
.entry
[TOOLSTABLE
].table
)
263 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[TOOLSTABLE
].handle
,
264 &priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
,
265 &priv
->smu_tables
.entry
[TOOLSTABLE
].table
);
267 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[AVFSTABLE
].handle
,
268 &priv
->smu_tables
.entry
[AVFSTABLE
].mc_addr
,
269 &priv
->smu_tables
.entry
[AVFSTABLE
].table
);
271 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[WMTABLE
].handle
,
272 &priv
->smu_tables
.entry
[WMTABLE
].mc_addr
,
273 &priv
->smu_tables
.entry
[WMTABLE
].table
);
275 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[PPTABLE
].handle
,
276 &priv
->smu_tables
.entry
[PPTABLE
].mc_addr
,
277 &priv
->smu_tables
.entry
[PPTABLE
].table
);
279 kfree(hwmgr
->smu_backend
);
284 static int vega10_smu_fini(struct pp_hwmgr
*hwmgr
)
286 struct vega10_smumgr
*priv
= hwmgr
->smu_backend
;
289 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[PPTABLE
].handle
,
290 &priv
->smu_tables
.entry
[PPTABLE
].mc_addr
,
291 &priv
->smu_tables
.entry
[PPTABLE
].table
);
292 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[WMTABLE
].handle
,
293 &priv
->smu_tables
.entry
[WMTABLE
].mc_addr
,
294 &priv
->smu_tables
.entry
[WMTABLE
].table
);
295 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[AVFSTABLE
].handle
,
296 &priv
->smu_tables
.entry
[AVFSTABLE
].mc_addr
,
297 &priv
->smu_tables
.entry
[AVFSTABLE
].table
);
298 if (priv
->smu_tables
.entry
[TOOLSTABLE
].table
)
299 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[TOOLSTABLE
].handle
,
300 &priv
->smu_tables
.entry
[TOOLSTABLE
].mc_addr
,
301 &priv
->smu_tables
.entry
[TOOLSTABLE
].table
);
302 amdgpu_bo_free_kernel(&priv
->smu_tables
.entry
[AVFSFUSETABLE
].handle
,
303 &priv
->smu_tables
.entry
[AVFSFUSETABLE
].mc_addr
,
304 &priv
->smu_tables
.entry
[AVFSFUSETABLE
].table
);
305 kfree(hwmgr
->smu_backend
);
306 hwmgr
->smu_backend
= NULL
;
311 static int vega10_start_smu(struct pp_hwmgr
*hwmgr
)
313 if (!smu9_is_smc_ram_running(hwmgr
))
316 PP_ASSERT_WITH_CODE(!vega10_verify_smc_interface(hwmgr
),
317 "Failed to verify SMC interface!",
320 vega10_set_tools_address(hwmgr
);
325 static int vega10_smc_table_manager(struct pp_hwmgr
*hwmgr
, uint8_t *table
,
326 uint16_t table_id
, bool rw
)
331 ret
= vega10_copy_table_from_smc(hwmgr
, table
, table_id
);
333 ret
= vega10_copy_table_to_smc(hwmgr
, table
, table_id
);
338 const struct pp_smumgr_func vega10_smu_funcs
= {
339 .smu_init
= &vega10_smu_init
,
340 .smu_fini
= &vega10_smu_fini
,
341 .start_smu
= &vega10_start_smu
,
342 .request_smu_load_specific_fw
= NULL
,
343 .send_msg_to_smc
= &smu9_send_msg_to_smc
,
344 .send_msg_to_smc_with_parameter
= &smu9_send_msg_to_smc_with_parameter
,
345 .download_pptable_settings
= NULL
,
346 .upload_pptable_settings
= NULL
,
347 .is_dpm_running
= vega10_is_dpm_running
,
348 .get_argument
= smu9_get_argument
,
349 .smc_table_manager
= vega10_smc_table_manager
,