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"
36 static void psp_set_funcs(struct amdgpu_device
*adev
);
38 static int psp_early_init(void *handle
)
40 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
47 static int psp_sw_init(void *handle
)
49 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
50 struct psp_context
*psp
= &adev
->psp
;
53 switch (adev
->asic_type
) {
56 psp_v3_1_set_psp_funcs(psp
);
59 psp_v10_0_set_psp_funcs(psp
);
62 psp_v11_0_set_psp_funcs(psp
);
70 ret
= psp_init_microcode(psp
);
72 DRM_ERROR("Failed to load psp firmware!\n");
79 static int psp_sw_fini(void *handle
)
81 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
83 release_firmware(adev
->psp
.sos_fw
);
84 adev
->psp
.sos_fw
= NULL
;
85 release_firmware(adev
->psp
.asd_fw
);
86 adev
->psp
.asd_fw
= NULL
;
87 if (adev
->psp
.ta_fw
) {
88 release_firmware(adev
->psp
.ta_fw
);
89 adev
->psp
.ta_fw
= NULL
;
94 int psp_wait_for(struct psp_context
*psp
, uint32_t reg_index
,
95 uint32_t reg_val
, uint32_t mask
, bool check_changed
)
99 struct amdgpu_device
*adev
= psp
->adev
;
101 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
102 val
= RREG32(reg_index
);
107 if ((val
& mask
) == reg_val
)
117 psp_cmd_submit_buf(struct psp_context
*psp
,
118 struct amdgpu_firmware_info
*ucode
,
119 struct psp_gfx_cmd_resp
*cmd
, uint64_t fence_mc_addr
)
124 memset(psp
->cmd_buf_mem
, 0, PSP_CMD_BUFFER_SIZE
);
126 memcpy(psp
->cmd_buf_mem
, cmd
, sizeof(struct psp_gfx_cmd_resp
));
128 index
= atomic_inc_return(&psp
->fence_value
);
129 ret
= psp_cmd_submit(psp
, ucode
, psp
->cmd_buf_mc_addr
,
130 fence_mc_addr
, index
);
132 atomic_dec(&psp
->fence_value
);
136 while (*((unsigned int *)psp
->fence_buf
) != index
)
139 /* In some cases, psp response status is not 0 even there is no
140 * problem while the command is submitted. Some version of PSP FW
141 * doesn't write 0 to that field.
142 * So here we would like to only print a warning instead of an error
143 * during psp initialization to avoid breaking hw_init and it doesn't
146 if (psp
->cmd_buf_mem
->resp
.status
) {
148 DRM_WARN("failed to load ucode id (%d) ",
150 DRM_WARN("psp command failed and response status is (%d)\n",
151 psp
->cmd_buf_mem
->resp
.status
);
154 /* get xGMI session id from response buffer */
155 cmd
->resp
.session_id
= psp
->cmd_buf_mem
->resp
.session_id
;
158 ucode
->tmr_mc_addr_lo
= psp
->cmd_buf_mem
->resp
.fw_addr_lo
;
159 ucode
->tmr_mc_addr_hi
= psp
->cmd_buf_mem
->resp
.fw_addr_hi
;
165 static void psp_prep_tmr_cmd_buf(struct psp_context
*psp
,
166 struct psp_gfx_cmd_resp
*cmd
,
167 uint64_t tmr_mc
, uint32_t size
)
169 if (psp_support_vmr_ring(psp
))
170 cmd
->cmd_id
= GFX_CMD_ID_SETUP_VMR
;
172 cmd
->cmd_id
= GFX_CMD_ID_SETUP_TMR
;
173 cmd
->cmd
.cmd_setup_tmr
.buf_phy_addr_lo
= lower_32_bits(tmr_mc
);
174 cmd
->cmd
.cmd_setup_tmr
.buf_phy_addr_hi
= upper_32_bits(tmr_mc
);
175 cmd
->cmd
.cmd_setup_tmr
.buf_size
= size
;
178 /* Set up Trusted Memory Region */
179 static int psp_tmr_init(struct psp_context
*psp
)
184 * Allocate 3M memory aligned to 1M from Frame Buffer (local
187 * Note: this memory need be reserved till the driver
190 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_TMR_SIZE
, 0x100000,
191 AMDGPU_GEM_DOMAIN_VRAM
,
192 &psp
->tmr_bo
, &psp
->tmr_mc_addr
, &psp
->tmr_buf
);
197 static int psp_tmr_load(struct psp_context
*psp
)
200 struct psp_gfx_cmd_resp
*cmd
;
202 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
206 psp_prep_tmr_cmd_buf(psp
, cmd
, psp
->tmr_mc_addr
, PSP_TMR_SIZE
);
207 DRM_INFO("reserve 0x%x from 0x%llx for PSP TMR SIZE\n",
208 PSP_TMR_SIZE
, psp
->tmr_mc_addr
);
210 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
211 psp
->fence_buf_mc_addr
);
224 static void psp_prep_asd_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
225 uint64_t asd_mc
, uint64_t asd_mc_shared
,
226 uint32_t size
, uint32_t shared_size
)
228 cmd
->cmd_id
= GFX_CMD_ID_LOAD_ASD
;
229 cmd
->cmd
.cmd_load_ta
.app_phy_addr_lo
= lower_32_bits(asd_mc
);
230 cmd
->cmd
.cmd_load_ta
.app_phy_addr_hi
= upper_32_bits(asd_mc
);
231 cmd
->cmd
.cmd_load_ta
.app_len
= size
;
233 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_lo
= lower_32_bits(asd_mc_shared
);
234 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_hi
= upper_32_bits(asd_mc_shared
);
235 cmd
->cmd
.cmd_load_ta
.cmd_buf_len
= shared_size
;
238 static int psp_asd_init(struct psp_context
*psp
)
243 * Allocate 16k memory aligned to 4k from Frame Buffer (local
244 * physical) for shared ASD <-> Driver
246 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_ASD_SHARED_MEM_SIZE
,
247 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
249 &psp
->asd_shared_mc_addr
,
250 &psp
->asd_shared_buf
);
255 static int psp_asd_load(struct psp_context
*psp
)
258 struct psp_gfx_cmd_resp
*cmd
;
260 /* If PSP version doesn't match ASD version, asd loading will be failed.
261 * add workaround to bypass it for sriov now.
262 * TODO: add version check to make it common
264 if (amdgpu_sriov_vf(psp
->adev
))
267 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
271 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
272 memcpy(psp
->fw_pri_buf
, psp
->asd_start_addr
, psp
->asd_ucode_size
);
274 psp_prep_asd_cmd_buf(cmd
, psp
->fw_pri_mc_addr
, psp
->asd_shared_mc_addr
,
275 psp
->asd_ucode_size
, PSP_ASD_SHARED_MEM_SIZE
);
277 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
278 psp
->fence_buf_mc_addr
);
285 static void psp_prep_xgmi_ta_load_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
286 uint64_t xgmi_ta_mc
, uint64_t xgmi_mc_shared
,
287 uint32_t xgmi_ta_size
, uint32_t shared_size
)
289 cmd
->cmd_id
= GFX_CMD_ID_LOAD_TA
;
290 cmd
->cmd
.cmd_load_ta
.app_phy_addr_lo
= lower_32_bits(xgmi_ta_mc
);
291 cmd
->cmd
.cmd_load_ta
.app_phy_addr_hi
= upper_32_bits(xgmi_ta_mc
);
292 cmd
->cmd
.cmd_load_ta
.app_len
= xgmi_ta_size
;
294 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_lo
= lower_32_bits(xgmi_mc_shared
);
295 cmd
->cmd
.cmd_load_ta
.cmd_buf_phy_addr_hi
= upper_32_bits(xgmi_mc_shared
);
296 cmd
->cmd
.cmd_load_ta
.cmd_buf_len
= shared_size
;
299 static int psp_xgmi_init_shared_buf(struct psp_context
*psp
)
304 * Allocate 16k memory aligned to 4k from Frame Buffer (local
305 * physical) for xgmi ta <-> Driver
307 ret
= amdgpu_bo_create_kernel(psp
->adev
, PSP_XGMI_SHARED_MEM_SIZE
,
308 PAGE_SIZE
, AMDGPU_GEM_DOMAIN_VRAM
,
309 &psp
->xgmi_context
.xgmi_shared_bo
,
310 &psp
->xgmi_context
.xgmi_shared_mc_addr
,
311 &psp
->xgmi_context
.xgmi_shared_buf
);
316 static int psp_xgmi_load(struct psp_context
*psp
)
319 struct psp_gfx_cmd_resp
*cmd
;
322 * TODO: bypass the loading in sriov for now
324 if (amdgpu_sriov_vf(psp
->adev
))
327 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
331 memset(psp
->fw_pri_buf
, 0, PSP_1_MEG
);
332 memcpy(psp
->fw_pri_buf
, psp
->ta_xgmi_start_addr
, psp
->ta_xgmi_ucode_size
);
334 psp_prep_xgmi_ta_load_cmd_buf(cmd
, psp
->fw_pri_mc_addr
,
335 psp
->xgmi_context
.xgmi_shared_mc_addr
,
336 psp
->ta_xgmi_ucode_size
, PSP_XGMI_SHARED_MEM_SIZE
);
338 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
339 psp
->fence_buf_mc_addr
);
342 psp
->xgmi_context
.initialized
= 1;
343 psp
->xgmi_context
.session_id
= cmd
->resp
.session_id
;
351 static void psp_prep_xgmi_ta_unload_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
352 uint32_t xgmi_session_id
)
354 cmd
->cmd_id
= GFX_CMD_ID_UNLOAD_TA
;
355 cmd
->cmd
.cmd_unload_ta
.session_id
= xgmi_session_id
;
358 static int psp_xgmi_unload(struct psp_context
*psp
)
361 struct psp_gfx_cmd_resp
*cmd
;
364 * TODO: bypass the unloading in sriov for now
366 if (amdgpu_sriov_vf(psp
->adev
))
369 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
373 psp_prep_xgmi_ta_unload_cmd_buf(cmd
, psp
->xgmi_context
.session_id
);
375 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
376 psp
->fence_buf_mc_addr
);
383 static void psp_prep_xgmi_ta_invoke_cmd_buf(struct psp_gfx_cmd_resp
*cmd
,
385 uint32_t xgmi_session_id
)
387 cmd
->cmd_id
= GFX_CMD_ID_INVOKE_CMD
;
388 cmd
->cmd
.cmd_invoke_cmd
.session_id
= xgmi_session_id
;
389 cmd
->cmd
.cmd_invoke_cmd
.ta_cmd_id
= ta_cmd_id
;
390 /* Note: cmd_invoke_cmd.buf is not used for now */
393 int psp_xgmi_invoke(struct psp_context
*psp
, uint32_t ta_cmd_id
)
396 struct psp_gfx_cmd_resp
*cmd
;
399 * TODO: bypass the loading in sriov for now
401 if (amdgpu_sriov_vf(psp
->adev
))
404 cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
408 psp_prep_xgmi_ta_invoke_cmd_buf(cmd
, ta_cmd_id
,
409 psp
->xgmi_context
.session_id
);
411 ret
= psp_cmd_submit_buf(psp
, NULL
, cmd
,
412 psp
->fence_buf_mc_addr
);
419 static int psp_xgmi_terminate(struct psp_context
*psp
)
423 if (!psp
->xgmi_context
.initialized
)
426 ret
= psp_xgmi_unload(psp
);
430 psp
->xgmi_context
.initialized
= 0;
432 /* free xgmi shared memory */
433 amdgpu_bo_free_kernel(&psp
->xgmi_context
.xgmi_shared_bo
,
434 &psp
->xgmi_context
.xgmi_shared_mc_addr
,
435 &psp
->xgmi_context
.xgmi_shared_buf
);
440 static int psp_xgmi_initialize(struct psp_context
*psp
)
442 struct ta_xgmi_shared_memory
*xgmi_cmd
;
445 if (!psp
->adev
->psp
.ta_fw
)
448 if (!psp
->xgmi_context
.initialized
) {
449 ret
= psp_xgmi_init_shared_buf(psp
);
455 ret
= psp_xgmi_load(psp
);
459 /* Initialize XGMI session */
460 xgmi_cmd
= (struct ta_xgmi_shared_memory
*)(psp
->xgmi_context
.xgmi_shared_buf
);
461 memset(xgmi_cmd
, 0, sizeof(struct ta_xgmi_shared_memory
));
462 xgmi_cmd
->cmd_id
= TA_COMMAND_XGMI__INITIALIZE
;
464 ret
= psp_xgmi_invoke(psp
, xgmi_cmd
->cmd_id
);
469 static int psp_hw_start(struct psp_context
*psp
)
471 struct amdgpu_device
*adev
= psp
->adev
;
474 if (!amdgpu_sriov_vf(adev
) || !adev
->in_gpu_reset
) {
475 ret
= psp_bootloader_load_sysdrv(psp
);
479 ret
= psp_bootloader_load_sos(psp
);
484 ret
= psp_ring_create(psp
, PSP_RING_TYPE__KM
);
488 ret
= psp_tmr_load(psp
);
492 ret
= psp_asd_load(psp
);
496 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1) {
497 ret
= psp_xgmi_initialize(psp
);
498 /* Warning the XGMI seesion initialize failure
499 * Instead of stop driver initialization
502 dev_err(psp
->adev
->dev
,
503 "XGMI: Failed to initialize XGMI session\n");
508 static int psp_get_fw_type(struct amdgpu_firmware_info
*ucode
,
509 enum psp_gfx_fw_type
*type
)
511 switch (ucode
->ucode_id
) {
512 case AMDGPU_UCODE_ID_SDMA0
:
513 *type
= GFX_FW_TYPE_SDMA0
;
515 case AMDGPU_UCODE_ID_SDMA1
:
516 *type
= GFX_FW_TYPE_SDMA1
;
518 case AMDGPU_UCODE_ID_CP_CE
:
519 *type
= GFX_FW_TYPE_CP_CE
;
521 case AMDGPU_UCODE_ID_CP_PFP
:
522 *type
= GFX_FW_TYPE_CP_PFP
;
524 case AMDGPU_UCODE_ID_CP_ME
:
525 *type
= GFX_FW_TYPE_CP_ME
;
527 case AMDGPU_UCODE_ID_CP_MEC1
:
528 *type
= GFX_FW_TYPE_CP_MEC
;
530 case AMDGPU_UCODE_ID_CP_MEC1_JT
:
531 *type
= GFX_FW_TYPE_CP_MEC_ME1
;
533 case AMDGPU_UCODE_ID_CP_MEC2
:
534 *type
= GFX_FW_TYPE_CP_MEC
;
536 case AMDGPU_UCODE_ID_CP_MEC2_JT
:
537 *type
= GFX_FW_TYPE_CP_MEC_ME2
;
539 case AMDGPU_UCODE_ID_RLC_G
:
540 *type
= GFX_FW_TYPE_RLC_G
;
542 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL
:
543 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_CNTL
;
545 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM
:
546 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_GPM_MEM
;
548 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM
:
549 *type
= GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_MEM
;
551 case AMDGPU_UCODE_ID_SMC
:
552 *type
= GFX_FW_TYPE_SMU
;
554 case AMDGPU_UCODE_ID_UVD
:
555 *type
= GFX_FW_TYPE_UVD
;
557 case AMDGPU_UCODE_ID_UVD1
:
558 *type
= GFX_FW_TYPE_UVD1
;
560 case AMDGPU_UCODE_ID_VCE
:
561 *type
= GFX_FW_TYPE_VCE
;
563 case AMDGPU_UCODE_ID_VCN
:
564 *type
= GFX_FW_TYPE_VCN
;
566 case AMDGPU_UCODE_ID_DMCU_ERAM
:
567 *type
= GFX_FW_TYPE_DMCU_ERAM
;
569 case AMDGPU_UCODE_ID_DMCU_INTV
:
570 *type
= GFX_FW_TYPE_DMCU_ISR
;
572 case AMDGPU_UCODE_ID_MAXIMUM
:
580 static int psp_prep_load_ip_fw_cmd_buf(struct amdgpu_firmware_info
*ucode
,
581 struct psp_gfx_cmd_resp
*cmd
)
584 uint64_t fw_mem_mc_addr
= ucode
->mc_addr
;
586 memset(cmd
, 0, sizeof(struct psp_gfx_cmd_resp
));
588 cmd
->cmd_id
= GFX_CMD_ID_LOAD_IP_FW
;
589 cmd
->cmd
.cmd_load_ip_fw
.fw_phy_addr_lo
= lower_32_bits(fw_mem_mc_addr
);
590 cmd
->cmd
.cmd_load_ip_fw
.fw_phy_addr_hi
= upper_32_bits(fw_mem_mc_addr
);
591 cmd
->cmd
.cmd_load_ip_fw
.fw_size
= ucode
->ucode_size
;
593 ret
= psp_get_fw_type(ucode
, &cmd
->cmd
.cmd_load_ip_fw
.fw_type
);
595 DRM_ERROR("Unknown firmware type\n");
600 static int psp_np_fw_load(struct psp_context
*psp
)
603 struct amdgpu_firmware_info
*ucode
;
604 struct amdgpu_device
* adev
= psp
->adev
;
606 for (i
= 0; i
< adev
->firmware
.max_ucodes
; i
++) {
607 ucode
= &adev
->firmware
.ucode
[i
];
611 if (ucode
->ucode_id
== AMDGPU_UCODE_ID_SMC
&&
612 psp_smu_reload_quirk(psp
))
614 if (amdgpu_sriov_vf(adev
) &&
615 (ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA0
616 || ucode
->ucode_id
== AMDGPU_UCODE_ID_SDMA1
617 || ucode
->ucode_id
== AMDGPU_UCODE_ID_RLC_G
))
618 /*skip ucode loading in SRIOV VF */
621 ret
= psp_prep_load_ip_fw_cmd_buf(ucode
, psp
->cmd
);
625 ret
= psp_cmd_submit_buf(psp
, ucode
, psp
->cmd
,
626 psp
->fence_buf_mc_addr
);
631 /* check if firmware loaded sucessfully */
632 if (!amdgpu_psp_check_fw_loading_status(adev
, i
))
640 static int psp_load_fw(struct amdgpu_device
*adev
)
643 struct psp_context
*psp
= &adev
->psp
;
645 if (amdgpu_sriov_vf(adev
) && adev
->in_gpu_reset
) {
646 psp_ring_stop(psp
, PSP_RING_TYPE__KM
); /* should not destroy ring, only stop */
650 psp
->cmd
= kzalloc(sizeof(struct psp_gfx_cmd_resp
), GFP_KERNEL
);
654 ret
= amdgpu_bo_create_kernel(adev
, PSP_1_MEG
, PSP_1_MEG
,
655 AMDGPU_GEM_DOMAIN_GTT
,
657 &psp
->fw_pri_mc_addr
,
662 ret
= amdgpu_bo_create_kernel(adev
, PSP_FENCE_BUFFER_SIZE
, PAGE_SIZE
,
663 AMDGPU_GEM_DOMAIN_VRAM
,
665 &psp
->fence_buf_mc_addr
,
670 ret
= amdgpu_bo_create_kernel(adev
, PSP_CMD_BUFFER_SIZE
, PAGE_SIZE
,
671 AMDGPU_GEM_DOMAIN_VRAM
,
672 &psp
->cmd_buf_bo
, &psp
->cmd_buf_mc_addr
,
673 (void **)&psp
->cmd_buf_mem
);
677 memset(psp
->fence_buf
, 0, PSP_FENCE_BUFFER_SIZE
);
679 ret
= psp_ring_init(psp
, PSP_RING_TYPE__KM
);
683 ret
= psp_tmr_init(psp
);
687 ret
= psp_asd_init(psp
);
692 ret
= psp_hw_start(psp
);
696 ret
= psp_np_fw_load(psp
);
703 amdgpu_bo_free_kernel(&psp
->cmd_buf_bo
,
704 &psp
->cmd_buf_mc_addr
,
705 (void **)&psp
->cmd_buf_mem
);
707 amdgpu_bo_free_kernel(&psp
->fence_buf_bo
,
708 &psp
->fence_buf_mc_addr
, &psp
->fence_buf
);
710 amdgpu_bo_free_kernel(&psp
->fw_pri_bo
,
711 &psp
->fw_pri_mc_addr
, &psp
->fw_pri_buf
);
718 static int psp_hw_init(void *handle
)
721 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
723 mutex_lock(&adev
->firmware
.mutex
);
725 * This sequence is just used on hw_init only once, no need on
728 ret
= amdgpu_ucode_init_bo(adev
);
732 ret
= psp_load_fw(adev
);
734 DRM_ERROR("PSP firmware loading failed\n");
738 mutex_unlock(&adev
->firmware
.mutex
);
742 adev
->firmware
.load_type
= AMDGPU_FW_LOAD_DIRECT
;
743 mutex_unlock(&adev
->firmware
.mutex
);
747 static int psp_hw_fini(void *handle
)
749 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
750 struct psp_context
*psp
= &adev
->psp
;
752 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1 &&
753 psp
->xgmi_context
.initialized
== 1)
754 psp_xgmi_terminate(psp
);
756 psp_ring_destroy(psp
, PSP_RING_TYPE__KM
);
758 amdgpu_bo_free_kernel(&psp
->tmr_bo
, &psp
->tmr_mc_addr
, &psp
->tmr_buf
);
759 amdgpu_bo_free_kernel(&psp
->fw_pri_bo
,
760 &psp
->fw_pri_mc_addr
, &psp
->fw_pri_buf
);
761 amdgpu_bo_free_kernel(&psp
->fence_buf_bo
,
762 &psp
->fence_buf_mc_addr
, &psp
->fence_buf
);
763 amdgpu_bo_free_kernel(&psp
->asd_shared_bo
, &psp
->asd_shared_mc_addr
,
764 &psp
->asd_shared_buf
);
765 amdgpu_bo_free_kernel(&psp
->cmd_buf_bo
, &psp
->cmd_buf_mc_addr
,
766 (void **)&psp
->cmd_buf_mem
);
774 static int psp_suspend(void *handle
)
777 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
778 struct psp_context
*psp
= &adev
->psp
;
780 if (adev
->gmc
.xgmi
.num_physical_nodes
> 1 &&
781 psp
->xgmi_context
.initialized
== 1) {
782 ret
= psp_xgmi_terminate(psp
);
784 DRM_ERROR("Failed to terminate xgmi ta\n");
789 ret
= psp_ring_stop(psp
, PSP_RING_TYPE__KM
);
791 DRM_ERROR("PSP ring stop failed\n");
798 static int psp_resume(void *handle
)
801 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
802 struct psp_context
*psp
= &adev
->psp
;
804 DRM_INFO("PSP is resuming...\n");
806 mutex_lock(&adev
->firmware
.mutex
);
808 ret
= psp_hw_start(psp
);
812 ret
= psp_np_fw_load(psp
);
816 mutex_unlock(&adev
->firmware
.mutex
);
821 DRM_ERROR("PSP resume failed\n");
822 mutex_unlock(&adev
->firmware
.mutex
);
826 int psp_gpu_reset(struct amdgpu_device
*adev
)
828 if (adev
->firmware
.load_type
!= AMDGPU_FW_LOAD_PSP
)
831 return psp_mode1_reset(&adev
->psp
);
834 static bool psp_check_fw_loading_status(struct amdgpu_device
*adev
,
835 enum AMDGPU_UCODE_ID ucode_type
)
837 struct amdgpu_firmware_info
*ucode
= NULL
;
839 if (!adev
->firmware
.fw_size
)
842 ucode
= &adev
->firmware
.ucode
[ucode_type
];
843 if (!ucode
->fw
|| !ucode
->ucode_size
)
846 return psp_compare_sram_data(&adev
->psp
, ucode
, ucode_type
);
849 static int psp_set_clockgating_state(void *handle
,
850 enum amd_clockgating_state state
)
855 static int psp_set_powergating_state(void *handle
,
856 enum amd_powergating_state state
)
861 const struct amd_ip_funcs psp_ip_funcs
= {
863 .early_init
= psp_early_init
,
865 .sw_init
= psp_sw_init
,
866 .sw_fini
= psp_sw_fini
,
867 .hw_init
= psp_hw_init
,
868 .hw_fini
= psp_hw_fini
,
869 .suspend
= psp_suspend
,
870 .resume
= psp_resume
,
872 .check_soft_reset
= NULL
,
873 .wait_for_idle
= NULL
,
875 .set_clockgating_state
= psp_set_clockgating_state
,
876 .set_powergating_state
= psp_set_powergating_state
,
879 static const struct amdgpu_psp_funcs psp_funcs
= {
880 .check_fw_loading_status
= psp_check_fw_loading_status
,
883 static void psp_set_funcs(struct amdgpu_device
*adev
)
885 if (NULL
== adev
->firmware
.funcs
)
886 adev
->firmware
.funcs
= &psp_funcs
;
889 const struct amdgpu_ip_block_version psp_v3_1_ip_block
=
891 .type
= AMD_IP_BLOCK_TYPE_PSP
,
895 .funcs
= &psp_ip_funcs
,
898 const struct amdgpu_ip_block_version psp_v10_0_ip_block
=
900 .type
= AMD_IP_BLOCK_TYPE_PSP
,
904 .funcs
= &psp_ip_funcs
,
907 const struct amdgpu_ip_block_version psp_v11_0_ip_block
=
909 .type
= AMD_IP_BLOCK_TYPE_PSP
,
913 .funcs
= &psp_ip_funcs
,