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.
26 #include <linux/firmware.h>
29 #include "amdgpu_psp.h"
30 #include "amdgpu_ucode.h"
31 #include "soc15_common.h"
33 #include "psp_v10_0.h"
34 #include "psp_v11_0.h"
35 #include "psp_v12_0.h"
37 #include "amdgpu_ras.h"
39 static void psp_set_funcs(struct amdgpu_device
*adev
);
41 static int psp_early_init(void *handle
)
43 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
44 struct psp_context
*psp
= &adev
->psp
;
48 switch (adev
->asic_type
) {
51 psp_v3_1_set_psp_funcs(psp
);
52 psp
->autoload_supported
= false;
55 psp_v10_0_set_psp_funcs(psp
);
56 psp
->autoload_supported
= false;
60 psp_v11_0_set_psp_funcs(psp
);
61 psp
->autoload_supported
= false;
66 psp_v11_0_set_psp_funcs(psp
);
67 psp
->autoload_supported
= true;
70 psp_v12_0_set_psp_funcs(psp
);
81 static int psp_sw_init(void *handle
)
83 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
84 struct psp_context
*psp
= &adev
->psp
;
87 ret
= psp_init_microcode(psp
);
89 DRM_ERROR("Failed to load psp firmware!\n");
93 ret
= psp_mem_training_init(psp
);
95 DRM_ERROR("Failed to initialize memory training!\n");
98 ret
= psp_mem_training(psp
, PSP_MEM_TRAIN_COLD_BOOT
);
100 DRM_ERROR("Failed to process memory training!\n");
107 static int psp_sw_fini(void *handle
)
109 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
111 psp_mem_training_fini(&adev
->psp
);
112 release_firmware(adev
->psp
.sos_fw
);
113 adev
->psp
.sos_fw
= NULL
;
114 release_firmware(adev
->psp
.asd_fw
);
115 adev
->psp
.asd_fw
= NULL
;
116 if (adev
->psp
.ta_fw
) {
117 release_firmware(adev
->psp
.ta_fw
);
118 adev
->psp
.ta_fw
= NULL
;
123 int psp_wait_for(struct psp_context
*psp
, uint32_t reg_index
,
124 uint32_t reg_val
, uint32_t mask
, bool check_changed
)
128 struct amdgpu_device
*adev
= psp
->adev
;
130 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
131 val
= RREG32(reg_index
);
136 if ((val
& mask
) == reg_val
)
146 psp_cmd_submit_buf(struct psp_context
*psp
,
147 struct amdgpu_firmware_info
*ucode
,
148 struct psp_gfx_cmd_resp
*cmd
, uint64_t fence_mc_addr
)
154 mutex_lock(&psp
->mutex
);
156 memset(psp
->cmd_buf_mem
, 0, PSP_CMD_BUFFER_SIZE
);
158 memcpy(psp
->cmd_buf_mem
, cmd
, sizeof(struct psp_gfx_cmd_resp
));
160 index
= atomic_inc_return(&psp
->fence_value
);
161 ret
= psp_ring_cmd_submit(psp
, psp
->cmd_buf_mc_addr
, fence_mc_addr
, index
);
163 atomic_dec(&psp
->fence_value
);
164 mutex_unlock(&psp
->mutex
);
168 amdgpu_asic_invalidate_hdp(psp
->adev
, NULL
);
169 while (*((unsigned int *)psp
->fence_buf
) != index
) {
173 * Shouldn't wait for timeout when err_event_athub occurs,
174 * because gpu reset thread triggered and lock resource should
175 * be released for psp resume sequence.
177 if (amdgpu_ras_intr_triggered())
180 amdgpu_asic_invalidate_hdp(psp
->adev
, NULL
);
183 /* In some cases, psp response status is not 0 even there is no
184 * problem while the command is submitted. Some version of PSP FW
185 * doesn't write 0 to that field.
186 * So here we would like to only print a warning instead of an error
187 * during psp initialization to avoid breaking hw_init and it doesn't
190 if (psp
->cmd_buf_mem
->resp
.status
|| !timeout
) {
192 DRM_WARN("failed to load ucode id (%d) ",
194 DRM_WARN("psp command (0x%X) failed and response status is (0x%X)\n",
195 psp
->cmd_buf_mem
->cmd_id
,
196 psp
->cmd_buf_mem
->resp
.status
);
198 mutex_unlock(&psp
->mutex
);
203 /* get xGMI session id from response buffer */
204 cmd
->resp
.session_id
= psp
->cmd_buf_mem
->resp
.session_id
;
207 ucode
->tmr_mc_addr_lo
= psp
->cmd_buf_mem
->resp
.fw_addr_lo
;
208 ucode
->tmr_mc_addr_hi
= psp
->cmd_buf_mem
->resp
.fw_addr_hi
;
210 mutex_unlock(&psp
->mutex
);
215 static void psp_prep_tmr_cmd_buf(struct psp_context
*psp
,
216 struct psp_gfx_cmd_resp
*cmd
,
217 uint64_t tmr_mc
, uint32_t size
)
219 if (psp_support_vmr_ring(psp
))
220 cmd
->cmd_id
= GFX_CMD_ID_SETUP_VMR
;
222 cmd
->cmd_id
= GFX_CMD_ID_SETUP_TMR
;
223 cmd
->cmd
.cmd_setup_tmr
.buf_phy_addr_lo
= lower_32_bits(tmr_mc
);
224 cmd
->cmd
.cmd_setup_tmr
.buf_phy_addr_hi
= upper_32_bits(tmr_mc
);
225 cmd
->cmd
.cmd_setup_tmr
.buf_size
= size
;
228 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
229 uint64_t pri_buf_mc
, uint32_t size
)
231 cmd
->cmd_id
= GFX_CMD_ID_LOAD_TOC
;
232 cmd
->cmd
.cmd_load_toc
.toc_phy_addr_lo
= lower_32_bits(pri_buf_mc
);
233 cmd
->cmd
.cmd_load_toc
.toc_phy_addr_hi
= upper_32_bits(pri_buf_mc
);
234 cmd
->cmd
.cmd_load_toc
.toc_size
= size
;
237 /* Issue LOAD TOC cmd to PSP to part toc and calculate tmr size needed */
238 static int psp_load_toc(struct psp_context
*psp
,
242 struct psp_gfx_cmd_resp
*cmd
;
244 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
247 /* Copy toc to psp firmware private buffer */
248 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
249 memcpy(psp
->fw_pri_buf
, psp
->toc_start_addr
, psp
->toc_bin_size
);
251 psp_prep_load_toc_cmd_buf(cmd
, psp
->fw_pri_mc_addr
, psp
->toc_bin_size
);
253 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
254 psp
->fence_buf_mc_addr
);
256 *tmr_size
= psp
->cmd_buf_mem
->resp
.tmr_size
;
261 /* Set up Trusted Memory Region */
262 static int psp_tmr_init(struct psp_context
*psp
)
270 * According to HW engineer, they prefer the TMR address be "naturally
271 * aligned" , e.g. the start address be an integer divide of TMR size.
273 * Note: this memory need be reserved till the driver
276 tmr_size
= PSP_TMR_SIZE
;
278 /* For ASICs support RLC autoload, psp will parse the toc
279 * and calculate the total size of TMR needed */
280 if (!amdgpu_sriov_vf(psp
->adev
) &&
281 psp
->toc_start_addr
&&
284 ret
= psp_load_toc(psp
, &tmr_size
);
286 DRM_ERROR("Failed to load toc\n");
291 pptr
= amdgpu_sriov_vf(psp
->adev
) ? &tmr_buf
: NULL
;
292 ret
= amdgpu_bo_create_kernel(psp
->adev
, tmr_size
, PSP_TMR_SIZE
,
293 AMDGPU_GEM_DOMAIN_VRAM
,
294 &psp
->tmr_bo
, &psp
->tmr_mc_addr
, pptr
);
299 static int psp_tmr_load(struct psp_context
*psp
)
302 struct psp_gfx_cmd_resp
*cmd
;
304 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
308 psp_prep_tmr_cmd_buf(psp
, cmd
, psp
->tmr_mc_addr
,
309 amdgpu_bo_size(psp
->tmr_bo
));
310 DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
311 amdgpu_bo_size(psp
->tmr_bo
), psp
->tmr_mc_addr
);
313 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
314 psp
->fence_buf_mc_addr
);
321 static void psp_prep_asd_load_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
322 uint64_t asd_mc
, uint32_t size
)
324 cmd
->cmd_id
= GFX_CMD_ID_LOAD_ASD
;
325 cmd
->cmd
.cmd_load_ta
.app_phy_addr_lo
= lower_32_bits(asd_mc
);
326 cmd
->cmd
.cmd_load_ta
.app_phy_addr_hi
= upper_32_bits(asd_mc
);
327 cmd
->cmd
.cmd_load_ta
.app_len
= size
;
329 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_lo
= 0;
330 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_hi
= 0;
331 cmd
->cmd
.cmd_load_ta
.cmd_buf_len
= 0;
334 static int psp_asd_load(struct psp_context
*psp
)
337 struct psp_gfx_cmd_resp
*cmd
;
339 /* If PSP version doesn't match ASD version, asd loading will be failed.
340 * add workaround to bypass it for sriov now.
341 * TODO: add version check to make it common
343 if (amdgpu_sriov_vf(psp
->adev
))
346 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
350 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
351 memcpy(psp
->fw_pri_buf
, psp
->asd_start_addr
, psp
->asd_ucode_size
);
353 psp_prep_asd_load_cmd_buf(cmd
, psp
->fw_pri_mc_addr
,
354 psp
->asd_ucode_size
);
356 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
357 psp
->fence_buf_mc_addr
);
359 psp
->asd_context
.asd_initialized
= true;
360 psp
->asd_context
.session_id
= cmd
->resp
.session_id
;
368 static void psp_prep_ta_unload_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
371 cmd
->cmd_id
= GFX_CMD_ID_UNLOAD_TA
;
372 cmd
->cmd
.cmd_unload_ta
.session_id
= session_id
;
375 static int psp_asd_unload(struct psp_context
*psp
)
378 struct psp_gfx_cmd_resp
*cmd
;
380 if (amdgpu_sriov_vf(psp
->adev
))
383 if (!psp
->asd_context
.asd_initialized
)
386 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
390 psp_prep_ta_unload_cmd_buf(cmd
, psp
->asd_context
.session_id
);
392 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
393 psp
->fence_buf_mc_addr
);
395 psp
->asd_context
.asd_initialized
= false;
402 static void psp_prep_reg_prog_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
403 uint32_t id
, uint32_t value
)
405 cmd
->cmd_id
= GFX_CMD_ID_PROG_REG
;
406 cmd
->cmd
.cmd_setup_reg_prog
.reg_value
= value
;
407 cmd
->cmd
.cmd_setup_reg_prog
.reg_id
= id
;
410 int psp_reg_program(struct psp_context
*psp
, enum psp_reg_prog_id reg
,
413 struct psp_gfx_cmd_resp
*cmd
= NULL
;
416 if (reg
>= PSP_REG_LAST
)
419 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
423 psp_prep_reg_prog_cmd_buf(cmd
, reg
, value
);
424 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
, psp
->fence_buf_mc_addr
);
430 static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
432 uint32_t ta_bin_size
,
433 uint64_t ta_shared_mc
,
434 uint32_t ta_shared_size
)
436 cmd
->cmd_id
= GFX_CMD_ID_LOAD_TA
;
437 cmd
->cmd
.cmd_load_ta
.app_phy_addr_lo
= lower_32_bits(ta_bin_mc
);
438 cmd
->cmd
.cmd_load_ta
.app_phy_addr_hi
= upper_32_bits(ta_bin_mc
);
439 cmd
->cmd
.cmd_load_ta
.app_len
= ta_bin_size
;
441 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_lo
= lower_32_bits(ta_shared_mc
);
442 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_hi
= upper_32_bits(ta_shared_mc
);
443 cmd
->cmd
.cmd_load_ta
.cmd_buf_len
= ta_shared_size
;
446 static int psp_xgmi_init_shared_buf(struct psp_context
*psp
)
451 * Allocate 16k memory aligned to 4k from Frame Buffer (local
452 * physical) for xgmi ta <-> Driver
454 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_XGMI_SHARED_MEM_SIZE
,
455 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
456 &psp
->xgmi_context
.xgmi_shared_bo
,
457 &psp
->xgmi_context
.xgmi_shared_mc_addr
,
458 &psp
->xgmi_context
.xgmi_shared_buf
);
463 static void psp_prep_ta_invoke_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
467 cmd
->cmd_id
= GFX_CMD_ID_INVOKE_CMD
;
468 cmd
->cmd
.cmd_invoke_cmd
.session_id
= session_id
;
469 cmd
->cmd
.cmd_invoke_cmd
.ta_cmd_id
= ta_cmd_id
;
472 int psp_ta_invoke(struct psp_context
*psp
,
477 struct psp_gfx_cmd_resp
*cmd
;
479 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
483 psp_prep_ta_invoke_cmd_buf(cmd
, ta_cmd_id
, session_id
);
485 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
486 psp
->fence_buf_mc_addr
);
493 static int psp_xgmi_load(struct psp_context
*psp
)
496 struct psp_gfx_cmd_resp
*cmd
;
499 * TODO: bypass the loading in sriov for now
502 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
506 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
507 memcpy(psp
->fw_pri_buf
, psp
->ta_xgmi_start_addr
, psp
->ta_xgmi_ucode_size
);
509 psp_prep_ta_load_cmd_buf(cmd
,
511 psp
->ta_xgmi_ucode_size
,
512 psp
->xgmi_context
.xgmi_shared_mc_addr
,
513 PSP_XGMI_SHARED_MEM_SIZE
);
515 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
516 psp
->fence_buf_mc_addr
);
519 psp
->xgmi_context
.initialized
= 1;
520 psp
->xgmi_context
.session_id
= cmd
->resp
.session_id
;
528 static int psp_xgmi_unload(struct psp_context
*psp
)
531 struct psp_gfx_cmd_resp
*cmd
;
532 struct amdgpu_device
*adev
= psp
->adev
;
534 /* XGMI TA unload currently is not supported on Arcturus */
535 if (adev
->asic_type
== CHIP_ARCTURUS
)
539 * TODO: bypass the unloading in sriov for now
542 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
546 psp_prep_ta_unload_cmd_buf(cmd
, psp
->xgmi_context
.session_id
);
548 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
549 psp
->fence_buf_mc_addr
);
556 int psp_xgmi_invoke(struct psp_context
*psp
, uint32_t ta_cmd_id
)
558 return psp_ta_invoke(psp
, ta_cmd_id
, psp
->xgmi_context
.session_id
);
561 static int psp_xgmi_terminate(struct psp_context
*psp
)
565 if (!psp
->xgmi_context
.initialized
)
568 ret
= psp_xgmi_unload(psp
);
572 psp
->xgmi_context
.initialized
= 0;
574 /* free xgmi shared memory */
575 amdgpu_bo_free_kernel(&psp
->xgmi_context
.xgmi_shared_bo
,
576 &psp
->xgmi_context
.xgmi_shared_mc_addr
,
577 &psp
->xgmi_context
.xgmi_shared_buf
);
582 static int psp_xgmi_initialize(struct psp_context
*psp
)
584 struct ta_xgmi_shared_memory
*xgmi_cmd
;
587 if (!psp
->adev
->psp
.ta_fw
||
588 !psp
->adev
->psp
.ta_xgmi_ucode_size
||
589 !psp
->adev
->psp
.ta_xgmi_start_addr
)
592 if (!psp
->xgmi_context
.initialized
) {
593 ret
= psp_xgmi_init_shared_buf(psp
);
599 ret
= psp_xgmi_load(psp
);
603 /* Initialize XGMI session */
604 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)(psp
->xgmi_context
.xgmi_shared_buf
);
605 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
606 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__INITIALIZE
;
608 ret
= psp_xgmi_invoke(psp
, xgmi_cmd
->cmd_id
);
614 static int psp_ras_init_shared_buf(struct psp_context
*psp
)
619 * Allocate 16k memory aligned to 4k from Frame Buffer (local
620 * physical) for ras ta <-> Driver
622 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_RAS_SHARED_MEM_SIZE
,
623 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
624 &psp
->ras
.ras_shared_bo
,
625 &psp
->ras
.ras_shared_mc_addr
,
626 &psp
->ras
.ras_shared_buf
);
631 static int psp_ras_load(struct psp_context
*psp
)
634 struct psp_gfx_cmd_resp
*cmd
;
637 * TODO: bypass the loading in sriov for now
639 if (amdgpu_sriov_vf(psp
->adev
))
642 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
646 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
647 memcpy(psp
->fw_pri_buf
, psp
->ta_ras_start_addr
, psp
->ta_ras_ucode_size
);
649 psp_prep_ta_load_cmd_buf(cmd
,
651 psp
->ta_ras_ucode_size
,
652 psp
->ras
.ras_shared_mc_addr
,
653 PSP_RAS_SHARED_MEM_SIZE
);
655 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
656 psp
->fence_buf_mc_addr
);
659 psp
->ras
.ras_initialized
= true;
660 psp
->ras
.session_id
= cmd
->resp
.session_id
;
668 static int psp_ras_unload(struct psp_context
*psp
)
671 struct psp_gfx_cmd_resp
*cmd
;
674 * TODO: bypass the unloading in sriov for now
676 if (amdgpu_sriov_vf(psp
->adev
))
679 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
683 psp_prep_ta_unload_cmd_buf(cmd
, psp
->ras
.session_id
);
685 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
686 psp
->fence_buf_mc_addr
);
693 int psp_ras_invoke(struct psp_context
*psp
, uint32_t ta_cmd_id
)
696 * TODO: bypass the loading in sriov for now
698 if (amdgpu_sriov_vf(psp
->adev
))
701 return psp_ta_invoke(psp
, ta_cmd_id
, psp
->ras
.session_id
);
704 int psp_ras_enable_features(struct psp_context
*psp
,
705 union ta_ras_cmd_input
*info
, bool enable
)
707 struct ta_ras_shared_memory
*ras_cmd
;
710 if (!psp
->ras
.ras_initialized
)
713 ras_cmd
= (struct ta_ras_shared_memory
*)psp
->ras
.ras_shared_buf
;
714 memset(ras_cmd
, 0, sizeof(struct ta_ras_shared_memory
));
717 ras_cmd
->cmd_id
= TA_RAS_COMMAND__ENABLE_FEATURES
;
719 ras_cmd
->cmd_id
= TA_RAS_COMMAND__DISABLE_FEATURES
;
721 ras_cmd
->ras_in_message
= *info
;
723 ret
= psp_ras_invoke(psp
, ras_cmd
->cmd_id
);
727 return ras_cmd
->ras_status
;
730 static int psp_ras_terminate(struct psp_context
*psp
)
735 * TODO: bypass the terminate in sriov for now
737 if (amdgpu_sriov_vf(psp
->adev
))
740 if (!psp
->ras
.ras_initialized
)
743 ret
= psp_ras_unload(psp
);
747 psp
->ras
.ras_initialized
= false;
749 /* free ras shared memory */
750 amdgpu_bo_free_kernel(&psp
->ras
.ras_shared_bo
,
751 &psp
->ras
.ras_shared_mc_addr
,
752 &psp
->ras
.ras_shared_buf
);
757 static int psp_ras_initialize(struct psp_context
*psp
)
762 * TODO: bypass the initialize in sriov for now
764 if (amdgpu_sriov_vf(psp
->adev
))
767 if (!psp
->adev
->psp
.ta_ras_ucode_size
||
768 !psp
->adev
->psp
.ta_ras_start_addr
) {
769 dev_warn(psp
->adev
->dev
, "RAS: ras ta ucode is not available\n");
773 if (!psp
->ras
.ras_initialized
) {
774 ret
= psp_ras_init_shared_buf(psp
);
779 ret
= psp_ras_load(psp
);
788 static int psp_hdcp_init_shared_buf(struct psp_context
*psp
)
793 * Allocate 16k memory aligned to 4k from Frame Buffer (local
794 * physical) for hdcp ta <-> Driver
796 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_HDCP_SHARED_MEM_SIZE
,
797 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
798 &psp
->hdcp_context
.hdcp_shared_bo
,
799 &psp
->hdcp_context
.hdcp_shared_mc_addr
,
800 &psp
->hdcp_context
.hdcp_shared_buf
);
805 static int psp_hdcp_load(struct psp_context
*psp
)
808 struct psp_gfx_cmd_resp
*cmd
;
811 * TODO: bypass the loading in sriov for now
813 if (amdgpu_sriov_vf(psp
->adev
))
816 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
820 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
821 memcpy(psp
->fw_pri_buf
, psp
->ta_hdcp_start_addr
,
822 psp
->ta_hdcp_ucode_size
);
824 psp_prep_ta_load_cmd_buf(cmd
,
826 psp
->ta_hdcp_ucode_size
,
827 psp
->hdcp_context
.hdcp_shared_mc_addr
,
828 PSP_HDCP_SHARED_MEM_SIZE
);
830 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
, psp
->fence_buf_mc_addr
);
833 psp
->hdcp_context
.hdcp_initialized
= true;
834 psp
->hdcp_context
.session_id
= cmd
->resp
.session_id
;
841 static int psp_hdcp_initialize(struct psp_context
*psp
)
846 * TODO: bypass the initialize in sriov for now
848 if (amdgpu_sriov_vf(psp
->adev
))
851 if (!psp
->adev
->psp
.ta_hdcp_ucode_size
||
852 !psp
->adev
->psp
.ta_hdcp_start_addr
) {
853 dev_warn(psp
->adev
->dev
, "HDCP: hdcp ta ucode is not available\n");
857 if (!psp
->hdcp_context
.hdcp_initialized
) {
858 ret
= psp_hdcp_init_shared_buf(psp
);
863 ret
= psp_hdcp_load(psp
);
870 static int psp_hdcp_unload(struct psp_context
*psp
)
873 struct psp_gfx_cmd_resp
*cmd
;
876 * TODO: bypass the unloading in sriov for now
878 if (amdgpu_sriov_vf(psp
->adev
))
881 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
885 psp_prep_ta_unload_cmd_buf(cmd
, psp
->hdcp_context
.session_id
);
887 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
, psp
->fence_buf_mc_addr
);
894 int psp_hdcp_invoke(struct psp_context
*psp
, uint32_t ta_cmd_id
)
897 * TODO: bypass the loading in sriov for now
899 if (amdgpu_sriov_vf(psp
->adev
))
902 return psp_ta_invoke(psp
, ta_cmd_id
, psp
->hdcp_context
.session_id
);
905 static int psp_hdcp_terminate(struct psp_context
*psp
)
910 * TODO: bypass the terminate in sriov for now
912 if (amdgpu_sriov_vf(psp
->adev
))
915 if (!psp
->hdcp_context
.hdcp_initialized
)
918 ret
= psp_hdcp_unload(psp
);
922 psp
->hdcp_context
.hdcp_initialized
= false;
924 /* free hdcp shared memory */
925 amdgpu_bo_free_kernel(&psp
->hdcp_context
.hdcp_shared_bo
,
926 &psp
->hdcp_context
.hdcp_shared_mc_addr
,
927 &psp
->hdcp_context
.hdcp_shared_buf
);
934 static int psp_dtm_init_shared_buf(struct psp_context
*psp
)
939 * Allocate 16k memory aligned to 4k from Frame Buffer (local
940 * physical) for dtm ta <-> Driver
942 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_DTM_SHARED_MEM_SIZE
,
943 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
944 &psp
->dtm_context
.dtm_shared_bo
,
945 &psp
->dtm_context
.dtm_shared_mc_addr
,
946 &psp
->dtm_context
.dtm_shared_buf
);
951 static int psp_dtm_load(struct psp_context
*psp
)
954 struct psp_gfx_cmd_resp
*cmd
;
957 * TODO: bypass the loading in sriov for now
959 if (amdgpu_sriov_vf(psp
->adev
))
962 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
966 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
967 memcpy(psp
->fw_pri_buf
, psp
->ta_dtm_start_addr
, psp
->ta_dtm_ucode_size
);
969 psp_prep_ta_load_cmd_buf(cmd
,
971 psp
->ta_dtm_ucode_size
,
972 psp
->dtm_context
.dtm_shared_mc_addr
,
973 PSP_DTM_SHARED_MEM_SIZE
);
975 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
, psp
->fence_buf_mc_addr
);
978 psp
->dtm_context
.dtm_initialized
= true;
979 psp
->dtm_context
.session_id
= cmd
->resp
.session_id
;
987 static int psp_dtm_initialize(struct psp_context
*psp
)
992 * TODO: bypass the initialize in sriov for now
994 if (amdgpu_sriov_vf(psp
->adev
))
997 if (!psp
->adev
->psp
.ta_dtm_ucode_size
||
998 !psp
->adev
->psp
.ta_dtm_start_addr
) {
999 dev_warn(psp
->adev
->dev
, "DTM: dtm ta ucode is not available\n");
1003 if (!psp
->dtm_context
.dtm_initialized
) {
1004 ret
= psp_dtm_init_shared_buf(psp
);
1009 ret
= psp_dtm_load(psp
);
1016 int psp_dtm_invoke(struct psp_context
*psp
, uint32_t ta_cmd_id
)
1019 * TODO: bypass the loading in sriov for now
1021 if (amdgpu_sriov_vf(psp
->adev
))
1024 return psp_ta_invoke(psp
, ta_cmd_id
, psp
->dtm_context
.session_id
);
1027 static int psp_dtm_terminate(struct psp_context
*psp
)
1032 * TODO: bypass the terminate in sriov for now
1034 if (amdgpu_sriov_vf(psp
->adev
))
1037 if (!psp
->dtm_context
.dtm_initialized
)
1040 ret
= psp_hdcp_unload(psp
);
1044 psp
->dtm_context
.dtm_initialized
= false;
1046 /* free hdcp shared memory */
1047 amdgpu_bo_free_kernel(&psp
->dtm_context
.dtm_shared_bo
,
1048 &psp
->dtm_context
.dtm_shared_mc_addr
,
1049 &psp
->dtm_context
.dtm_shared_buf
);
1055 static int psp_hw_start(struct psp_context
*psp
)
1057 struct amdgpu_device
*adev
= psp
->adev
;
1060 if (!amdgpu_sriov_vf(adev
) || !adev
->in_gpu_reset
) {
1061 if (psp
->kdb_bin_size
&&
1062 (psp
->funcs
->bootloader_load_kdb
!= NULL
)) {
1063 ret
= psp_bootloader_load_kdb(psp
);
1065 DRM_ERROR("PSP load kdb failed!\n");
1070 ret
= psp_bootloader_load_sysdrv(psp
);
1072 DRM_ERROR("PSP load sysdrv failed!\n");
1076 ret
= psp_bootloader_load_sos(psp
);
1078 DRM_ERROR("PSP load sos failed!\n");
1083 ret
= psp_ring_create(psp
, PSP_RING_TYPE__KM
);
1085 DRM_ERROR("PSP create ring failed!\n");
1089 ret
= psp_tmr_init(psp
);
1091 DRM_ERROR("PSP tmr init failed!\n");
1095 ret
= psp_tmr_load(psp
);
1097 DRM_ERROR("PSP load tmr failed!\n");
1104 static int psp_get_fw_type(struct amdgpu_firmware_info
*ucode
,
1105 enum psp_gfx_fw_type
*type
)
1107 switch (ucode
->ucode_id
) {
1108 case AMDGPU_UCODE_ID_SDMA0
:
1109 *type
= GFX_FW_TYPE_SDMA0
;
1111 case AMDGPU_UCODE_ID_SDMA1
:
1112 *type
= GFX_FW_TYPE_SDMA1
;
1114 case AMDGPU_UCODE_ID_SDMA2
:
1115 *type
= GFX_FW_TYPE_SDMA2
;
1117 case AMDGPU_UCODE_ID_SDMA3
:
1118 *type
= GFX_FW_TYPE_SDMA3
;
1120 case AMDGPU_UCODE_ID_SDMA4
:
1121 *type
= GFX_FW_TYPE_SDMA4
;
1123 case AMDGPU_UCODE_ID_SDMA5
:
1124 *type
= GFX_FW_TYPE_SDMA5
;
1126 case AMDGPU_UCODE_ID_SDMA6
:
1127 *type
= GFX_FW_TYPE_SDMA6
;
1129 case AMDGPU_UCODE_ID_SDMA7
:
1130 *type
= GFX_FW_TYPE_SDMA7
;
1132 case AMDGPU_UCODE_ID_CP_CE
:
1133 *type
= GFX_FW_TYPE_CP_CE
;
1135 case AMDGPU_UCODE_ID_CP_PFP
:
1136 *type
= GFX_FW_TYPE_CP_PFP
;
1138 case AMDGPU_UCODE_ID_CP_ME
:
1139 *type
= GFX_FW_TYPE_CP_ME
;
1141 case AMDGPU_UCODE_ID_CP_MEC1
:
1142 *type
= GFX_FW_TYPE_CP_MEC
;
1144 case AMDGPU_UCODE_ID_CP_MEC1_JT
:
1145 *type
= GFX_FW_TYPE_CP_MEC_ME1
;
1147 case AMDGPU_UCODE_ID_CP_MEC2
:
1148 *type
= GFX_FW_TYPE_CP_MEC
;
1150 case AMDGPU_UCODE_ID_CP_MEC2_JT
:
1151 *type
= GFX_FW_TYPE_CP_MEC_ME2
;
1153 case AMDGPU_UCODE_ID_RLC_G
:
1154 *type
= GFX_FW_TYPE_RLC_G
;
1156 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL
:
1157 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_CNTL
;
1159 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM
:
1160 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_GPM_MEM
;
1162 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM
:
1163 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_MEM
;
1165 case AMDGPU_UCODE_ID_SMC
:
1166 *type
= GFX_FW_TYPE_SMU
;
1168 case AMDGPU_UCODE_ID_UVD
:
1169 *type
= GFX_FW_TYPE_UVD
;
1171 case AMDGPU_UCODE_ID_UVD1
:
1172 *type
= GFX_FW_TYPE_UVD1
;
1174 case AMDGPU_UCODE_ID_VCE
:
1175 *type
= GFX_FW_TYPE_VCE
;
1177 case AMDGPU_UCODE_ID_VCN
:
1178 *type
= GFX_FW_TYPE_VCN
;
1180 case AMDGPU_UCODE_ID_VCN1
:
1181 *type
= GFX_FW_TYPE_VCN1
;
1183 case AMDGPU_UCODE_ID_DMCU_ERAM
:
1184 *type
= GFX_FW_TYPE_DMCU_ERAM
;
1186 case AMDGPU_UCODE_ID_DMCU_INTV
:
1187 *type
= GFX_FW_TYPE_DMCU_ISR
;
1189 case AMDGPU_UCODE_ID_VCN0_RAM
:
1190 *type
= GFX_FW_TYPE_VCN0_RAM
;
1192 case AMDGPU_UCODE_ID_VCN1_RAM
:
1193 *type
= GFX_FW_TYPE_VCN1_RAM
;
1195 case AMDGPU_UCODE_ID_DMCUB
:
1196 *type
= GFX_FW_TYPE_DMUB
;
1198 case AMDGPU_UCODE_ID_MAXIMUM
:
1206 static void psp_print_fw_hdr(struct psp_context
*psp
,
1207 struct amdgpu_firmware_info
*ucode
)
1209 struct amdgpu_device
*adev
= psp
->adev
;
1210 struct common_firmware_header
*hdr
;
1212 switch (ucode
->ucode_id
) {
1213 case AMDGPU_UCODE_ID_SDMA0
:
1214 case AMDGPU_UCODE_ID_SDMA1
:
1215 case AMDGPU_UCODE_ID_SDMA2
:
1216 case AMDGPU_UCODE_ID_SDMA3
:
1217 case AMDGPU_UCODE_ID_SDMA4
:
1218 case AMDGPU_UCODE_ID_SDMA5
:
1219 case AMDGPU_UCODE_ID_SDMA6
:
1220 case AMDGPU_UCODE_ID_SDMA7
:
1221 hdr
= (struct common_firmware_header
*)
1222 adev
->sdma
.instance
[ucode
->ucode_id
- AMDGPU_UCODE_ID_SDMA0
].fw
->data
;
1223 amdgpu_ucode_print_sdma_hdr(hdr
);
1225 case AMDGPU_UCODE_ID_CP_CE
:
1226 hdr
= (struct common_firmware_header
*)adev
->gfx
.ce_fw
->data
;
1227 amdgpu_ucode_print_gfx_hdr(hdr
);
1229 case AMDGPU_UCODE_ID_CP_PFP
:
1230 hdr
= (struct common_firmware_header
*)adev
->gfx
.pfp_fw
->data
;
1231 amdgpu_ucode_print_gfx_hdr(hdr
);
1233 case AMDGPU_UCODE_ID_CP_ME
:
1234 hdr
= (struct common_firmware_header
*)adev
->gfx
.me_fw
->data
;
1235 amdgpu_ucode_print_gfx_hdr(hdr
);
1237 case AMDGPU_UCODE_ID_CP_MEC1
:
1238 hdr
= (struct common_firmware_header
*)adev
->gfx
.mec_fw
->data
;
1239 amdgpu_ucode_print_gfx_hdr(hdr
);
1241 case AMDGPU_UCODE_ID_RLC_G
:
1242 hdr
= (struct common_firmware_header
*)adev
->gfx
.rlc_fw
->data
;
1243 amdgpu_ucode_print_rlc_hdr(hdr
);
1245 case AMDGPU_UCODE_ID_SMC
:
1246 hdr
= (struct common_firmware_header
*)adev
->pm
.fw
->data
;
1247 amdgpu_ucode_print_smc_hdr(hdr
);
1254 static int psp_prep_load_ip_fw_cmd_buf(struct amdgpu_firmware_info
*ucode
,
1255 struct psp_gfx_cmd_resp
*cmd
)
1258 uint64_t fw_mem_mc_addr
= ucode
->mc_addr
;
1260 memset(cmd
, 0, sizeof(struct psp_gfx_cmd_resp
));
1262 cmd
->cmd_id
= GFX_CMD_ID_LOAD_IP_FW
;
1263 cmd
->cmd
.cmd_load_ip_fw
.fw_phy_addr_lo
= lower_32_bits(fw_mem_mc_addr
);
1264 cmd
->cmd
.cmd_load_ip_fw
.fw_phy_addr_hi
= upper_32_bits(fw_mem_mc_addr
);
1265 cmd
->cmd
.cmd_load_ip_fw
.fw_size
= ucode
->ucode_size
;
1267 ret
= psp_get_fw_type(ucode
, &cmd
->cmd
.cmd_load_ip_fw
.fw_type
);
1269 DRM_ERROR("Unknown firmware type\n");
1274 static int psp_execute_np_fw_load(struct psp_context
*psp
,
1275 struct amdgpu_firmware_info
*ucode
)
1279 ret
= psp_prep_load_ip_fw_cmd_buf(ucode
, psp
->cmd
);
1283 ret
= psp_cmd_submit_buf(psp
, ucode
, psp
->cmd
,
1284 psp
->fence_buf_mc_addr
);
1289 static int psp_np_fw_load(struct psp_context
*psp
)
1292 struct amdgpu_firmware_info
*ucode
;
1293 struct amdgpu_device
* adev
= psp
->adev
;
1295 if (psp
->autoload_supported
) {
1296 ucode
= &adev
->firmware
.ucode
[AMDGPU_UCODE_ID_SMC
];
1300 ret
= psp_execute_np_fw_load(psp
, ucode
);
1306 for (i
= 0; i
< adev
->firmware
.max_ucodes
; i
++) {
1307 ucode
= &adev
->firmware
.ucode
[i
];
1311 if (ucode
->ucode_id
== AMDGPU_UCODE_ID_SMC
&&
1312 (psp_smu_reload_quirk(psp
) || psp
->autoload_supported
))
1315 if (amdgpu_sriov_vf(adev
) &&
1316 (ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA0
1317 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA1
1318 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA2
1319 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA3
1320 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA4
1321 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA5
1322 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA6
1323 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA7
1324 || ucode
->ucode_id
== AMDGPU_UCODE_ID_RLC_G
1325 || ucode
->ucode_id
== AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL
1326 || ucode
->ucode_id
== AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM
1327 || ucode
->ucode_id
== AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM
1328 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SMC
))
1329 /*skip ucode loading in SRIOV VF */
1332 if (psp
->autoload_supported
&&
1333 (ucode
->ucode_id
== AMDGPU_UCODE_ID_CP_MEC1_JT
||
1334 ucode
->ucode_id
== AMDGPU_UCODE_ID_CP_MEC2_JT
))
1335 /* skip mec JT when autoload is enabled */
1338 psp_print_fw_hdr(psp
, ucode
);
1340 ret
= psp_execute_np_fw_load(psp
, ucode
);
1344 /* Start rlc autoload after psp recieved all the gfx firmware */
1345 if (psp
->autoload_supported
&& ucode
->ucode_id
== (amdgpu_sriov_vf(adev
) ?
1346 AMDGPU_UCODE_ID_CP_MEC2
: AMDGPU_UCODE_ID_RLC_G
)) {
1347 ret
= psp_rlc_autoload(psp
);
1349 DRM_ERROR("Failed to start rlc autoload\n");
1354 /* check if firmware loaded sucessfully */
1355 if (!amdgpu_psp_check_fw_loading_status(adev
, i
))
1363 static int psp_load_fw(struct amdgpu_device
*adev
)
1366 struct psp_context
*psp
= &adev
->psp
;
1368 if (amdgpu_sriov_vf(adev
) && adev
->in_gpu_reset
) {
1369 psp_ring_stop(psp
, PSP_RING_TYPE__KM
); /* should not destroy ring, only stop */
1373 psp
->cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
1377 ret
= amdgpu_bo_create_kernel(adev
, PSP_1_MEG
, PSP_1_MEG
,
1378 AMDGPU_GEM_DOMAIN_GTT
,
1380 &psp
->fw_pri_mc_addr
,
1385 ret
= amdgpu_bo_create_kernel(adev
, PSP_FENCE_BUFFER_SIZE
, PAGE_SIZE
,
1386 AMDGPU_GEM_DOMAIN_VRAM
,
1388 &psp
->fence_buf_mc_addr
,
1393 ret
= amdgpu_bo_create_kernel(adev
, PSP_CMD_BUFFER_SIZE
, PAGE_SIZE
,
1394 AMDGPU_GEM_DOMAIN_VRAM
,
1395 &psp
->cmd_buf_bo
, &psp
->cmd_buf_mc_addr
,
1396 (void **)&psp
->cmd_buf_mem
);
1400 memset(psp
->fence_buf
, 0, PSP_FENCE_BUFFER_SIZE
);
1402 ret
= psp_ring_init(psp
, PSP_RING_TYPE__KM
);
1404 DRM_ERROR("PSP ring init failed!\n");
1409 ret
= psp_hw_start(psp
);
1413 ret
= psp_np_fw_load(psp
);
1417 ret
= psp_asd_load(psp
);
1419 DRM_ERROR("PSP load asd failed!\n");
1423 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
1424 ret
= psp_xgmi_initialize(psp
);
1425 /* Warning the XGMI seesion initialize failure
1426 * Instead of stop driver initialization
1429 dev_err(psp
->adev
->dev
,
1430 "XGMI: Failed to initialize XGMI session\n");
1433 if (psp
->adev
->psp
.ta_fw
) {
1434 ret
= psp_ras_initialize(psp
);
1436 dev_err(psp
->adev
->dev
,
1437 "RAS: Failed to initialize RAS\n");
1439 ret
= psp_hdcp_initialize(psp
);
1441 dev_err(psp
->adev
->dev
,
1442 "HDCP: Failed to initialize HDCP\n");
1444 ret
= psp_dtm_initialize(psp
);
1446 dev_err(psp
->adev
->dev
,
1447 "DTM: Failed to initialize DTM\n");
1454 * all cleanup jobs (xgmi terminate, ras terminate,
1455 * ring destroy, cmd/fence/fw buffers destory,
1456 * psp->cmd destory) are delayed to psp_hw_fini
1461 static int psp_hw_init(void *handle
)
1464 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1466 mutex_lock(&adev
->firmware
.mutex
);
1468 * This sequence is just used on hw_init only once, no need on
1471 ret
= amdgpu_ucode_init_bo(adev
);
1475 ret
= psp_load_fw(adev
);
1477 DRM_ERROR("PSP firmware loading failed\n");
1481 mutex_unlock(&adev
->firmware
.mutex
);
1485 adev
->firmware
.load_type
= AMDGPU_FW_LOAD_DIRECT
;
1486 mutex_unlock(&adev
->firmware
.mutex
);
1490 static int psp_hw_fini(void *handle
)
1492 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1493 struct psp_context
*psp
= &adev
->psp
;
1497 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1 &&
1498 psp
->xgmi_context
.initialized
== 1)
1499 psp_xgmi_terminate(psp
);
1501 if (psp
->adev
->psp
.ta_fw
) {
1502 psp_ras_terminate(psp
);
1503 psp_dtm_terminate(psp
);
1504 psp_hdcp_terminate(psp
);
1507 psp_asd_unload(psp
);
1509 psp_ring_destroy(psp
, PSP_RING_TYPE__KM
);
1511 pptr
= amdgpu_sriov_vf(psp
->adev
) ? &tmr_buf
: NULL
;
1512 amdgpu_bo_free_kernel(&psp
->tmr_bo
, &psp
->tmr_mc_addr
, pptr
);
1513 amdgpu_bo_free_kernel(&psp
->fw_pri_bo
,
1514 &psp
->fw_pri_mc_addr
, &psp
->fw_pri_buf
);
1515 amdgpu_bo_free_kernel(&psp
->fence_buf_bo
,
1516 &psp
->fence_buf_mc_addr
, &psp
->fence_buf
);
1517 amdgpu_bo_free_kernel(&psp
->cmd_buf_bo
, &psp
->cmd_buf_mc_addr
,
1518 (void **)&psp
->cmd_buf_mem
);
1526 static int psp_suspend(void *handle
)
1529 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1530 struct psp_context
*psp
= &adev
->psp
;
1532 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1 &&
1533 psp
->xgmi_context
.initialized
== 1) {
1534 ret
= psp_xgmi_terminate(psp
);
1536 DRM_ERROR("Failed to terminate xgmi ta\n");
1541 if (psp
->adev
->psp
.ta_fw
) {
1542 ret
= psp_ras_terminate(psp
);
1544 DRM_ERROR("Failed to terminate ras ta\n");
1547 ret
= psp_hdcp_terminate(psp
);
1549 DRM_ERROR("Failed to terminate hdcp ta\n");
1552 ret
= psp_dtm_terminate(psp
);
1554 DRM_ERROR("Failed to terminate dtm ta\n");
1559 ret
= psp_ring_stop(psp
, PSP_RING_TYPE__KM
);
1561 DRM_ERROR("PSP ring stop failed\n");
1568 static int psp_resume(void *handle
)
1571 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1572 struct psp_context
*psp
= &adev
->psp
;
1574 DRM_INFO("PSP is resuming...\n");
1576 ret
= psp_mem_training(psp
, PSP_MEM_TRAIN_RESUME
);
1578 DRM_ERROR("Failed to process memory training!\n");
1582 mutex_lock(&adev
->firmware
.mutex
);
1584 ret
= psp_hw_start(psp
);
1588 ret
= psp_np_fw_load(psp
);
1592 ret
= psp_asd_load(psp
);
1594 DRM_ERROR("PSP load asd failed!\n");
1598 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
1599 ret
= psp_xgmi_initialize(psp
);
1600 /* Warning the XGMI seesion initialize failure
1601 * Instead of stop driver initialization
1604 dev_err(psp
->adev
->dev
,
1605 "XGMI: Failed to initialize XGMI session\n");
1608 if (psp
->adev
->psp
.ta_fw
) {
1609 ret
= psp_ras_initialize(psp
);
1611 dev_err(psp
->adev
->dev
,
1612 "RAS: Failed to initialize RAS\n");
1614 ret
= psp_hdcp_initialize(psp
);
1616 dev_err(psp
->adev
->dev
,
1617 "HDCP: Failed to initialize HDCP\n");
1619 ret
= psp_dtm_initialize(psp
);
1621 dev_err(psp
->adev
->dev
,
1622 "DTM: Failed to initialize DTM\n");
1625 mutex_unlock(&adev
->firmware
.mutex
);
1630 DRM_ERROR("PSP resume failed\n");
1631 mutex_unlock(&adev
->firmware
.mutex
);
1635 int psp_gpu_reset(struct amdgpu_device
*adev
)
1639 if (adev
->firmware
.load_type
!= AMDGPU_FW_LOAD_PSP
)
1642 mutex_lock(&adev
->psp
.mutex
);
1643 ret
= psp_mode1_reset(&adev
->psp
);
1644 mutex_unlock(&adev
->psp
.mutex
);
1649 int psp_rlc_autoload_start(struct psp_context
*psp
)
1652 struct psp_gfx_cmd_resp
*cmd
;
1654 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
1658 cmd
->cmd_id
= GFX_CMD_ID_AUTOLOAD_RLC
;
1660 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
1661 psp
->fence_buf_mc_addr
);
1666 int psp_update_vcn_sram(struct amdgpu_device
*adev
, int inst_idx
,
1667 uint64_t cmd_gpu_addr
, int cmd_size
)
1669 struct amdgpu_firmware_info ucode
= {0};
1671 ucode
.ucode_id
= inst_idx
? AMDGPU_UCODE_ID_VCN1_RAM
:
1672 AMDGPU_UCODE_ID_VCN0_RAM
;
1673 ucode
.mc_addr
= cmd_gpu_addr
;
1674 ucode
.ucode_size
= cmd_size
;
1676 return psp_execute_np_fw_load(&adev
->psp
, &ucode
);
1679 int psp_ring_cmd_submit(struct psp_context
*psp
,
1680 uint64_t cmd_buf_mc_addr
,
1681 uint64_t fence_mc_addr
,
1684 unsigned int psp_write_ptr_reg
= 0;
1685 struct psp_gfx_rb_frame
*write_frame
;
1686 struct psp_ring
*ring
= &psp
->km_ring
;
1687 struct psp_gfx_rb_frame
*ring_buffer_start
= ring
->ring_mem
;
1688 struct psp_gfx_rb_frame
*ring_buffer_end
= ring_buffer_start
+
1689 ring
->ring_size
/ sizeof(struct psp_gfx_rb_frame
) - 1;
1690 struct amdgpu_device
*adev
= psp
->adev
;
1691 uint32_t ring_size_dw
= ring
->ring_size
/ 4;
1692 uint32_t rb_frame_size_dw
= sizeof(struct psp_gfx_rb_frame
) / 4;
1694 /* KM (GPCOM) prepare write pointer */
1695 psp_write_ptr_reg
= psp_ring_get_wptr(psp
);
1697 /* Update KM RB frame pointer to new frame */
1698 /* write_frame ptr increments by size of rb_frame in bytes */
1699 /* psp_write_ptr_reg increments by size of rb_frame in DWORDs */
1700 if ((psp_write_ptr_reg
% ring_size_dw
) == 0)
1701 write_frame
= ring_buffer_start
;
1703 write_frame
= ring_buffer_start
+ (psp_write_ptr_reg
/ rb_frame_size_dw
);
1704 /* Check invalid write_frame ptr address */
1705 if ((write_frame
< ring_buffer_start
) || (ring_buffer_end
< write_frame
)) {
1706 DRM_ERROR("ring_buffer_start = %p; ring_buffer_end = %p; write_frame = %p\n",
1707 ring_buffer_start
, ring_buffer_end
, write_frame
);
1708 DRM_ERROR("write_frame is pointing to address out of bounds\n");
1712 /* Initialize KM RB frame */
1713 memset(write_frame
, 0, sizeof(struct psp_gfx_rb_frame
));
1715 /* Update KM RB frame */
1716 write_frame
->cmd_buf_addr_hi
= upper_32_bits(cmd_buf_mc_addr
);
1717 write_frame
->cmd_buf_addr_lo
= lower_32_bits(cmd_buf_mc_addr
);
1718 write_frame
->fence_addr_hi
= upper_32_bits(fence_mc_addr
);
1719 write_frame
->fence_addr_lo
= lower_32_bits(fence_mc_addr
);
1720 write_frame
->fence_value
= index
;
1721 amdgpu_asic_flush_hdp(adev
, NULL
);
1723 /* Update the write Pointer in DWORDs */
1724 psp_write_ptr_reg
= (psp_write_ptr_reg
+ rb_frame_size_dw
) % ring_size_dw
;
1725 psp_ring_set_wptr(psp
, psp_write_ptr_reg
);
1729 static bool psp_check_fw_loading_status(struct amdgpu_device
*adev
,
1730 enum AMDGPU_UCODE_ID ucode_type
)
1732 struct amdgpu_firmware_info
*ucode
= NULL
;
1734 if (!adev
->firmware
.fw_size
)
1737 ucode
= &adev
->firmware
.ucode
[ucode_type
];
1738 if (!ucode
->fw
|| !ucode
->ucode_size
)
1741 return psp_compare_sram_data(&adev
->psp
, ucode
, ucode_type
);
1744 static int psp_set_clockgating_state(void *handle
,
1745 enum amd_clockgating_state state
)
1750 static int psp_set_powergating_state(void *handle
,
1751 enum amd_powergating_state state
)
1756 const struct amd_ip_funcs psp_ip_funcs
= {
1758 .early_init
= psp_early_init
,
1760 .sw_init
= psp_sw_init
,
1761 .sw_fini
= psp_sw_fini
,
1762 .hw_init
= psp_hw_init
,
1763 .hw_fini
= psp_hw_fini
,
1764 .suspend
= psp_suspend
,
1765 .resume
= psp_resume
,
1767 .check_soft_reset
= NULL
,
1768 .wait_for_idle
= NULL
,
1770 .set_clockgating_state
= psp_set_clockgating_state
,
1771 .set_powergating_state
= psp_set_powergating_state
,
1774 static const struct amdgpu_psp_funcs psp_funcs
= {
1775 .check_fw_loading_status
= psp_check_fw_loading_status
,
1778 static void psp_set_funcs(struct amdgpu_device
*adev
)
1780 if (NULL
== adev
->firmware
.funcs
)
1781 adev
->firmware
.funcs
= &psp_funcs
;
1784 const struct amdgpu_ip_block_version psp_v3_1_ip_block
=
1786 .type
= AMD_IP_BLOCK_TYPE_PSP
,
1790 .funcs
= &psp_ip_funcs
,
1793 const struct amdgpu_ip_block_version psp_v10_0_ip_block
=
1795 .type
= AMD_IP_BLOCK_TYPE_PSP
,
1799 .funcs
= &psp_ip_funcs
,
1802 const struct amdgpu_ip_block_version psp_v11_0_ip_block
=
1804 .type
= AMD_IP_BLOCK_TYPE_PSP
,
1808 .funcs
= &psp_ip_funcs
,
1811 const struct amdgpu_ip_block_version psp_v12_0_ip_block
=
1813 .type
= AMD_IP_BLOCK_TYPE_PSP
,
1817 .funcs
= &psp_ip_funcs
,