2 * Copyright 2018 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>
27 #include "amdgpu_psp.h"
28 #include "amdgpu_ucode.h"
29 #include "soc15_common.h"
30 #include "psp_v11_0.h"
32 #include "mp/mp_11_0_offset.h"
33 #include "mp/mp_11_0_sh_mask.h"
34 #include "gc/gc_9_0_offset.h"
35 #include "sdma0/sdma0_4_0_offset.h"
36 #include "nbio/nbio_7_4_offset.h"
38 #include "oss/osssys_4_0_offset.h"
39 #include "oss/osssys_4_0_sh_mask.h"
41 MODULE_FIRMWARE("amdgpu/vega20_sos.bin");
42 MODULE_FIRMWARE("amdgpu/vega20_asd.bin");
43 MODULE_FIRMWARE("amdgpu/vega20_ta.bin");
44 MODULE_FIRMWARE("amdgpu/navi10_sos.bin");
45 MODULE_FIRMWARE("amdgpu/navi10_asd.bin");
46 MODULE_FIRMWARE("amdgpu/navi10_ta.bin");
47 MODULE_FIRMWARE("amdgpu/navi14_sos.bin");
48 MODULE_FIRMWARE("amdgpu/navi14_asd.bin");
49 MODULE_FIRMWARE("amdgpu/navi14_ta.bin");
50 MODULE_FIRMWARE("amdgpu/navi12_sos.bin");
51 MODULE_FIRMWARE("amdgpu/navi12_asd.bin");
52 MODULE_FIRMWARE("amdgpu/navi12_ta.bin");
53 MODULE_FIRMWARE("amdgpu/arcturus_sos.bin");
54 MODULE_FIRMWARE("amdgpu/arcturus_asd.bin");
55 MODULE_FIRMWARE("amdgpu/arcturus_ta.bin");
58 #define smnMP1_FIRMWARE_FLAGS 0x3010024
59 /* navi10 reg offset define */
60 #define mmRLC_GPM_UCODE_ADDR_NV10 0x5b61
61 #define mmRLC_GPM_UCODE_DATA_NV10 0x5b62
62 #define mmSDMA0_UCODE_ADDR_NV10 0x5880
63 #define mmSDMA0_UCODE_DATA_NV10 0x5881
64 /* memory training timeout define */
65 #define MEM_TRAIN_SEND_MSG_TIMEOUT_US 3000000
67 static int psp_v11_0_init_microcode(struct psp_context
*psp
)
69 struct amdgpu_device
*adev
= psp
->adev
;
70 const char *chip_name
;
73 const struct psp_firmware_header_v1_0
*sos_hdr
;
74 const struct psp_firmware_header_v1_1
*sos_hdr_v1_1
;
75 const struct psp_firmware_header_v1_2
*sos_hdr_v1_2
;
76 const struct psp_firmware_header_v1_0
*asd_hdr
;
77 const struct ta_firmware_header_v1_0
*ta_hdr
;
81 switch (adev
->asic_type
) {
95 chip_name
= "arcturus";
101 snprintf(fw_name
, sizeof(fw_name
), "amdgpu/%s_sos.bin", chip_name
);
102 err
= request_firmware(&adev
->psp
.sos_fw
, fw_name
, adev
->dev
);
106 err
= amdgpu_ucode_validate(adev
->psp
.sos_fw
);
110 sos_hdr
= (const struct psp_firmware_header_v1_0
*)adev
->psp
.sos_fw
->data
;
111 amdgpu_ucode_print_psp_hdr(&sos_hdr
->header
);
113 switch (sos_hdr
->header
.header_version_major
) {
115 adev
->psp
.sos_fw_version
= le32_to_cpu(sos_hdr
->header
.ucode_version
);
116 adev
->psp
.sos_feature_version
= le32_to_cpu(sos_hdr
->ucode_feature_version
);
117 adev
->psp
.sos_bin_size
= le32_to_cpu(sos_hdr
->sos_size_bytes
);
118 adev
->psp
.sys_bin_size
= le32_to_cpu(sos_hdr
->sos_offset_bytes
);
119 adev
->psp
.sys_start_addr
= (uint8_t *)sos_hdr
+
120 le32_to_cpu(sos_hdr
->header
.ucode_array_offset_bytes
);
121 adev
->psp
.sos_start_addr
= (uint8_t *)adev
->psp
.sys_start_addr
+
122 le32_to_cpu(sos_hdr
->sos_offset_bytes
);
123 if (sos_hdr
->header
.header_version_minor
== 1) {
124 sos_hdr_v1_1
= (const struct psp_firmware_header_v1_1
*)adev
->psp
.sos_fw
->data
;
125 adev
->psp
.toc_bin_size
= le32_to_cpu(sos_hdr_v1_1
->toc_size_bytes
);
126 adev
->psp
.toc_start_addr
= (uint8_t *)adev
->psp
.sys_start_addr
+
127 le32_to_cpu(sos_hdr_v1_1
->toc_offset_bytes
);
128 adev
->psp
.kdb_bin_size
= le32_to_cpu(sos_hdr_v1_1
->kdb_size_bytes
);
129 adev
->psp
.kdb_start_addr
= (uint8_t *)adev
->psp
.sys_start_addr
+
130 le32_to_cpu(sos_hdr_v1_1
->kdb_offset_bytes
);
132 if (sos_hdr
->header
.header_version_minor
== 2) {
133 sos_hdr_v1_2
= (const struct psp_firmware_header_v1_2
*)adev
->psp
.sos_fw
->data
;
134 adev
->psp
.kdb_bin_size
= le32_to_cpu(sos_hdr_v1_2
->kdb_size_bytes
);
135 adev
->psp
.kdb_start_addr
= (uint8_t *)adev
->psp
.sys_start_addr
+
136 le32_to_cpu(sos_hdr_v1_2
->kdb_offset_bytes
);
141 "Unsupported psp sos firmware\n");
146 snprintf(fw_name
, sizeof(fw_name
), "amdgpu/%s_asd.bin", chip_name
);
147 err
= request_firmware(&adev
->psp
.asd_fw
, fw_name
, adev
->dev
);
151 err
= amdgpu_ucode_validate(adev
->psp
.asd_fw
);
155 asd_hdr
= (const struct psp_firmware_header_v1_0
*)adev
->psp
.asd_fw
->data
;
156 adev
->psp
.asd_fw_version
= le32_to_cpu(asd_hdr
->header
.ucode_version
);
157 adev
->psp
.asd_feature_version
= le32_to_cpu(asd_hdr
->ucode_feature_version
);
158 adev
->psp
.asd_ucode_size
= le32_to_cpu(asd_hdr
->header
.ucode_size_bytes
);
159 adev
->psp
.asd_start_addr
= (uint8_t *)asd_hdr
+
160 le32_to_cpu(asd_hdr
->header
.ucode_array_offset_bytes
);
162 switch (adev
->asic_type
) {
165 snprintf(fw_name
, sizeof(fw_name
), "amdgpu/%s_ta.bin", chip_name
);
166 err
= request_firmware(&adev
->psp
.ta_fw
, fw_name
, adev
->dev
);
168 release_firmware(adev
->psp
.ta_fw
);
169 adev
->psp
.ta_fw
= NULL
;
171 "psp v11.0: Failed to load firmware \"%s\"\n", fw_name
);
173 err
= amdgpu_ucode_validate(adev
->psp
.ta_fw
);
177 ta_hdr
= (const struct ta_firmware_header_v1_0
*)adev
->psp
.ta_fw
->data
;
178 adev
->psp
.ta_xgmi_ucode_version
= le32_to_cpu(ta_hdr
->ta_xgmi_ucode_version
);
179 adev
->psp
.ta_xgmi_ucode_size
= le32_to_cpu(ta_hdr
->ta_xgmi_size_bytes
);
180 adev
->psp
.ta_xgmi_start_addr
= (uint8_t *)ta_hdr
+
181 le32_to_cpu(ta_hdr
->header
.ucode_array_offset_bytes
);
182 adev
->psp
.ta_fw_version
= le32_to_cpu(ta_hdr
->header
.ucode_version
);
183 adev
->psp
.ta_ras_ucode_version
= le32_to_cpu(ta_hdr
->ta_ras_ucode_version
);
184 adev
->psp
.ta_ras_ucode_size
= le32_to_cpu(ta_hdr
->ta_ras_size_bytes
);
185 adev
->psp
.ta_ras_start_addr
= (uint8_t *)adev
->psp
.ta_xgmi_start_addr
+
186 le32_to_cpu(ta_hdr
->ta_ras_offset_bytes
);
192 snprintf(fw_name
, sizeof(fw_name
), "amdgpu/%s_ta.bin", chip_name
);
193 err
= request_firmware(&adev
->psp
.ta_fw
, fw_name
, adev
->dev
);
195 release_firmware(adev
->psp
.ta_fw
);
196 adev
->psp
.ta_fw
= NULL
;
198 "psp v11.0: Failed to load firmware \"%s\"\n", fw_name
);
200 err
= amdgpu_ucode_validate(adev
->psp
.ta_fw
);
204 ta_hdr
= (const struct ta_firmware_header_v1_0
*)adev
->psp
.ta_fw
->data
;
205 adev
->psp
.ta_hdcp_ucode_version
= le32_to_cpu(ta_hdr
->ta_hdcp_ucode_version
);
206 adev
->psp
.ta_hdcp_ucode_size
= le32_to_cpu(ta_hdr
->ta_hdcp_size_bytes
);
207 adev
->psp
.ta_hdcp_start_addr
= (uint8_t *)ta_hdr
+
208 le32_to_cpu(ta_hdr
->header
.ucode_array_offset_bytes
);
210 adev
->psp
.ta_fw_version
= le32_to_cpu(ta_hdr
->header
.ucode_version
);
212 adev
->psp
.ta_dtm_ucode_version
= le32_to_cpu(ta_hdr
->ta_dtm_ucode_version
);
213 adev
->psp
.ta_dtm_ucode_size
= le32_to_cpu(ta_hdr
->ta_dtm_size_bytes
);
214 adev
->psp
.ta_dtm_start_addr
= (uint8_t *)adev
->psp
.ta_hdcp_start_addr
+
215 le32_to_cpu(ta_hdr
->ta_dtm_offset_bytes
);
225 release_firmware(adev
->psp
.ta_fw
);
226 adev
->psp
.ta_fw
= NULL
;
228 release_firmware(adev
->psp
.asd_fw
);
229 adev
->psp
.asd_fw
= NULL
;
232 "psp v11.0: Failed to load firmware \"%s\"\n", fw_name
);
233 release_firmware(adev
->psp
.sos_fw
);
234 adev
->psp
.sos_fw
= NULL
;
239 int psp_v11_0_wait_for_bootloader(struct psp_context
*psp
)
241 struct amdgpu_device
*adev
= psp
->adev
;
246 for (retry_loop
= 0; retry_loop
< 10; retry_loop
++) {
247 /* Wait for bootloader to signify that is
248 ready having bit 31 of C2PMSG_35 set to 1 */
249 ret
= psp_wait_for(psp
,
250 SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_35
),
262 static bool psp_v11_0_is_sos_alive(struct psp_context
*psp
)
264 struct amdgpu_device
*adev
= psp
->adev
;
267 sol_reg
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_81
);
269 return sol_reg
!= 0x0;
272 static int psp_v11_0_bootloader_load_kdb(struct psp_context
*psp
)
275 uint32_t psp_gfxdrv_command_reg
= 0;
276 struct amdgpu_device
*adev
= psp
->adev
;
278 /* Check tOS sign of life register to confirm sys driver and sOS
279 * are already been loaded.
281 if (psp_v11_0_is_sos_alive(psp
)) {
282 psp
->sos_fw_version
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_58
);
283 dev_info(adev
->dev
, "sos fw version = 0x%x.\n", psp
->sos_fw_version
);
287 ret
= psp_v11_0_wait_for_bootloader(psp
);
291 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
293 /* Copy PSP KDB binary to memory */
294 memcpy(psp
->fw_pri_buf
, psp
->kdb_start_addr
, psp
->kdb_bin_size
);
296 /* Provide the PSP KDB to bootloader */
297 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_36
,
298 (uint32_t)(psp
->fw_pri_mc_addr
>> 20));
299 psp_gfxdrv_command_reg
= PSP_BL__LOAD_KEY_DATABASE
;
300 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_35
,
301 psp_gfxdrv_command_reg
);
303 ret
= psp_v11_0_wait_for_bootloader(psp
);
308 static int psp_v11_0_bootloader_load_sysdrv(struct psp_context
*psp
)
311 uint32_t psp_gfxdrv_command_reg
= 0;
312 struct amdgpu_device
*adev
= psp
->adev
;
314 /* Check sOS sign of life register to confirm sys driver and sOS
315 * are already been loaded.
317 if (psp_v11_0_is_sos_alive(psp
)) {
318 psp
->sos_fw_version
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_58
);
319 dev_info(adev
->dev
, "sos fw version = 0x%x.\n", psp
->sos_fw_version
);
323 ret
= psp_v11_0_wait_for_bootloader(psp
);
327 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
329 /* Copy PSP System Driver binary to memory */
330 memcpy(psp
->fw_pri_buf
, psp
->sys_start_addr
, psp
->sys_bin_size
);
332 /* Provide the sys driver to bootloader */
333 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_36
,
334 (uint32_t)(psp
->fw_pri_mc_addr
>> 20));
335 psp_gfxdrv_command_reg
= PSP_BL__LOAD_SYSDRV
;
336 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_35
,
337 psp_gfxdrv_command_reg
);
339 /* there might be handshake issue with hardware which needs delay */
342 ret
= psp_v11_0_wait_for_bootloader(psp
);
347 static int psp_v11_0_bootloader_load_sos(struct psp_context
*psp
)
350 unsigned int psp_gfxdrv_command_reg
= 0;
351 struct amdgpu_device
*adev
= psp
->adev
;
353 /* Check sOS sign of life register to confirm sys driver and sOS
354 * are already been loaded.
356 if (psp_v11_0_is_sos_alive(psp
))
359 ret
= psp_v11_0_wait_for_bootloader(psp
);
363 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
365 /* Copy Secure OS binary to PSP memory */
366 memcpy(psp
->fw_pri_buf
, psp
->sos_start_addr
, psp
->sos_bin_size
);
368 /* Provide the PSP secure OS to bootloader */
369 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_36
,
370 (uint32_t)(psp
->fw_pri_mc_addr
>> 20));
371 psp_gfxdrv_command_reg
= PSP_BL__LOAD_SOSDRV
;
372 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_35
,
373 psp_gfxdrv_command_reg
);
375 /* there might be handshake issue with hardware which needs delay */
377 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_81
),
378 RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_81
),
384 static void psp_v11_0_reroute_ih(struct psp_context
*psp
)
386 struct amdgpu_device
*adev
= psp
->adev
;
389 /* Change IH ring for VMC */
390 tmp
= REG_SET_FIELD(0, IH_CLIENT_CFG_DATA
, CREDIT_RETURN_ADDR
, 0x1244b);
391 tmp
= REG_SET_FIELD(tmp
, IH_CLIENT_CFG_DATA
, CLIENT_TYPE
, 1);
392 tmp
= REG_SET_FIELD(tmp
, IH_CLIENT_CFG_DATA
, RING_ID
, 1);
394 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_69
, 3);
395 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_70
, tmp
);
396 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_64
, GFX_CTRL_CMD_ID_GBR_IH_SET
);
399 psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
),
400 0x80000000, 0x8000FFFF, false);
402 /* Change IH ring for UMC */
403 tmp
= REG_SET_FIELD(0, IH_CLIENT_CFG_DATA
, CREDIT_RETURN_ADDR
, 0x1216b);
404 tmp
= REG_SET_FIELD(tmp
, IH_CLIENT_CFG_DATA
, RING_ID
, 1);
406 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_69
, 4);
407 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_70
, tmp
);
408 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_64
, GFX_CTRL_CMD_ID_GBR_IH_SET
);
411 psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
),
412 0x80000000, 0x8000FFFF, false);
415 static int psp_v11_0_ring_init(struct psp_context
*psp
,
416 enum psp_ring_type ring_type
)
419 struct psp_ring
*ring
;
420 struct amdgpu_device
*adev
= psp
->adev
;
422 psp_v11_0_reroute_ih(psp
);
424 ring
= &psp
->km_ring
;
426 ring
->ring_type
= ring_type
;
428 /* allocate 4k Page of Local Frame Buffer memory for ring */
429 ring
->ring_size
= 0x1000;
430 ret
= amdgpu_bo_create_kernel(adev
, ring
->ring_size
, PAGE_SIZE
,
431 AMDGPU_GEM_DOMAIN_VRAM
,
432 &adev
->firmware
.rbuf
,
433 &ring
->ring_mem_mc_addr
,
434 (void **)&ring
->ring_mem
);
443 static bool psp_v11_0_support_vmr_ring(struct psp_context
*psp
)
445 if (amdgpu_sriov_vf(psp
->adev
) && psp
->sos_fw_version
> 0x80045)
450 static int psp_v11_0_ring_stop(struct psp_context
*psp
,
451 enum psp_ring_type ring_type
)
454 struct amdgpu_device
*adev
= psp
->adev
;
456 /* Write the ring destroy command*/
457 if (psp_v11_0_support_vmr_ring(psp
))
458 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_101
,
459 GFX_CTRL_CMD_ID_DESTROY_GPCOM_RING
);
461 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_64
,
462 GFX_CTRL_CMD_ID_DESTROY_RINGS
);
464 /* there might be handshake issue with hardware which needs delay */
467 /* Wait for response flag (bit 31) */
468 if (psp_v11_0_support_vmr_ring(psp
))
469 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_101
),
470 0x80000000, 0x80000000, false);
472 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
),
473 0x80000000, 0x80000000, false);
478 static int psp_v11_0_ring_create(struct psp_context
*psp
,
479 enum psp_ring_type ring_type
)
482 unsigned int psp_ring_reg
= 0;
483 struct psp_ring
*ring
= &psp
->km_ring
;
484 struct amdgpu_device
*adev
= psp
->adev
;
486 if (psp_v11_0_support_vmr_ring(psp
)) {
487 ret
= psp_v11_0_ring_stop(psp
, ring_type
);
489 DRM_ERROR("psp_v11_0_ring_stop_sriov failed!\n");
493 /* Write low address of the ring to C2PMSG_102 */
494 psp_ring_reg
= lower_32_bits(ring
->ring_mem_mc_addr
);
495 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_102
, psp_ring_reg
);
496 /* Write high address of the ring to C2PMSG_103 */
497 psp_ring_reg
= upper_32_bits(ring
->ring_mem_mc_addr
);
498 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_103
, psp_ring_reg
);
500 /* Write the ring initialization command to C2PMSG_101 */
501 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_101
,
502 GFX_CTRL_CMD_ID_INIT_GPCOM_RING
);
504 /* there might be handshake issue with hardware which needs delay */
507 /* Wait for response flag (bit 31) in C2PMSG_101 */
508 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_101
),
509 0x80000000, 0x8000FFFF, false);
512 /* Wait for sOS ready for ring creation */
513 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
),
514 0x80000000, 0x80000000, false);
516 DRM_ERROR("Failed to wait for sOS ready for ring creation\n");
520 /* Write low address of the ring to C2PMSG_69 */
521 psp_ring_reg
= lower_32_bits(ring
->ring_mem_mc_addr
);
522 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_69
, psp_ring_reg
);
523 /* Write high address of the ring to C2PMSG_70 */
524 psp_ring_reg
= upper_32_bits(ring
->ring_mem_mc_addr
);
525 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_70
, psp_ring_reg
);
526 /* Write size of ring to C2PMSG_71 */
527 psp_ring_reg
= ring
->ring_size
;
528 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_71
, psp_ring_reg
);
529 /* Write the ring initialization command to C2PMSG_64 */
530 psp_ring_reg
= ring_type
;
531 psp_ring_reg
= psp_ring_reg
<< 16;
532 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_64
, psp_ring_reg
);
534 /* there might be handshake issue with hardware which needs delay */
537 /* Wait for response flag (bit 31) in C2PMSG_64 */
538 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
),
539 0x80000000, 0x8000FFFF, false);
546 static int psp_v11_0_ring_destroy(struct psp_context
*psp
,
547 enum psp_ring_type ring_type
)
550 struct psp_ring
*ring
= &psp
->km_ring
;
551 struct amdgpu_device
*adev
= psp
->adev
;
553 ret
= psp_v11_0_ring_stop(psp
, ring_type
);
555 DRM_ERROR("Fail to stop psp ring\n");
557 amdgpu_bo_free_kernel(&adev
->firmware
.rbuf
,
558 &ring
->ring_mem_mc_addr
,
559 (void **)&ring
->ring_mem
);
565 psp_v11_0_sram_map(struct amdgpu_device
*adev
,
566 unsigned int *sram_offset
, unsigned int *sram_addr_reg_offset
,
567 unsigned int *sram_data_reg_offset
,
568 enum AMDGPU_UCODE_ID ucode_id
)
573 /* TODO: needs to confirm */
575 case AMDGPU_UCODE_ID_SMC
:
577 *sram_addr_reg_offset
= 0;
578 *sram_data_reg_offset
= 0;
582 case AMDGPU_UCODE_ID_CP_CE
:
584 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_CE_UCODE_ADDR
);
585 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_CE_UCODE_DATA
);
588 case AMDGPU_UCODE_ID_CP_PFP
:
590 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_PFP_UCODE_ADDR
);
591 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_PFP_UCODE_DATA
);
594 case AMDGPU_UCODE_ID_CP_ME
:
596 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_HYP_ME_UCODE_ADDR
);
597 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_HYP_ME_UCODE_DATA
);
600 case AMDGPU_UCODE_ID_CP_MEC1
:
601 *sram_offset
= 0x10000;
602 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_MEC_ME1_UCODE_ADDR
);
603 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_MEC_ME1_UCODE_DATA
);
606 case AMDGPU_UCODE_ID_CP_MEC2
:
607 *sram_offset
= 0x10000;
608 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_HYP_MEC2_UCODE_ADDR
);
609 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmCP_HYP_MEC2_UCODE_DATA
);
612 case AMDGPU_UCODE_ID_RLC_G
:
613 *sram_offset
= 0x2000;
614 if (adev
->asic_type
< CHIP_NAVI10
) {
615 *sram_addr_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmRLC_GPM_UCODE_ADDR
);
616 *sram_data_reg_offset
= SOC15_REG_OFFSET(GC
, 0, mmRLC_GPM_UCODE_DATA
);
618 *sram_addr_reg_offset
= adev
->reg_offset
[GC_HWIP
][0][1] + mmRLC_GPM_UCODE_ADDR_NV10
;
619 *sram_data_reg_offset
= adev
->reg_offset
[GC_HWIP
][0][1] + mmRLC_GPM_UCODE_DATA_NV10
;
623 case AMDGPU_UCODE_ID_SDMA0
:
625 if (adev
->asic_type
< CHIP_NAVI10
) {
626 *sram_addr_reg_offset
= SOC15_REG_OFFSET(SDMA0
, 0, mmSDMA0_UCODE_ADDR
);
627 *sram_data_reg_offset
= SOC15_REG_OFFSET(SDMA0
, 0, mmSDMA0_UCODE_DATA
);
629 *sram_addr_reg_offset
= adev
->reg_offset
[GC_HWIP
][0][1] + mmSDMA0_UCODE_ADDR_NV10
;
630 *sram_data_reg_offset
= adev
->reg_offset
[GC_HWIP
][0][1] + mmSDMA0_UCODE_DATA_NV10
;
634 /* TODO: needs to confirm */
636 case AMDGPU_UCODE_ID_SDMA1
:
638 *sram_addr_reg_offset
= ;
641 case AMDGPU_UCODE_ID_UVD
:
643 *sram_addr_reg_offset
= ;
646 case AMDGPU_UCODE_ID_VCE
:
648 *sram_addr_reg_offset
= ;
652 case AMDGPU_UCODE_ID_MAXIMUM
:
661 static bool psp_v11_0_compare_sram_data(struct psp_context
*psp
,
662 struct amdgpu_firmware_info
*ucode
,
663 enum AMDGPU_UCODE_ID ucode_type
)
666 unsigned int fw_sram_reg_val
= 0;
667 unsigned int fw_sram_addr_reg_offset
= 0;
668 unsigned int fw_sram_data_reg_offset
= 0;
669 unsigned int ucode_size
;
670 uint32_t *ucode_mem
= NULL
;
671 struct amdgpu_device
*adev
= psp
->adev
;
673 err
= psp_v11_0_sram_map(adev
, &fw_sram_reg_val
, &fw_sram_addr_reg_offset
,
674 &fw_sram_data_reg_offset
, ucode_type
);
678 WREG32(fw_sram_addr_reg_offset
, fw_sram_reg_val
);
680 ucode_size
= ucode
->ucode_size
;
681 ucode_mem
= (uint32_t *)ucode
->kaddr
;
683 fw_sram_reg_val
= RREG32(fw_sram_data_reg_offset
);
685 if (*ucode_mem
!= fw_sram_reg_val
)
696 static int psp_v11_0_mode1_reset(struct psp_context
*psp
)
700 struct amdgpu_device
*adev
= psp
->adev
;
702 offset
= SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_64
);
704 ret
= psp_wait_for(psp
, offset
, 0x80000000, 0x8000FFFF, false);
707 DRM_INFO("psp is not working correctly before mode1 reset!\n");
711 /*send the mode 1 reset command*/
712 WREG32(offset
, GFX_CTRL_CMD_ID_MODE1_RST
);
716 offset
= SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_33
);
718 ret
= psp_wait_for(psp
, offset
, 0x80000000, 0x80000000, false);
721 DRM_INFO("psp mode 1 reset failed!\n");
725 DRM_INFO("psp mode1 reset succeed \n");
730 /* TODO: Fill in follow functions once PSP firmware interface for XGMI is ready.
731 * For now, return success and hack the hive_id so high level code can
734 static int psp_v11_0_xgmi_get_topology_info(struct psp_context
*psp
,
735 int number_devices
, struct psp_xgmi_topology_info
*topology
)
737 struct ta_xgmi_shared_memory
*xgmi_cmd
;
738 struct ta_xgmi_cmd_get_topology_info_input
*topology_info_input
;
739 struct ta_xgmi_cmd_get_topology_info_output
*topology_info_output
;
743 if (!topology
|| topology
->num_nodes
> TA_XGMI__MAX_CONNECTED_NODES
)
746 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)psp
->xgmi_context
.xgmi_shared_buf
;
747 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
749 /* Fill in the shared memory with topology information as input */
750 topology_info_input
= &xgmi_cmd
->xgmi_in_message
.get_topology_info
;
751 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__GET_GET_TOPOLOGY_INFO
;
752 topology_info_input
->num_nodes
= number_devices
;
754 for (i
= 0; i
< topology_info_input
->num_nodes
; i
++) {
755 topology_info_input
->nodes
[i
].node_id
= topology
->nodes
[i
].node_id
;
756 topology_info_input
->nodes
[i
].num_hops
= topology
->nodes
[i
].num_hops
;
757 topology_info_input
->nodes
[i
].is_sharing_enabled
= topology
->nodes
[i
].is_sharing_enabled
;
758 topology_info_input
->nodes
[i
].sdma_engine
= topology
->nodes
[i
].sdma_engine
;
761 /* Invoke xgmi ta to get the topology information */
762 ret
= psp_xgmi_invoke(psp
, TA_COMMAND_XGMI__GET_GET_TOPOLOGY_INFO
);
766 /* Read the output topology information from the shared memory */
767 topology_info_output
= &xgmi_cmd
->xgmi_out_message
.get_topology_info
;
768 topology
->num_nodes
= xgmi_cmd
->xgmi_out_message
.get_topology_info
.num_nodes
;
769 for (i
= 0; i
< topology
->num_nodes
; i
++) {
770 topology
->nodes
[i
].node_id
= topology_info_output
->nodes
[i
].node_id
;
771 topology
->nodes
[i
].num_hops
= topology_info_output
->nodes
[i
].num_hops
;
772 topology
->nodes
[i
].is_sharing_enabled
= topology_info_output
->nodes
[i
].is_sharing_enabled
;
773 topology
->nodes
[i
].sdma_engine
= topology_info_output
->nodes
[i
].sdma_engine
;
779 static int psp_v11_0_xgmi_set_topology_info(struct psp_context
*psp
,
780 int number_devices
, struct psp_xgmi_topology_info
*topology
)
782 struct ta_xgmi_shared_memory
*xgmi_cmd
;
783 struct ta_xgmi_cmd_get_topology_info_input
*topology_info_input
;
786 if (!topology
|| topology
->num_nodes
> TA_XGMI__MAX_CONNECTED_NODES
)
789 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)psp
->xgmi_context
.xgmi_shared_buf
;
790 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
792 topology_info_input
= &xgmi_cmd
->xgmi_in_message
.get_topology_info
;
793 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__SET_TOPOLOGY_INFO
;
794 topology_info_input
->num_nodes
= number_devices
;
796 for (i
= 0; i
< topology_info_input
->num_nodes
; i
++) {
797 topology_info_input
->nodes
[i
].node_id
= topology
->nodes
[i
].node_id
;
798 topology_info_input
->nodes
[i
].num_hops
= topology
->nodes
[i
].num_hops
;
799 topology_info_input
->nodes
[i
].is_sharing_enabled
= 1;
800 topology_info_input
->nodes
[i
].sdma_engine
= topology
->nodes
[i
].sdma_engine
;
803 /* Invoke xgmi ta to set topology information */
804 return psp_xgmi_invoke(psp
, TA_COMMAND_XGMI__SET_TOPOLOGY_INFO
);
807 static int psp_v11_0_xgmi_get_hive_id(struct psp_context
*psp
, uint64_t *hive_id
)
809 struct ta_xgmi_shared_memory
*xgmi_cmd
;
812 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)psp
->xgmi_context
.xgmi_shared_buf
;
813 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
815 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__GET_HIVE_ID
;
817 /* Invoke xgmi ta to get hive id */
818 ret
= psp_xgmi_invoke(psp
, xgmi_cmd
->cmd_id
);
822 *hive_id
= xgmi_cmd
->xgmi_out_message
.get_hive_id
.hive_id
;
827 static int psp_v11_0_xgmi_get_node_id(struct psp_context
*psp
, uint64_t *node_id
)
829 struct ta_xgmi_shared_memory
*xgmi_cmd
;
832 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)psp
->xgmi_context
.xgmi_shared_buf
;
833 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
835 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__GET_NODE_ID
;
837 /* Invoke xgmi ta to get the node id */
838 ret
= psp_xgmi_invoke(psp
, xgmi_cmd
->cmd_id
);
842 *node_id
= xgmi_cmd
->xgmi_out_message
.get_node_id
.node_id
;
847 static int psp_v11_0_ras_trigger_error(struct psp_context
*psp
,
848 struct ta_ras_trigger_error_input
*info
)
850 struct ta_ras_shared_memory
*ras_cmd
;
853 if (!psp
->ras
.ras_initialized
)
856 ras_cmd
= (struct ta_ras_shared_memory
*)psp
->ras
.ras_shared_buf
;
857 memset(ras_cmd
, 0, sizeof(struct ta_ras_shared_memory
));
859 ras_cmd
->cmd_id
= TA_RAS_COMMAND__TRIGGER_ERROR
;
860 ras_cmd
->ras_in_message
.trigger_error
= *info
;
862 ret
= psp_ras_invoke(psp
, ras_cmd
->cmd_id
);
866 return ras_cmd
->ras_status
;
869 static int psp_v11_0_ras_cure_posion(struct psp_context
*psp
, uint64_t *mode_ptr
)
873 struct ta_ras_shared_memory
*ras_cmd
;
876 if (!psp
->ras
.ras_initialized
)
879 ras_cmd
= (struct ta_ras_shared_memory
*)psp
->ras
.ras_shared_buf
;
880 memset(ras_cmd
, 0, sizeof(struct ta_ras_shared_memory
));
882 ras_cmd
->cmd_id
= TA_RAS_COMMAND__CURE_POISON
;
883 ras_cmd
->ras_in_message
.cure_poison
.mode_ptr
= mode_ptr
;
885 ret
= psp_ras_invoke(psp
, ras_cmd
->cmd_id
);
889 return ras_cmd
->ras_status
;
895 static int psp_v11_0_rlc_autoload_start(struct psp_context
*psp
)
897 return psp_rlc_autoload_start(psp
);
900 static int psp_v11_0_memory_training_send_msg(struct psp_context
*psp
, int msg
)
906 struct amdgpu_device
*adev
= psp
->adev
;
908 data_32
= (psp
->mem_train_ctx
.c2p_train_data_offset
>> 20);
909 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_36
, data_32
);
910 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_35
, msg
);
912 max_wait
= MEM_TRAIN_SEND_MSG_TIMEOUT_US
/ adev
->usec_timeout
;
913 for (i
= 0; i
< max_wait
; i
++) {
914 ret
= psp_wait_for(psp
, SOC15_REG_OFFSET(MP0
, 0, mmMP0_SMN_C2PMSG_35
),
915 0x80000000, 0x80000000, false);
924 DRM_DEBUG("training %s %s, cost %d @ %d ms\n",
925 (msg
== PSP_BL__DRAM_SHORT_TRAIN
) ? "short" : "long",
926 (ret
== 0) ? "succeed" : "failed",
927 i
, adev
->usec_timeout
/1000);
931 static void psp_v11_0_memory_training_fini(struct psp_context
*psp
)
933 struct psp_memory_training_context
*ctx
= &psp
->mem_train_ctx
;
935 ctx
->init
= PSP_MEM_TRAIN_NOT_SUPPORT
;
936 kfree(ctx
->sys_cache
);
937 ctx
->sys_cache
= NULL
;
940 static int psp_v11_0_memory_training_init(struct psp_context
*psp
)
943 struct psp_memory_training_context
*ctx
= &psp
->mem_train_ctx
;
945 if (ctx
->init
!= PSP_MEM_TRAIN_RESERVE_SUCCESS
) {
946 DRM_DEBUG("memory training is not supported!\n");
950 ctx
->sys_cache
= kzalloc(ctx
->train_data_size
, GFP_KERNEL
);
951 if (ctx
->sys_cache
== NULL
) {
952 DRM_ERROR("alloc mem_train_ctx.sys_cache failed!\n");
957 DRM_DEBUG("train_data_size:%llx,p2c_train_data_offset:%llx,c2p_train_data_offset:%llx.\n",
958 ctx
->train_data_size
,
959 ctx
->p2c_train_data_offset
,
960 ctx
->c2p_train_data_offset
);
961 ctx
->init
= PSP_MEM_TRAIN_INIT_SUCCESS
;
965 psp_v11_0_memory_training_fini(psp
);
970 * save and restore proces
972 static int psp_v11_0_memory_training(struct psp_context
*psp
, uint32_t ops
)
975 uint32_t p2c_header
[4];
976 struct psp_memory_training_context
*ctx
= &psp
->mem_train_ctx
;
977 uint32_t *pcache
= (uint32_t*)ctx
->sys_cache
;
979 if (ctx
->init
== PSP_MEM_TRAIN_NOT_SUPPORT
) {
980 DRM_DEBUG("Memory training is not supported.\n");
982 } else if (ctx
->init
!= PSP_MEM_TRAIN_INIT_SUCCESS
) {
983 DRM_ERROR("Memory training initialization failure.\n");
987 if (psp_v11_0_is_sos_alive(psp
)) {
988 DRM_DEBUG("SOS is alive, skip memory training.\n");
992 amdgpu_device_vram_access(psp
->adev
, ctx
->p2c_train_data_offset
, p2c_header
, sizeof(p2c_header
), false);
993 DRM_DEBUG("sys_cache[%08x,%08x,%08x,%08x] p2c_header[%08x,%08x,%08x,%08x]\n",
994 pcache
[0], pcache
[1], pcache
[2], pcache
[3],
995 p2c_header
[0], p2c_header
[1], p2c_header
[2], p2c_header
[3]);
997 if (ops
& PSP_MEM_TRAIN_SEND_SHORT_MSG
) {
998 DRM_DEBUG("Short training depends on restore.\n");
999 ops
|= PSP_MEM_TRAIN_RESTORE
;
1002 if ((ops
& PSP_MEM_TRAIN_RESTORE
) &&
1003 pcache
[0] != MEM_TRAIN_SYSTEM_SIGNATURE
) {
1004 DRM_DEBUG("sys_cache[0] is invalid, restore depends on save.\n");
1005 ops
|= PSP_MEM_TRAIN_SAVE
;
1008 if (p2c_header
[0] == MEM_TRAIN_SYSTEM_SIGNATURE
&&
1009 !(pcache
[0] == MEM_TRAIN_SYSTEM_SIGNATURE
&&
1010 pcache
[3] == p2c_header
[3])) {
1011 DRM_DEBUG("sys_cache is invalid or out-of-date, need save training data to sys_cache.\n");
1012 ops
|= PSP_MEM_TRAIN_SAVE
;
1015 if ((ops
& PSP_MEM_TRAIN_SAVE
) &&
1016 p2c_header
[0] != MEM_TRAIN_SYSTEM_SIGNATURE
) {
1017 DRM_DEBUG("p2c_header[0] is invalid, save depends on long training.\n");
1018 ops
|= PSP_MEM_TRAIN_SEND_LONG_MSG
;
1021 if (ops
& PSP_MEM_TRAIN_SEND_LONG_MSG
) {
1022 ops
&= ~PSP_MEM_TRAIN_SEND_SHORT_MSG
;
1023 ops
|= PSP_MEM_TRAIN_SAVE
;
1026 DRM_DEBUG("Memory training ops:%x.\n", ops
);
1028 if (ops
& PSP_MEM_TRAIN_SEND_LONG_MSG
) {
1029 ret
= psp_v11_0_memory_training_send_msg(psp
, PSP_BL__DRAM_LONG_TRAIN
);
1031 DRM_ERROR("Send long training msg failed.\n");
1036 if (ops
& PSP_MEM_TRAIN_SAVE
) {
1037 amdgpu_device_vram_access(psp
->adev
, ctx
->p2c_train_data_offset
, ctx
->sys_cache
, ctx
->train_data_size
, false);
1040 if (ops
& PSP_MEM_TRAIN_RESTORE
) {
1041 amdgpu_device_vram_access(psp
->adev
, ctx
->c2p_train_data_offset
, ctx
->sys_cache
, ctx
->train_data_size
, true);
1044 if (ops
& PSP_MEM_TRAIN_SEND_SHORT_MSG
) {
1045 ret
= psp_v11_0_memory_training_send_msg(psp
, (amdgpu_force_long_training
> 0) ?
1046 PSP_BL__DRAM_LONG_TRAIN
: PSP_BL__DRAM_SHORT_TRAIN
);
1048 DRM_ERROR("send training msg failed.\n");
1052 ctx
->training_cnt
++;
1056 static uint32_t psp_v11_0_ring_get_wptr(struct psp_context
*psp
)
1059 struct amdgpu_device
*adev
= psp
->adev
;
1061 if (psp_v11_0_support_vmr_ring(psp
))
1062 data
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_102
);
1064 data
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_67
);
1069 static void psp_v11_0_ring_set_wptr(struct psp_context
*psp
, uint32_t value
)
1071 struct amdgpu_device
*adev
= psp
->adev
;
1073 if (psp_v11_0_support_vmr_ring(psp
)) {
1074 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_102
, value
);
1075 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_101
, GFX_CTRL_CMD_ID_CONSUME_CMD
);
1077 WREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_67
, value
);
1080 static const struct psp_funcs psp_v11_0_funcs
= {
1081 .init_microcode
= psp_v11_0_init_microcode
,
1082 .bootloader_load_kdb
= psp_v11_0_bootloader_load_kdb
,
1083 .bootloader_load_sysdrv
= psp_v11_0_bootloader_load_sysdrv
,
1084 .bootloader_load_sos
= psp_v11_0_bootloader_load_sos
,
1085 .ring_init
= psp_v11_0_ring_init
,
1086 .ring_create
= psp_v11_0_ring_create
,
1087 .ring_stop
= psp_v11_0_ring_stop
,
1088 .ring_destroy
= psp_v11_0_ring_destroy
,
1089 .compare_sram_data
= psp_v11_0_compare_sram_data
,
1090 .mode1_reset
= psp_v11_0_mode1_reset
,
1091 .xgmi_get_topology_info
= psp_v11_0_xgmi_get_topology_info
,
1092 .xgmi_set_topology_info
= psp_v11_0_xgmi_set_topology_info
,
1093 .xgmi_get_hive_id
= psp_v11_0_xgmi_get_hive_id
,
1094 .xgmi_get_node_id
= psp_v11_0_xgmi_get_node_id
,
1095 .support_vmr_ring
= psp_v11_0_support_vmr_ring
,
1096 .ras_trigger_error
= psp_v11_0_ras_trigger_error
,
1097 .ras_cure_posion
= psp_v11_0_ras_cure_posion
,
1098 .rlc_autoload_start
= psp_v11_0_rlc_autoload_start
,
1099 .mem_training_init
= psp_v11_0_memory_training_init
,
1100 .mem_training_fini
= psp_v11_0_memory_training_fini
,
1101 .mem_training
= psp_v11_0_memory_training
,
1102 .ring_get_wptr
= psp_v11_0_ring_get_wptr
,
1103 .ring_set_wptr
= psp_v11_0_ring_set_wptr
,
1106 void psp_v11_0_set_psp_funcs(struct psp_context
*psp
)
1108 psp
->funcs
= &psp_v11_0_funcs
;