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>
27 #include <linux/dma-mapping.h>
30 #include "amdgpu_psp.h"
31 #include "amdgpu_ucode.h"
32 #include "soc15_common.h"
34 #include "psp_v10_0.h"
35 #include "psp_v11_0.h"
36 #include "psp_v12_0.h"
37 #include "psp_v13_0.h"
39 #include "amdgpu_ras.h"
40 #include "amdgpu_securedisplay.h"
41 #include "amdgpu_atomfirmware.h"
43 static int psp_sysfs_init(struct amdgpu_device *adev);
44 static void psp_sysfs_fini(struct amdgpu_device *adev);
46 static int psp_load_smu_fw(struct psp_context *psp);
49 * Due to DF Cstate management centralized to PMFW, the firmware
50 * loading sequence will be updated as below:
56 * - Load other non-psp fw
58 * - Load XGMI/RAS/HDCP/DTM TA if any
60 * This new sequence is required for
61 * - Arcturus and onwards
62 * - Navi12 and onwards
64 static void psp_check_pmfw_centralized_cstate_management(struct psp_context *psp)
66 struct amdgpu_device *adev = psp->adev;
68 psp->pmfw_centralized_cstate_management = false;
70 if (amdgpu_sriov_vf(adev))
73 if (adev->flags & AMD_IS_APU)
76 if ((adev->asic_type >= CHIP_ARCTURUS) ||
77 (adev->asic_type >= CHIP_NAVI12))
78 psp->pmfw_centralized_cstate_management = true;
81 static int psp_early_init(void *handle)
83 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
84 struct psp_context *psp = &adev->psp;
86 switch (adev->asic_type) {
89 psp_v3_1_set_psp_funcs(psp);
90 psp->autoload_supported = false;
93 psp_v10_0_set_psp_funcs(psp);
94 psp->autoload_supported = false;
98 psp_v11_0_set_psp_funcs(psp);
99 psp->autoload_supported = false;
104 case CHIP_SIENNA_CICHLID:
105 case CHIP_NAVY_FLOUNDER:
107 case CHIP_DIMGREY_CAVEFISH:
108 case CHIP_BEIGE_GOBY:
109 psp_v11_0_set_psp_funcs(psp);
110 psp->autoload_supported = true;
113 psp_v12_0_set_psp_funcs(psp);
116 psp_v13_0_set_psp_funcs(psp);
124 psp_check_pmfw_centralized_cstate_management(psp);
129 static void psp_memory_training_fini(struct psp_context *psp)
131 struct psp_memory_training_context *ctx = &psp->mem_train_ctx;
133 ctx->init = PSP_MEM_TRAIN_NOT_SUPPORT;
134 kfree(ctx->sys_cache);
135 ctx->sys_cache = NULL;
138 static int psp_memory_training_init(struct psp_context *psp)
141 struct psp_memory_training_context *ctx = &psp->mem_train_ctx;
143 if (ctx->init != PSP_MEM_TRAIN_RESERVE_SUCCESS) {
144 DRM_DEBUG("memory training is not supported!\n");
148 ctx->sys_cache = kzalloc(ctx->train_data_size, GFP_KERNEL);
149 if (ctx->sys_cache == NULL) {
150 DRM_ERROR("alloc mem_train_ctx.sys_cache failed!\n");
155 DRM_DEBUG("train_data_size:%llx,p2c_train_data_offset:%llx,c2p_train_data_offset:%llx.\n",
156 ctx->train_data_size,
157 ctx->p2c_train_data_offset,
158 ctx->c2p_train_data_offset);
159 ctx->init = PSP_MEM_TRAIN_INIT_SUCCESS;
163 psp_memory_training_fini(psp);
167 static int psp_sw_init(void *handle)
169 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
170 struct psp_context *psp = &adev->psp;
173 if (!amdgpu_sriov_vf(adev)) {
174 ret = psp_init_microcode(psp);
176 DRM_ERROR("Failed to load psp firmware!\n");
181 ret = psp_memory_training_init(psp);
183 DRM_ERROR("Failed to initialize memory training!\n");
186 ret = psp_mem_training(psp, PSP_MEM_TRAIN_COLD_BOOT);
188 DRM_ERROR("Failed to process memory training!\n");
192 if (adev->asic_type == CHIP_NAVI10 || adev->asic_type == CHIP_SIENNA_CICHLID) {
193 ret= psp_sysfs_init(adev);
202 static int psp_sw_fini(void *handle)
204 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
206 psp_memory_training_fini(&adev->psp);
207 if (adev->psp.sos_fw) {
208 release_firmware(adev->psp.sos_fw);
209 adev->psp.sos_fw = NULL;
211 if (adev->psp.asd_fw) {
212 release_firmware(adev->psp.asd_fw);
213 adev->psp.asd_fw = NULL;
215 if (adev->psp.ta_fw) {
216 release_firmware(adev->psp.ta_fw);
217 adev->psp.ta_fw = NULL;
220 if (adev->asic_type == CHIP_NAVI10 ||
221 adev->asic_type == CHIP_SIENNA_CICHLID)
222 psp_sysfs_fini(adev);
227 int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
228 uint32_t reg_val, uint32_t mask, bool check_changed)
232 struct amdgpu_device *adev = psp->adev;
234 if (psp->adev->in_pci_err_recovery)
237 for (i = 0; i < adev->usec_timeout; i++) {
238 val = RREG32(reg_index);
243 if ((val & mask) == reg_val)
253 psp_cmd_submit_buf(struct psp_context *psp,
254 struct amdgpu_firmware_info *ucode,
255 struct psp_gfx_cmd_resp *cmd, uint64_t fence_mc_addr)
260 bool ras_intr = false;
261 bool skip_unsupport = false;
263 if (psp->adev->in_pci_err_recovery)
266 mutex_lock(&psp->mutex);
268 memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
270 memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
272 index = atomic_inc_return(&psp->fence_value);
273 ret = psp_ring_cmd_submit(psp, psp->cmd_buf_mc_addr, fence_mc_addr, index);
275 atomic_dec(&psp->fence_value);
276 mutex_unlock(&psp->mutex);
280 amdgpu_asic_invalidate_hdp(psp->adev, NULL);
281 while (*((unsigned int *)psp->fence_buf) != index) {
285 * Shouldn't wait for timeout when err_event_athub occurs,
286 * because gpu reset thread triggered and lock resource should
287 * be released for psp resume sequence.
289 ras_intr = amdgpu_ras_intr_triggered();
292 usleep_range(10, 100);
293 amdgpu_asic_invalidate_hdp(psp->adev, NULL);
296 /* We allow TEE_ERROR_NOT_SUPPORTED for VMR command and PSP_ERR_UNKNOWN_COMMAND in SRIOV */
297 skip_unsupport = (psp->cmd_buf_mem->resp.status == TEE_ERROR_NOT_SUPPORTED ||
298 psp->cmd_buf_mem->resp.status == PSP_ERR_UNKNOWN_COMMAND) && amdgpu_sriov_vf(psp->adev);
300 memcpy((void*)&cmd->resp, (void*)&psp->cmd_buf_mem->resp, sizeof(struct psp_gfx_resp));
302 /* In some cases, psp response status is not 0 even there is no
303 * problem while the command is submitted. Some version of PSP FW
304 * doesn't write 0 to that field.
305 * So here we would like to only print a warning instead of an error
306 * during psp initialization to avoid breaking hw_init and it doesn't
309 if (!skip_unsupport && (psp->cmd_buf_mem->resp.status || !timeout) && !ras_intr) {
311 DRM_WARN("failed to load ucode id (%d) ",
313 DRM_WARN("psp command (0x%X) failed and response status is (0x%X)\n",
314 psp->cmd_buf_mem->cmd_id,
315 psp->cmd_buf_mem->resp.status);
317 mutex_unlock(&psp->mutex);
323 ucode->tmr_mc_addr_lo = psp->cmd_buf_mem->resp.fw_addr_lo;
324 ucode->tmr_mc_addr_hi = psp->cmd_buf_mem->resp.fw_addr_hi;
326 mutex_unlock(&psp->mutex);
331 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
332 struct psp_gfx_cmd_resp *cmd,
333 uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
335 struct amdgpu_device *adev = psp->adev;
336 uint32_t size = amdgpu_bo_size(tmr_bo);
337 uint64_t tmr_pa = amdgpu_gmc_vram_pa(adev, tmr_bo);
339 if (amdgpu_sriov_vf(psp->adev))
340 cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
342 cmd->cmd_id = GFX_CMD_ID_SETUP_TMR;
343 cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
344 cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
345 cmd->cmd.cmd_setup_tmr.buf_size = size;
346 cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
347 cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
348 cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
351 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
352 uint64_t pri_buf_mc, uint32_t size)
354 cmd->cmd_id = GFX_CMD_ID_LOAD_TOC;
355 cmd->cmd.cmd_load_toc.toc_phy_addr_lo = lower_32_bits(pri_buf_mc);
356 cmd->cmd.cmd_load_toc.toc_phy_addr_hi = upper_32_bits(pri_buf_mc);
357 cmd->cmd.cmd_load_toc.toc_size = size;
360 /* Issue LOAD TOC cmd to PSP to part toc and calculate tmr size needed */
361 static int psp_load_toc(struct psp_context *psp,
365 struct psp_gfx_cmd_resp *cmd;
367 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
370 /* Copy toc to psp firmware private buffer */
371 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
372 memcpy(psp->fw_pri_buf, psp->toc_start_addr, psp->toc_bin_size);
374 psp_prep_load_toc_cmd_buf(cmd, psp->fw_pri_mc_addr, psp->toc_bin_size);
376 ret = psp_cmd_submit_buf(psp, NULL, cmd,
377 psp->fence_buf_mc_addr);
379 *tmr_size = psp->cmd_buf_mem->resp.tmr_size;
384 /* Set up Trusted Memory Region */
385 static int psp_tmr_init(struct psp_context *psp)
393 * According to HW engineer, they prefer the TMR address be "naturally
394 * aligned" , e.g. the start address be an integer divide of TMR size.
396 * Note: this memory need be reserved till the driver
399 tmr_size = PSP_TMR_SIZE(psp->adev);
401 /* For ASICs support RLC autoload, psp will parse the toc
402 * and calculate the total size of TMR needed */
403 if (!amdgpu_sriov_vf(psp->adev) &&
404 psp->toc_start_addr &&
407 ret = psp_load_toc(psp, &tmr_size);
409 DRM_ERROR("Failed to load toc\n");
414 pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
415 ret = amdgpu_bo_create_kernel(psp->adev, tmr_size, PSP_TMR_SIZE(psp->adev),
416 AMDGPU_GEM_DOMAIN_VRAM,
417 &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
422 static bool psp_skip_tmr(struct psp_context *psp)
424 switch (psp->adev->asic_type) {
426 case CHIP_SIENNA_CICHLID:
434 static int psp_tmr_load(struct psp_context *psp)
437 struct psp_gfx_cmd_resp *cmd;
439 /* For Navi12 and CHIP_SIENNA_CICHLID SRIOV, do not set up TMR.
440 * Already set up by host driver.
442 if (amdgpu_sriov_vf(psp->adev) && psp_skip_tmr(psp))
445 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
449 psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
450 DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
451 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
453 ret = psp_cmd_submit_buf(psp, NULL, cmd,
454 psp->fence_buf_mc_addr);
461 static void psp_prep_tmr_unload_cmd_buf(struct psp_context *psp,
462 struct psp_gfx_cmd_resp *cmd)
464 if (amdgpu_sriov_vf(psp->adev))
465 cmd->cmd_id = GFX_CMD_ID_DESTROY_VMR;
467 cmd->cmd_id = GFX_CMD_ID_DESTROY_TMR;
470 static int psp_tmr_unload(struct psp_context *psp)
473 struct psp_gfx_cmd_resp *cmd;
475 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
479 psp_prep_tmr_unload_cmd_buf(psp, cmd);
480 DRM_INFO("free PSP TMR buffer\n");
482 ret = psp_cmd_submit_buf(psp, NULL, cmd,
483 psp->fence_buf_mc_addr);
490 static int psp_tmr_terminate(struct psp_context *psp)
496 ret = psp_tmr_unload(psp);
500 /* free TMR memory buffer */
501 pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
502 amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
507 int psp_get_fw_attestation_records_addr(struct psp_context *psp,
508 uint64_t *output_ptr)
511 struct psp_gfx_cmd_resp *cmd;
516 if (amdgpu_sriov_vf(psp->adev))
519 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
523 cmd->cmd_id = GFX_CMD_ID_GET_FW_ATTESTATION;
525 ret = psp_cmd_submit_buf(psp, NULL, cmd,
526 psp->fence_buf_mc_addr);
529 *output_ptr = ((uint64_t)cmd->resp.uresp.fwar_db_info.fwar_db_addr_lo) +
530 ((uint64_t)cmd->resp.uresp.fwar_db_info.fwar_db_addr_hi << 32);
538 static int psp_boot_config_set(struct amdgpu_device *adev)
540 struct psp_context *psp = &adev->psp;
541 struct psp_gfx_cmd_resp *cmd = psp->cmd;
543 if (amdgpu_sriov_vf(adev))
546 memset(cmd, 0, sizeof(struct psp_gfx_cmd_resp));
548 cmd->cmd_id = GFX_CMD_ID_BOOT_CFG;
549 cmd->cmd.boot_cfg.sub_cmd = BOOTCFG_CMD_SET;
550 cmd->cmd.boot_cfg.boot_config = BOOT_CONFIG_GECC;
551 cmd->cmd.boot_cfg.boot_config_valid = BOOT_CONFIG_GECC;
553 return psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
556 static int psp_rl_load(struct amdgpu_device *adev)
558 struct psp_context *psp = &adev->psp;
559 struct psp_gfx_cmd_resp *cmd = psp->cmd;
561 if (psp->rl_bin_size == 0)
564 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
565 memcpy(psp->fw_pri_buf, psp->rl_start_addr, psp->rl_bin_size);
567 memset(cmd, 0, sizeof(struct psp_gfx_cmd_resp));
569 cmd->cmd_id = GFX_CMD_ID_LOAD_IP_FW;
570 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_lo = lower_32_bits(psp->fw_pri_mc_addr);
571 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_hi = upper_32_bits(psp->fw_pri_mc_addr);
572 cmd->cmd.cmd_load_ip_fw.fw_size = psp->rl_bin_size;
573 cmd->cmd.cmd_load_ip_fw.fw_type = GFX_FW_TYPE_REG_LIST;
575 return psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
578 static void psp_prep_asd_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
579 uint64_t asd_mc, uint32_t size)
581 cmd->cmd_id = GFX_CMD_ID_LOAD_ASD;
582 cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(asd_mc);
583 cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(asd_mc);
584 cmd->cmd.cmd_load_ta.app_len = size;
586 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = 0;
587 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = 0;
588 cmd->cmd.cmd_load_ta.cmd_buf_len = 0;
591 static int psp_asd_load(struct psp_context *psp)
594 struct psp_gfx_cmd_resp *cmd;
596 /* If PSP version doesn't match ASD version, asd loading will be failed.
597 * add workaround to bypass it for sriov now.
598 * TODO: add version check to make it common
600 if (amdgpu_sriov_vf(psp->adev) || !psp->asd_ucode_size)
603 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
607 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
608 memcpy(psp->fw_pri_buf, psp->asd_start_addr, psp->asd_ucode_size);
610 psp_prep_asd_load_cmd_buf(cmd, psp->fw_pri_mc_addr,
611 psp->asd_ucode_size);
613 ret = psp_cmd_submit_buf(psp, NULL, cmd,
614 psp->fence_buf_mc_addr);
616 psp->asd_context.asd_initialized = true;
617 psp->asd_context.session_id = cmd->resp.session_id;
625 static void psp_prep_ta_unload_cmd_buf(struct psp_gfx_cmd_resp *cmd,
628 cmd->cmd_id = GFX_CMD_ID_UNLOAD_TA;
629 cmd->cmd.cmd_unload_ta.session_id = session_id;
632 static int psp_asd_unload(struct psp_context *psp)
635 struct psp_gfx_cmd_resp *cmd;
637 if (amdgpu_sriov_vf(psp->adev))
640 if (!psp->asd_context.asd_initialized)
643 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
647 psp_prep_ta_unload_cmd_buf(cmd, psp->asd_context.session_id);
649 ret = psp_cmd_submit_buf(psp, NULL, cmd,
650 psp->fence_buf_mc_addr);
652 psp->asd_context.asd_initialized = false;
659 static void psp_prep_reg_prog_cmd_buf(struct psp_gfx_cmd_resp *cmd,
660 uint32_t id, uint32_t value)
662 cmd->cmd_id = GFX_CMD_ID_PROG_REG;
663 cmd->cmd.cmd_setup_reg_prog.reg_value = value;
664 cmd->cmd.cmd_setup_reg_prog.reg_id = id;
667 int psp_reg_program(struct psp_context *psp, enum psp_reg_prog_id reg,
670 struct psp_gfx_cmd_resp *cmd = NULL;
673 if (reg >= PSP_REG_LAST)
676 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
680 psp_prep_reg_prog_cmd_buf(cmd, reg, value);
681 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
687 static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
689 uint32_t ta_bin_size,
690 uint64_t ta_shared_mc,
691 uint32_t ta_shared_size)
693 cmd->cmd_id = GFX_CMD_ID_LOAD_TA;
694 cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(ta_bin_mc);
695 cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(ta_bin_mc);
696 cmd->cmd.cmd_load_ta.app_len = ta_bin_size;
698 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = lower_32_bits(ta_shared_mc);
699 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = upper_32_bits(ta_shared_mc);
700 cmd->cmd.cmd_load_ta.cmd_buf_len = ta_shared_size;
703 static int psp_xgmi_init_shared_buf(struct psp_context *psp)
708 * Allocate 16k memory aligned to 4k from Frame Buffer (local
709 * physical) for xgmi ta <-> Driver
711 ret = amdgpu_bo_create_kernel(psp->adev, PSP_XGMI_SHARED_MEM_SIZE,
712 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
713 &psp->xgmi_context.xgmi_shared_bo,
714 &psp->xgmi_context.xgmi_shared_mc_addr,
715 &psp->xgmi_context.xgmi_shared_buf);
720 static void psp_prep_ta_invoke_cmd_buf(struct psp_gfx_cmd_resp *cmd,
724 cmd->cmd_id = GFX_CMD_ID_INVOKE_CMD;
725 cmd->cmd.cmd_invoke_cmd.session_id = session_id;
726 cmd->cmd.cmd_invoke_cmd.ta_cmd_id = ta_cmd_id;
729 static int psp_ta_invoke(struct psp_context *psp,
734 struct psp_gfx_cmd_resp *cmd;
736 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
740 psp_prep_ta_invoke_cmd_buf(cmd, ta_cmd_id, session_id);
742 ret = psp_cmd_submit_buf(psp, NULL, cmd,
743 psp->fence_buf_mc_addr);
750 static int psp_xgmi_load(struct psp_context *psp)
753 struct psp_gfx_cmd_resp *cmd;
756 * TODO: bypass the loading in sriov for now
759 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
763 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
764 memcpy(psp->fw_pri_buf, psp->ta_xgmi_start_addr, psp->ta_xgmi_ucode_size);
766 psp_prep_ta_load_cmd_buf(cmd,
768 psp->ta_xgmi_ucode_size,
769 psp->xgmi_context.xgmi_shared_mc_addr,
770 PSP_XGMI_SHARED_MEM_SIZE);
772 ret = psp_cmd_submit_buf(psp, NULL, cmd,
773 psp->fence_buf_mc_addr);
776 psp->xgmi_context.initialized = 1;
777 psp->xgmi_context.session_id = cmd->resp.session_id;
785 static int psp_xgmi_unload(struct psp_context *psp)
788 struct psp_gfx_cmd_resp *cmd;
789 struct amdgpu_device *adev = psp->adev;
791 /* XGMI TA unload currently is not supported on Arcturus/Aldebaran A+A */
792 if (adev->asic_type == CHIP_ARCTURUS ||
793 (adev->asic_type == CHIP_ALDEBARAN && adev->gmc.xgmi.connected_to_cpu))
797 * TODO: bypass the unloading in sriov for now
800 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
804 psp_prep_ta_unload_cmd_buf(cmd, psp->xgmi_context.session_id);
806 ret = psp_cmd_submit_buf(psp, NULL, cmd,
807 psp->fence_buf_mc_addr);
814 int psp_xgmi_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
816 return psp_ta_invoke(psp, ta_cmd_id, psp->xgmi_context.session_id);
819 int psp_xgmi_terminate(struct psp_context *psp)
823 if (!psp->xgmi_context.initialized)
826 ret = psp_xgmi_unload(psp);
830 psp->xgmi_context.initialized = 0;
832 /* free xgmi shared memory */
833 amdgpu_bo_free_kernel(&psp->xgmi_context.xgmi_shared_bo,
834 &psp->xgmi_context.xgmi_shared_mc_addr,
835 &psp->xgmi_context.xgmi_shared_buf);
840 int psp_xgmi_initialize(struct psp_context *psp)
842 struct ta_xgmi_shared_memory *xgmi_cmd;
845 if (!psp->adev->psp.ta_fw ||
846 !psp->adev->psp.ta_xgmi_ucode_size ||
847 !psp->adev->psp.ta_xgmi_start_addr)
850 if (!psp->xgmi_context.initialized) {
851 ret = psp_xgmi_init_shared_buf(psp);
857 ret = psp_xgmi_load(psp);
861 /* Initialize XGMI session */
862 xgmi_cmd = (struct ta_xgmi_shared_memory *)(psp->xgmi_context.xgmi_shared_buf);
863 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
864 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__INITIALIZE;
866 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
871 int psp_xgmi_get_hive_id(struct psp_context *psp, uint64_t *hive_id)
873 struct ta_xgmi_shared_memory *xgmi_cmd;
876 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.xgmi_shared_buf;
877 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
879 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_HIVE_ID;
881 /* Invoke xgmi ta to get hive id */
882 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
886 *hive_id = xgmi_cmd->xgmi_out_message.get_hive_id.hive_id;
891 int psp_xgmi_get_node_id(struct psp_context *psp, uint64_t *node_id)
893 struct ta_xgmi_shared_memory *xgmi_cmd;
896 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.xgmi_shared_buf;
897 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
899 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_NODE_ID;
901 /* Invoke xgmi ta to get the node id */
902 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
906 *node_id = xgmi_cmd->xgmi_out_message.get_node_id.node_id;
911 int psp_xgmi_get_topology_info(struct psp_context *psp,
913 struct psp_xgmi_topology_info *topology)
915 struct ta_xgmi_shared_memory *xgmi_cmd;
916 struct ta_xgmi_cmd_get_topology_info_input *topology_info_input;
917 struct ta_xgmi_cmd_get_topology_info_output *topology_info_output;
921 if (!topology || topology->num_nodes > TA_XGMI__MAX_CONNECTED_NODES)
924 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.xgmi_shared_buf;
925 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
927 /* Fill in the shared memory with topology information as input */
928 topology_info_input = &xgmi_cmd->xgmi_in_message.get_topology_info;
929 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_GET_TOPOLOGY_INFO;
930 topology_info_input->num_nodes = number_devices;
932 for (i = 0; i < topology_info_input->num_nodes; i++) {
933 topology_info_input->nodes[i].node_id = topology->nodes[i].node_id;
934 topology_info_input->nodes[i].num_hops = topology->nodes[i].num_hops;
935 topology_info_input->nodes[i].is_sharing_enabled = topology->nodes[i].is_sharing_enabled;
936 topology_info_input->nodes[i].sdma_engine = topology->nodes[i].sdma_engine;
939 /* Invoke xgmi ta to get the topology information */
940 ret = psp_xgmi_invoke(psp, TA_COMMAND_XGMI__GET_GET_TOPOLOGY_INFO);
944 /* Read the output topology information from the shared memory */
945 topology_info_output = &xgmi_cmd->xgmi_out_message.get_topology_info;
946 topology->num_nodes = xgmi_cmd->xgmi_out_message.get_topology_info.num_nodes;
947 for (i = 0; i < topology->num_nodes; i++) {
948 topology->nodes[i].node_id = topology_info_output->nodes[i].node_id;
949 topology->nodes[i].num_hops = topology_info_output->nodes[i].num_hops;
950 topology->nodes[i].is_sharing_enabled = topology_info_output->nodes[i].is_sharing_enabled;
951 topology->nodes[i].sdma_engine = topology_info_output->nodes[i].sdma_engine;
957 int psp_xgmi_set_topology_info(struct psp_context *psp,
959 struct psp_xgmi_topology_info *topology)
961 struct ta_xgmi_shared_memory *xgmi_cmd;
962 struct ta_xgmi_cmd_get_topology_info_input *topology_info_input;
965 if (!topology || topology->num_nodes > TA_XGMI__MAX_CONNECTED_NODES)
968 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.xgmi_shared_buf;
969 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
971 topology_info_input = &xgmi_cmd->xgmi_in_message.get_topology_info;
972 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__SET_TOPOLOGY_INFO;
973 topology_info_input->num_nodes = number_devices;
975 for (i = 0; i < topology_info_input->num_nodes; i++) {
976 topology_info_input->nodes[i].node_id = topology->nodes[i].node_id;
977 topology_info_input->nodes[i].num_hops = topology->nodes[i].num_hops;
978 topology_info_input->nodes[i].is_sharing_enabled = 1;
979 topology_info_input->nodes[i].sdma_engine = topology->nodes[i].sdma_engine;
982 /* Invoke xgmi ta to set topology information */
983 return psp_xgmi_invoke(psp, TA_COMMAND_XGMI__SET_TOPOLOGY_INFO);
987 static int psp_ras_init_shared_buf(struct psp_context *psp)
992 * Allocate 16k memory aligned to 4k from Frame Buffer (local
993 * physical) for ras ta <-> Driver
995 ret = amdgpu_bo_create_kernel(psp->adev, PSP_RAS_SHARED_MEM_SIZE,
996 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
997 &psp->ras.ras_shared_bo,
998 &psp->ras.ras_shared_mc_addr,
999 &psp->ras.ras_shared_buf);
1004 static int psp_ras_load(struct psp_context *psp)
1007 struct psp_gfx_cmd_resp *cmd;
1008 struct ta_ras_shared_memory *ras_cmd;
1011 * TODO: bypass the loading in sriov for now
1013 if (amdgpu_sriov_vf(psp->adev))
1016 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1020 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1021 memcpy(psp->fw_pri_buf, psp->ta_ras_start_addr, psp->ta_ras_ucode_size);
1023 ras_cmd = (struct ta_ras_shared_memory *)psp->ras.ras_shared_buf;
1025 if (psp->adev->gmc.xgmi.connected_to_cpu)
1026 ras_cmd->ras_in_message.init_flags.poison_mode_en = 1;
1028 ras_cmd->ras_in_message.init_flags.dgpu_mode = 1;
1030 psp_prep_ta_load_cmd_buf(cmd,
1031 psp->fw_pri_mc_addr,
1032 psp->ta_ras_ucode_size,
1033 psp->ras.ras_shared_mc_addr,
1034 PSP_RAS_SHARED_MEM_SIZE);
1036 ret = psp_cmd_submit_buf(psp, NULL, cmd,
1037 psp->fence_buf_mc_addr);
1040 psp->ras.session_id = cmd->resp.session_id;
1042 if (!ras_cmd->ras_status)
1043 psp->ras.ras_initialized = true;
1045 dev_warn(psp->adev->dev, "RAS Init Status: 0x%X\n", ras_cmd->ras_status);
1048 if (ret || ras_cmd->ras_status)
1049 amdgpu_ras_fini(psp->adev);
1056 static int psp_ras_unload(struct psp_context *psp)
1059 struct psp_gfx_cmd_resp *cmd;
1062 * TODO: bypass the unloading in sriov for now
1064 if (amdgpu_sriov_vf(psp->adev))
1067 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1071 psp_prep_ta_unload_cmd_buf(cmd, psp->ras.session_id);
1073 ret = psp_cmd_submit_buf(psp, NULL, cmd,
1074 psp->fence_buf_mc_addr);
1081 int psp_ras_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1083 struct ta_ras_shared_memory *ras_cmd;
1086 ras_cmd = (struct ta_ras_shared_memory *)psp->ras.ras_shared_buf;
1089 * TODO: bypass the loading in sriov for now
1091 if (amdgpu_sriov_vf(psp->adev))
1094 ret = psp_ta_invoke(psp, ta_cmd_id, psp->ras.session_id);
1096 if (amdgpu_ras_intr_triggered())
1099 if (ras_cmd->if_version > RAS_TA_HOST_IF_VER)
1101 DRM_WARN("RAS: Unsupported Interface");
1106 if (ras_cmd->ras_out_message.flags.err_inject_switch_disable_flag) {
1107 dev_warn(psp->adev->dev, "ECC switch disabled\n");
1109 ras_cmd->ras_status = TA_RAS_STATUS__ERROR_RAS_NOT_AVAILABLE;
1111 else if (ras_cmd->ras_out_message.flags.reg_access_failure_flag)
1112 dev_warn(psp->adev->dev,
1113 "RAS internal register access blocked\n");
1119 static int psp_ras_status_to_errno(struct amdgpu_device *adev,
1120 enum ta_ras_status ras_status)
1124 switch (ras_status) {
1125 case TA_RAS_STATUS__SUCCESS:
1128 case TA_RAS_STATUS__RESET_NEEDED:
1131 case TA_RAS_STATUS__ERROR_RAS_NOT_AVAILABLE:
1132 dev_warn(adev->dev, "RAS WARN: ras function unavailable\n");
1134 case TA_RAS_STATUS__ERROR_ASD_READ_WRITE:
1135 dev_warn(adev->dev, "RAS WARN: asd read or write failed\n");
1138 dev_err(adev->dev, "RAS ERROR: ras function failed ret 0x%X\n", ret);
1144 int psp_ras_enable_features(struct psp_context *psp,
1145 union ta_ras_cmd_input *info, bool enable)
1147 struct ta_ras_shared_memory *ras_cmd;
1150 if (!psp->ras.ras_initialized)
1153 ras_cmd = (struct ta_ras_shared_memory *)psp->ras.ras_shared_buf;
1154 memset(ras_cmd, 0, sizeof(struct ta_ras_shared_memory));
1157 ras_cmd->cmd_id = TA_RAS_COMMAND__ENABLE_FEATURES;
1159 ras_cmd->cmd_id = TA_RAS_COMMAND__DISABLE_FEATURES;
1161 ras_cmd->ras_in_message = *info;
1163 ret = psp_ras_invoke(psp, ras_cmd->cmd_id);
1167 return psp_ras_status_to_errno(psp->adev, ras_cmd->ras_status);
1170 static int psp_ras_terminate(struct psp_context *psp)
1175 * TODO: bypass the terminate in sriov for now
1177 if (amdgpu_sriov_vf(psp->adev))
1180 if (!psp->ras.ras_initialized)
1183 ret = psp_ras_unload(psp);
1187 psp->ras.ras_initialized = false;
1189 /* free ras shared memory */
1190 amdgpu_bo_free_kernel(&psp->ras.ras_shared_bo,
1191 &psp->ras.ras_shared_mc_addr,
1192 &psp->ras.ras_shared_buf);
1197 static int psp_ras_initialize(struct psp_context *psp)
1202 * TODO: bypass the initialize in sriov for now
1204 if (amdgpu_sriov_vf(psp->adev))
1207 if (!psp->adev->psp.ta_ras_ucode_size ||
1208 !psp->adev->psp.ta_ras_start_addr) {
1209 dev_info(psp->adev->dev, "RAS: optional ras ta ucode is not available\n");
1213 if (!psp->ras.ras_initialized) {
1214 ret = psp_ras_init_shared_buf(psp);
1219 ret = psp_ras_load(psp);
1226 int psp_ras_trigger_error(struct psp_context *psp,
1227 struct ta_ras_trigger_error_input *info)
1229 struct ta_ras_shared_memory *ras_cmd;
1232 if (!psp->ras.ras_initialized)
1235 ras_cmd = (struct ta_ras_shared_memory *)psp->ras.ras_shared_buf;
1236 memset(ras_cmd, 0, sizeof(struct ta_ras_shared_memory));
1238 ras_cmd->cmd_id = TA_RAS_COMMAND__TRIGGER_ERROR;
1239 ras_cmd->ras_in_message.trigger_error = *info;
1241 ret = psp_ras_invoke(psp, ras_cmd->cmd_id);
1245 /* If err_event_athub occurs error inject was successful, however
1246 return status from TA is no long reliable */
1247 if (amdgpu_ras_intr_triggered())
1250 return psp_ras_status_to_errno(psp->adev, ras_cmd->ras_status);
1255 static int psp_hdcp_init_shared_buf(struct psp_context *psp)
1260 * Allocate 16k memory aligned to 4k from Frame Buffer (local
1261 * physical) for hdcp ta <-> Driver
1263 ret = amdgpu_bo_create_kernel(psp->adev, PSP_HDCP_SHARED_MEM_SIZE,
1264 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
1265 &psp->hdcp_context.hdcp_shared_bo,
1266 &psp->hdcp_context.hdcp_shared_mc_addr,
1267 &psp->hdcp_context.hdcp_shared_buf);
1272 static int psp_hdcp_load(struct psp_context *psp)
1275 struct psp_gfx_cmd_resp *cmd;
1278 * TODO: bypass the loading in sriov for now
1280 if (amdgpu_sriov_vf(psp->adev))
1283 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1287 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1288 memcpy(psp->fw_pri_buf, psp->ta_hdcp_start_addr,
1289 psp->ta_hdcp_ucode_size);
1291 psp_prep_ta_load_cmd_buf(cmd,
1292 psp->fw_pri_mc_addr,
1293 psp->ta_hdcp_ucode_size,
1294 psp->hdcp_context.hdcp_shared_mc_addr,
1295 PSP_HDCP_SHARED_MEM_SIZE);
1297 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1300 psp->hdcp_context.hdcp_initialized = true;
1301 psp->hdcp_context.session_id = cmd->resp.session_id;
1302 mutex_init(&psp->hdcp_context.mutex);
1309 static int psp_hdcp_initialize(struct psp_context *psp)
1314 * TODO: bypass the initialize in sriov for now
1316 if (amdgpu_sriov_vf(psp->adev))
1319 if (!psp->adev->psp.ta_hdcp_ucode_size ||
1320 !psp->adev->psp.ta_hdcp_start_addr) {
1321 dev_info(psp->adev->dev, "HDCP: optional hdcp ta ucode is not available\n");
1325 if (!psp->hdcp_context.hdcp_initialized) {
1326 ret = psp_hdcp_init_shared_buf(psp);
1331 ret = psp_hdcp_load(psp);
1338 static int psp_hdcp_unload(struct psp_context *psp)
1341 struct psp_gfx_cmd_resp *cmd;
1344 * TODO: bypass the unloading in sriov for now
1346 if (amdgpu_sriov_vf(psp->adev))
1349 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1353 psp_prep_ta_unload_cmd_buf(cmd, psp->hdcp_context.session_id);
1355 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1362 int psp_hdcp_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1365 * TODO: bypass the loading in sriov for now
1367 if (amdgpu_sriov_vf(psp->adev))
1370 return psp_ta_invoke(psp, ta_cmd_id, psp->hdcp_context.session_id);
1373 static int psp_hdcp_terminate(struct psp_context *psp)
1378 * TODO: bypass the terminate in sriov for now
1380 if (amdgpu_sriov_vf(psp->adev))
1383 if (!psp->hdcp_context.hdcp_initialized) {
1384 if (psp->hdcp_context.hdcp_shared_buf)
1390 ret = psp_hdcp_unload(psp);
1394 psp->hdcp_context.hdcp_initialized = false;
1397 /* free hdcp shared memory */
1398 amdgpu_bo_free_kernel(&psp->hdcp_context.hdcp_shared_bo,
1399 &psp->hdcp_context.hdcp_shared_mc_addr,
1400 &psp->hdcp_context.hdcp_shared_buf);
1407 static int psp_dtm_init_shared_buf(struct psp_context *psp)
1412 * Allocate 16k memory aligned to 4k from Frame Buffer (local
1413 * physical) for dtm ta <-> Driver
1415 ret = amdgpu_bo_create_kernel(psp->adev, PSP_DTM_SHARED_MEM_SIZE,
1416 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
1417 &psp->dtm_context.dtm_shared_bo,
1418 &psp->dtm_context.dtm_shared_mc_addr,
1419 &psp->dtm_context.dtm_shared_buf);
1424 static int psp_dtm_load(struct psp_context *psp)
1427 struct psp_gfx_cmd_resp *cmd;
1430 * TODO: bypass the loading in sriov for now
1432 if (amdgpu_sriov_vf(psp->adev))
1435 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1439 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1440 memcpy(psp->fw_pri_buf, psp->ta_dtm_start_addr, psp->ta_dtm_ucode_size);
1442 psp_prep_ta_load_cmd_buf(cmd,
1443 psp->fw_pri_mc_addr,
1444 psp->ta_dtm_ucode_size,
1445 psp->dtm_context.dtm_shared_mc_addr,
1446 PSP_DTM_SHARED_MEM_SIZE);
1448 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1451 psp->dtm_context.dtm_initialized = true;
1452 psp->dtm_context.session_id = cmd->resp.session_id;
1453 mutex_init(&psp->dtm_context.mutex);
1461 static int psp_dtm_initialize(struct psp_context *psp)
1466 * TODO: bypass the initialize in sriov for now
1468 if (amdgpu_sriov_vf(psp->adev))
1471 if (!psp->adev->psp.ta_dtm_ucode_size ||
1472 !psp->adev->psp.ta_dtm_start_addr) {
1473 dev_info(psp->adev->dev, "DTM: optional dtm ta ucode is not available\n");
1477 if (!psp->dtm_context.dtm_initialized) {
1478 ret = psp_dtm_init_shared_buf(psp);
1483 ret = psp_dtm_load(psp);
1490 static int psp_dtm_unload(struct psp_context *psp)
1493 struct psp_gfx_cmd_resp *cmd;
1496 * TODO: bypass the unloading in sriov for now
1498 if (amdgpu_sriov_vf(psp->adev))
1501 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1505 psp_prep_ta_unload_cmd_buf(cmd, psp->dtm_context.session_id);
1507 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1514 int psp_dtm_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1517 * TODO: bypass the loading in sriov for now
1519 if (amdgpu_sriov_vf(psp->adev))
1522 return psp_ta_invoke(psp, ta_cmd_id, psp->dtm_context.session_id);
1525 static int psp_dtm_terminate(struct psp_context *psp)
1530 * TODO: bypass the terminate in sriov for now
1532 if (amdgpu_sriov_vf(psp->adev))
1535 if (!psp->dtm_context.dtm_initialized) {
1536 if (psp->dtm_context.dtm_shared_buf)
1542 ret = psp_dtm_unload(psp);
1546 psp->dtm_context.dtm_initialized = false;
1549 /* free hdcp shared memory */
1550 amdgpu_bo_free_kernel(&psp->dtm_context.dtm_shared_bo,
1551 &psp->dtm_context.dtm_shared_mc_addr,
1552 &psp->dtm_context.dtm_shared_buf);
1559 static int psp_rap_init_shared_buf(struct psp_context *psp)
1564 * Allocate 16k memory aligned to 4k from Frame Buffer (local
1565 * physical) for rap ta <-> Driver
1567 ret = amdgpu_bo_create_kernel(psp->adev, PSP_RAP_SHARED_MEM_SIZE,
1568 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
1569 &psp->rap_context.rap_shared_bo,
1570 &psp->rap_context.rap_shared_mc_addr,
1571 &psp->rap_context.rap_shared_buf);
1576 static int psp_rap_load(struct psp_context *psp)
1579 struct psp_gfx_cmd_resp *cmd;
1581 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1585 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1586 memcpy(psp->fw_pri_buf, psp->ta_rap_start_addr, psp->ta_rap_ucode_size);
1588 psp_prep_ta_load_cmd_buf(cmd,
1589 psp->fw_pri_mc_addr,
1590 psp->ta_rap_ucode_size,
1591 psp->rap_context.rap_shared_mc_addr,
1592 PSP_RAP_SHARED_MEM_SIZE);
1594 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1597 psp->rap_context.rap_initialized = true;
1598 psp->rap_context.session_id = cmd->resp.session_id;
1599 mutex_init(&psp->rap_context.mutex);
1607 static int psp_rap_unload(struct psp_context *psp)
1610 struct psp_gfx_cmd_resp *cmd;
1612 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1616 psp_prep_ta_unload_cmd_buf(cmd, psp->rap_context.session_id);
1618 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1625 static int psp_rap_initialize(struct psp_context *psp)
1628 enum ta_rap_status status = TA_RAP_STATUS__SUCCESS;
1631 * TODO: bypass the initialize in sriov for now
1633 if (amdgpu_sriov_vf(psp->adev))
1636 if (!psp->adev->psp.ta_rap_ucode_size ||
1637 !psp->adev->psp.ta_rap_start_addr) {
1638 dev_info(psp->adev->dev, "RAP: optional rap ta ucode is not available\n");
1642 if (!psp->rap_context.rap_initialized) {
1643 ret = psp_rap_init_shared_buf(psp);
1648 ret = psp_rap_load(psp);
1652 ret = psp_rap_invoke(psp, TA_CMD_RAP__INITIALIZE, &status);
1653 if (ret || status != TA_RAP_STATUS__SUCCESS) {
1654 psp_rap_unload(psp);
1656 amdgpu_bo_free_kernel(&psp->rap_context.rap_shared_bo,
1657 &psp->rap_context.rap_shared_mc_addr,
1658 &psp->rap_context.rap_shared_buf);
1660 psp->rap_context.rap_initialized = false;
1662 dev_warn(psp->adev->dev, "RAP TA initialize fail (%d) status %d.\n",
1671 static int psp_rap_terminate(struct psp_context *psp)
1675 if (!psp->rap_context.rap_initialized)
1678 ret = psp_rap_unload(psp);
1680 psp->rap_context.rap_initialized = false;
1682 /* free rap shared memory */
1683 amdgpu_bo_free_kernel(&psp->rap_context.rap_shared_bo,
1684 &psp->rap_context.rap_shared_mc_addr,
1685 &psp->rap_context.rap_shared_buf);
1690 int psp_rap_invoke(struct psp_context *psp, uint32_t ta_cmd_id, enum ta_rap_status *status)
1692 struct ta_rap_shared_memory *rap_cmd;
1695 if (!psp->rap_context.rap_initialized)
1698 if (ta_cmd_id != TA_CMD_RAP__INITIALIZE &&
1699 ta_cmd_id != TA_CMD_RAP__VALIDATE_L0)
1702 mutex_lock(&psp->rap_context.mutex);
1704 rap_cmd = (struct ta_rap_shared_memory *)
1705 psp->rap_context.rap_shared_buf;
1706 memset(rap_cmd, 0, sizeof(struct ta_rap_shared_memory));
1708 rap_cmd->cmd_id = ta_cmd_id;
1709 rap_cmd->validation_method_id = METHOD_A;
1711 ret = psp_ta_invoke(psp, rap_cmd->cmd_id, psp->rap_context.session_id);
1716 *status = rap_cmd->rap_status;
1719 mutex_unlock(&psp->rap_context.mutex);
1725 /* securedisplay start */
1726 static int psp_securedisplay_init_shared_buf(struct psp_context *psp)
1731 * Allocate 16k memory aligned to 4k from Frame Buffer (local
1732 * physical) for sa ta <-> Driver
1734 ret = amdgpu_bo_create_kernel(psp->adev, PSP_SECUREDISPLAY_SHARED_MEM_SIZE,
1735 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
1736 &psp->securedisplay_context.securedisplay_shared_bo,
1737 &psp->securedisplay_context.securedisplay_shared_mc_addr,
1738 &psp->securedisplay_context.securedisplay_shared_buf);
1743 static int psp_securedisplay_load(struct psp_context *psp)
1746 struct psp_gfx_cmd_resp *cmd;
1748 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1752 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1753 memcpy(psp->fw_pri_buf, psp->ta_securedisplay_start_addr, psp->ta_securedisplay_ucode_size);
1755 psp_prep_ta_load_cmd_buf(cmd,
1756 psp->fw_pri_mc_addr,
1757 psp->ta_securedisplay_ucode_size,
1758 psp->securedisplay_context.securedisplay_shared_mc_addr,
1759 PSP_SECUREDISPLAY_SHARED_MEM_SIZE);
1761 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1766 psp->securedisplay_context.securedisplay_initialized = true;
1767 psp->securedisplay_context.session_id = cmd->resp.session_id;
1768 mutex_init(&psp->securedisplay_context.mutex);
1775 static int psp_securedisplay_unload(struct psp_context *psp)
1778 struct psp_gfx_cmd_resp *cmd;
1780 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
1784 psp_prep_ta_unload_cmd_buf(cmd, psp->securedisplay_context.session_id);
1786 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1793 static int psp_securedisplay_initialize(struct psp_context *psp)
1796 struct securedisplay_cmd *securedisplay_cmd;
1799 * TODO: bypass the initialize in sriov for now
1801 if (amdgpu_sriov_vf(psp->adev))
1804 if (!psp->adev->psp.ta_securedisplay_ucode_size ||
1805 !psp->adev->psp.ta_securedisplay_start_addr) {
1806 dev_info(psp->adev->dev, "SECUREDISPLAY: securedisplay ta ucode is not available\n");
1810 if (!psp->securedisplay_context.securedisplay_initialized) {
1811 ret = psp_securedisplay_init_shared_buf(psp);
1816 ret = psp_securedisplay_load(psp);
1820 psp_prep_securedisplay_cmd_buf(psp, &securedisplay_cmd,
1821 TA_SECUREDISPLAY_COMMAND__QUERY_TA);
1823 ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__QUERY_TA);
1825 psp_securedisplay_unload(psp);
1827 amdgpu_bo_free_kernel(&psp->securedisplay_context.securedisplay_shared_bo,
1828 &psp->securedisplay_context.securedisplay_shared_mc_addr,
1829 &psp->securedisplay_context.securedisplay_shared_buf);
1831 psp->securedisplay_context.securedisplay_initialized = false;
1833 dev_err(psp->adev->dev, "SECUREDISPLAY TA initialize fail.\n");
1837 if (securedisplay_cmd->status != TA_SECUREDISPLAY_STATUS__SUCCESS) {
1838 psp_securedisplay_parse_resp_status(psp, securedisplay_cmd->status);
1839 dev_err(psp->adev->dev, "SECUREDISPLAY: query securedisplay TA failed. ret 0x%x\n",
1840 securedisplay_cmd->securedisplay_out_message.query_ta.query_cmd_ret);
1846 static int psp_securedisplay_terminate(struct psp_context *psp)
1851 * TODO:bypass the terminate in sriov for now
1853 if (amdgpu_sriov_vf(psp->adev))
1856 if (!psp->securedisplay_context.securedisplay_initialized)
1859 ret = psp_securedisplay_unload(psp);
1863 psp->securedisplay_context.securedisplay_initialized = false;
1865 /* free securedisplay shared memory */
1866 amdgpu_bo_free_kernel(&psp->securedisplay_context.securedisplay_shared_bo,
1867 &psp->securedisplay_context.securedisplay_shared_mc_addr,
1868 &psp->securedisplay_context.securedisplay_shared_buf);
1873 int psp_securedisplay_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1877 if (!psp->securedisplay_context.securedisplay_initialized)
1880 if (ta_cmd_id != TA_SECUREDISPLAY_COMMAND__QUERY_TA &&
1881 ta_cmd_id != TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC)
1884 mutex_lock(&psp->securedisplay_context.mutex);
1886 ret = psp_ta_invoke(psp, ta_cmd_id, psp->securedisplay_context.session_id);
1888 mutex_unlock(&psp->securedisplay_context.mutex);
1892 /* SECUREDISPLAY end */
1894 static int psp_hw_start(struct psp_context *psp)
1896 struct amdgpu_device *adev = psp->adev;
1899 if (!amdgpu_sriov_vf(adev)) {
1900 if (psp->kdb_bin_size &&
1901 (psp->funcs->bootloader_load_kdb != NULL)) {
1902 ret = psp_bootloader_load_kdb(psp);
1904 DRM_ERROR("PSP load kdb failed!\n");
1909 if (psp->spl_bin_size) {
1910 ret = psp_bootloader_load_spl(psp);
1912 DRM_ERROR("PSP load spl failed!\n");
1917 ret = psp_bootloader_load_sysdrv(psp);
1919 DRM_ERROR("PSP load sysdrv failed!\n");
1923 ret = psp_bootloader_load_sos(psp);
1925 DRM_ERROR("PSP load sos failed!\n");
1930 ret = psp_ring_create(psp, PSP_RING_TYPE__KM);
1932 DRM_ERROR("PSP create ring failed!\n");
1936 if (amdgpu_atomfirmware_dynamic_boot_config_supported(adev)) {
1937 ret = psp_boot_config_set(adev);
1939 dev_warn(adev->dev, "PSP set boot config failed\n");
1942 ret = psp_tmr_init(psp);
1944 DRM_ERROR("PSP tmr init failed!\n");
1949 * For ASICs with DF Cstate management centralized
1950 * to PMFW, TMR setup should be performed after PMFW
1951 * loaded and before other non-psp firmware loaded.
1953 if (psp->pmfw_centralized_cstate_management) {
1954 ret = psp_load_smu_fw(psp);
1959 ret = psp_tmr_load(psp);
1961 DRM_ERROR("PSP load tmr failed!\n");
1968 static int psp_get_fw_type(struct amdgpu_firmware_info *ucode,
1969 enum psp_gfx_fw_type *type)
1971 switch (ucode->ucode_id) {
1972 case AMDGPU_UCODE_ID_SDMA0:
1973 *type = GFX_FW_TYPE_SDMA0;
1975 case AMDGPU_UCODE_ID_SDMA1:
1976 *type = GFX_FW_TYPE_SDMA1;
1978 case AMDGPU_UCODE_ID_SDMA2:
1979 *type = GFX_FW_TYPE_SDMA2;
1981 case AMDGPU_UCODE_ID_SDMA3:
1982 *type = GFX_FW_TYPE_SDMA3;
1984 case AMDGPU_UCODE_ID_SDMA4:
1985 *type = GFX_FW_TYPE_SDMA4;
1987 case AMDGPU_UCODE_ID_SDMA5:
1988 *type = GFX_FW_TYPE_SDMA5;
1990 case AMDGPU_UCODE_ID_SDMA6:
1991 *type = GFX_FW_TYPE_SDMA6;
1993 case AMDGPU_UCODE_ID_SDMA7:
1994 *type = GFX_FW_TYPE_SDMA7;
1996 case AMDGPU_UCODE_ID_CP_MES:
1997 *type = GFX_FW_TYPE_CP_MES;
1999 case AMDGPU_UCODE_ID_CP_MES_DATA:
2000 *type = GFX_FW_TYPE_MES_STACK;
2002 case AMDGPU_UCODE_ID_CP_CE:
2003 *type = GFX_FW_TYPE_CP_CE;
2005 case AMDGPU_UCODE_ID_CP_PFP:
2006 *type = GFX_FW_TYPE_CP_PFP;
2008 case AMDGPU_UCODE_ID_CP_ME:
2009 *type = GFX_FW_TYPE_CP_ME;
2011 case AMDGPU_UCODE_ID_CP_MEC1:
2012 *type = GFX_FW_TYPE_CP_MEC;
2014 case AMDGPU_UCODE_ID_CP_MEC1_JT:
2015 *type = GFX_FW_TYPE_CP_MEC_ME1;
2017 case AMDGPU_UCODE_ID_CP_MEC2:
2018 *type = GFX_FW_TYPE_CP_MEC;
2020 case AMDGPU_UCODE_ID_CP_MEC2_JT:
2021 *type = GFX_FW_TYPE_CP_MEC_ME2;
2023 case AMDGPU_UCODE_ID_RLC_G:
2024 *type = GFX_FW_TYPE_RLC_G;
2026 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL:
2027 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_CNTL;
2029 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM:
2030 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_GPM_MEM;
2032 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM:
2033 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_MEM;
2035 case AMDGPU_UCODE_ID_RLC_IRAM:
2036 *type = GFX_FW_TYPE_RLC_IRAM;
2038 case AMDGPU_UCODE_ID_RLC_DRAM:
2039 *type = GFX_FW_TYPE_RLC_DRAM_BOOT;
2041 case AMDGPU_UCODE_ID_SMC:
2042 *type = GFX_FW_TYPE_SMU;
2044 case AMDGPU_UCODE_ID_UVD:
2045 *type = GFX_FW_TYPE_UVD;
2047 case AMDGPU_UCODE_ID_UVD1:
2048 *type = GFX_FW_TYPE_UVD1;
2050 case AMDGPU_UCODE_ID_VCE:
2051 *type = GFX_FW_TYPE_VCE;
2053 case AMDGPU_UCODE_ID_VCN:
2054 *type = GFX_FW_TYPE_VCN;
2056 case AMDGPU_UCODE_ID_VCN1:
2057 *type = GFX_FW_TYPE_VCN1;
2059 case AMDGPU_UCODE_ID_DMCU_ERAM:
2060 *type = GFX_FW_TYPE_DMCU_ERAM;
2062 case AMDGPU_UCODE_ID_DMCU_INTV:
2063 *type = GFX_FW_TYPE_DMCU_ISR;
2065 case AMDGPU_UCODE_ID_VCN0_RAM:
2066 *type = GFX_FW_TYPE_VCN0_RAM;
2068 case AMDGPU_UCODE_ID_VCN1_RAM:
2069 *type = GFX_FW_TYPE_VCN1_RAM;
2071 case AMDGPU_UCODE_ID_DMCUB:
2072 *type = GFX_FW_TYPE_DMUB;
2074 case AMDGPU_UCODE_ID_MAXIMUM:
2082 static void psp_print_fw_hdr(struct psp_context *psp,
2083 struct amdgpu_firmware_info *ucode)
2085 struct amdgpu_device *adev = psp->adev;
2086 struct common_firmware_header *hdr;
2088 switch (ucode->ucode_id) {
2089 case AMDGPU_UCODE_ID_SDMA0:
2090 case AMDGPU_UCODE_ID_SDMA1:
2091 case AMDGPU_UCODE_ID_SDMA2:
2092 case AMDGPU_UCODE_ID_SDMA3:
2093 case AMDGPU_UCODE_ID_SDMA4:
2094 case AMDGPU_UCODE_ID_SDMA5:
2095 case AMDGPU_UCODE_ID_SDMA6:
2096 case AMDGPU_UCODE_ID_SDMA7:
2097 hdr = (struct common_firmware_header *)
2098 adev->sdma.instance[ucode->ucode_id - AMDGPU_UCODE_ID_SDMA0].fw->data;
2099 amdgpu_ucode_print_sdma_hdr(hdr);
2101 case AMDGPU_UCODE_ID_CP_CE:
2102 hdr = (struct common_firmware_header *)adev->gfx.ce_fw->data;
2103 amdgpu_ucode_print_gfx_hdr(hdr);
2105 case AMDGPU_UCODE_ID_CP_PFP:
2106 hdr = (struct common_firmware_header *)adev->gfx.pfp_fw->data;
2107 amdgpu_ucode_print_gfx_hdr(hdr);
2109 case AMDGPU_UCODE_ID_CP_ME:
2110 hdr = (struct common_firmware_header *)adev->gfx.me_fw->data;
2111 amdgpu_ucode_print_gfx_hdr(hdr);
2113 case AMDGPU_UCODE_ID_CP_MEC1:
2114 hdr = (struct common_firmware_header *)adev->gfx.mec_fw->data;
2115 amdgpu_ucode_print_gfx_hdr(hdr);
2117 case AMDGPU_UCODE_ID_RLC_G:
2118 hdr = (struct common_firmware_header *)adev->gfx.rlc_fw->data;
2119 amdgpu_ucode_print_rlc_hdr(hdr);
2121 case AMDGPU_UCODE_ID_SMC:
2122 hdr = (struct common_firmware_header *)adev->pm.fw->data;
2123 amdgpu_ucode_print_smc_hdr(hdr);
2130 static int psp_prep_load_ip_fw_cmd_buf(struct amdgpu_firmware_info *ucode,
2131 struct psp_gfx_cmd_resp *cmd)
2134 uint64_t fw_mem_mc_addr = ucode->mc_addr;
2136 memset(cmd, 0, sizeof(struct psp_gfx_cmd_resp));
2138 cmd->cmd_id = GFX_CMD_ID_LOAD_IP_FW;
2139 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_lo = lower_32_bits(fw_mem_mc_addr);
2140 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_hi = upper_32_bits(fw_mem_mc_addr);
2141 cmd->cmd.cmd_load_ip_fw.fw_size = ucode->ucode_size;
2143 ret = psp_get_fw_type(ucode, &cmd->cmd.cmd_load_ip_fw.fw_type);
2145 DRM_ERROR("Unknown firmware type\n");
2150 static int psp_execute_np_fw_load(struct psp_context *psp,
2151 struct amdgpu_firmware_info *ucode)
2155 ret = psp_prep_load_ip_fw_cmd_buf(ucode, psp->cmd);
2159 ret = psp_cmd_submit_buf(psp, ucode, psp->cmd,
2160 psp->fence_buf_mc_addr);
2165 static int psp_load_smu_fw(struct psp_context *psp)
2168 struct amdgpu_device *adev = psp->adev;
2169 struct amdgpu_firmware_info *ucode =
2170 &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
2171 struct amdgpu_ras *ras = psp->ras.ras;
2173 if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
2176 if ((amdgpu_in_reset(adev) &&
2177 ras && adev->ras_enabled &&
2178 (adev->asic_type == CHIP_ARCTURUS ||
2179 adev->asic_type == CHIP_VEGA20)) ||
2181 adev->asic_type >= CHIP_NAVI10 &&
2182 adev->asic_type <= CHIP_NAVI12)) {
2183 ret = amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_UNLOAD);
2185 DRM_WARN("Failed to set MP1 state prepare for reload\n");
2189 ret = psp_execute_np_fw_load(psp, ucode);
2192 DRM_ERROR("PSP load smu failed!\n");
2197 static bool fw_load_skip_check(struct psp_context *psp,
2198 struct amdgpu_firmware_info *ucode)
2203 if (ucode->ucode_id == AMDGPU_UCODE_ID_SMC &&
2204 (psp_smu_reload_quirk(psp) ||
2205 psp->autoload_supported ||
2206 psp->pmfw_centralized_cstate_management))
2209 if (amdgpu_sriov_vf(psp->adev) &&
2210 (ucode->ucode_id == AMDGPU_UCODE_ID_SDMA0
2211 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA1
2212 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA2
2213 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA3
2214 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA4
2215 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA5
2216 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA6
2217 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA7
2218 || ucode->ucode_id == AMDGPU_UCODE_ID_RLC_G
2219 || ucode->ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL
2220 || ucode->ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM
2221 || ucode->ucode_id == AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM
2222 || ucode->ucode_id == AMDGPU_UCODE_ID_SMC))
2223 /*skip ucode loading in SRIOV VF */
2226 if (psp->autoload_supported &&
2227 (ucode->ucode_id == AMDGPU_UCODE_ID_CP_MEC1_JT ||
2228 ucode->ucode_id == AMDGPU_UCODE_ID_CP_MEC2_JT))
2229 /* skip mec JT when autoload is enabled */
2235 int psp_load_fw_list(struct psp_context *psp,
2236 struct amdgpu_firmware_info **ucode_list, int ucode_count)
2239 struct amdgpu_firmware_info *ucode;
2241 for (i = 0; i < ucode_count; ++i) {
2242 ucode = ucode_list[i];
2243 psp_print_fw_hdr(psp, ucode);
2244 ret = psp_execute_np_fw_load(psp, ucode);
2251 static int psp_np_fw_load(struct psp_context *psp)
2254 struct amdgpu_firmware_info *ucode;
2255 struct amdgpu_device *adev = psp->adev;
2257 if (psp->autoload_supported &&
2258 !psp->pmfw_centralized_cstate_management) {
2259 ret = psp_load_smu_fw(psp);
2264 for (i = 0; i < adev->firmware.max_ucodes; i++) {
2265 ucode = &adev->firmware.ucode[i];
2267 if (ucode->ucode_id == AMDGPU_UCODE_ID_SMC &&
2268 !fw_load_skip_check(psp, ucode)) {
2269 ret = psp_load_smu_fw(psp);
2275 if (fw_load_skip_check(psp, ucode))
2278 if (psp->autoload_supported &&
2279 (adev->asic_type >= CHIP_SIENNA_CICHLID &&
2280 adev->asic_type <= CHIP_DIMGREY_CAVEFISH) &&
2281 (ucode->ucode_id == AMDGPU_UCODE_ID_SDMA1 ||
2282 ucode->ucode_id == AMDGPU_UCODE_ID_SDMA2 ||
2283 ucode->ucode_id == AMDGPU_UCODE_ID_SDMA3))
2284 /* PSP only receive one SDMA fw for sienna_cichlid,
2285 * as all four sdma fw are same */
2288 psp_print_fw_hdr(psp, ucode);
2290 ret = psp_execute_np_fw_load(psp, ucode);
2294 /* Start rlc autoload after psp recieved all the gfx firmware */
2295 if (psp->autoload_supported && ucode->ucode_id == (amdgpu_sriov_vf(adev) ?
2296 AMDGPU_UCODE_ID_CP_MEC2 : AMDGPU_UCODE_ID_RLC_G)) {
2297 ret = psp_rlc_autoload_start(psp);
2299 DRM_ERROR("Failed to start rlc autoload\n");
2308 static int psp_load_fw(struct amdgpu_device *adev)
2311 struct psp_context *psp = &adev->psp;
2313 if (amdgpu_sriov_vf(adev) && amdgpu_in_reset(adev)) {
2314 psp_ring_stop(psp, PSP_RING_TYPE__KM); /* should not destroy ring, only stop */
2318 psp->cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
2322 ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG,
2323 AMDGPU_GEM_DOMAIN_GTT,
2325 &psp->fw_pri_mc_addr,
2330 ret = amdgpu_bo_create_kernel(adev, PSP_FENCE_BUFFER_SIZE, PAGE_SIZE,
2331 AMDGPU_GEM_DOMAIN_VRAM,
2333 &psp->fence_buf_mc_addr,
2338 ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
2339 AMDGPU_GEM_DOMAIN_VRAM,
2340 &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
2341 (void **)&psp->cmd_buf_mem);
2345 memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);
2347 ret = psp_ring_init(psp, PSP_RING_TYPE__KM);
2349 DRM_ERROR("PSP ring init failed!\n");
2354 ret = psp_hw_start(psp);
2358 ret = psp_np_fw_load(psp);
2362 ret = psp_asd_load(psp);
2364 DRM_ERROR("PSP load asd failed!\n");
2368 ret = psp_rl_load(adev);
2370 DRM_ERROR("PSP load RL failed!\n");
2374 if (psp->adev->psp.ta_fw) {
2375 ret = psp_ras_initialize(psp);
2377 dev_err(psp->adev->dev,
2378 "RAS: Failed to initialize RAS\n");
2380 ret = psp_hdcp_initialize(psp);
2382 dev_err(psp->adev->dev,
2383 "HDCP: Failed to initialize HDCP\n");
2385 ret = psp_dtm_initialize(psp);
2387 dev_err(psp->adev->dev,
2388 "DTM: Failed to initialize DTM\n");
2390 ret = psp_rap_initialize(psp);
2392 dev_err(psp->adev->dev,
2393 "RAP: Failed to initialize RAP\n");
2395 ret = psp_securedisplay_initialize(psp);
2397 dev_err(psp->adev->dev,
2398 "SECUREDISPLAY: Failed to initialize SECUREDISPLAY\n");
2405 * all cleanup jobs (xgmi terminate, ras terminate,
2406 * ring destroy, cmd/fence/fw buffers destory,
2407 * psp->cmd destory) are delayed to psp_hw_fini
2412 static int psp_hw_init(void *handle)
2415 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2417 mutex_lock(&adev->firmware.mutex);
2419 * This sequence is just used on hw_init only once, no need on
2422 ret = amdgpu_ucode_init_bo(adev);
2426 ret = psp_load_fw(adev);
2428 DRM_ERROR("PSP firmware loading failed\n");
2432 mutex_unlock(&adev->firmware.mutex);
2436 adev->firmware.load_type = AMDGPU_FW_LOAD_DIRECT;
2437 mutex_unlock(&adev->firmware.mutex);
2441 static int psp_hw_fini(void *handle)
2443 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2444 struct psp_context *psp = &adev->psp;
2446 if (psp->adev->psp.ta_fw) {
2447 psp_ras_terminate(psp);
2448 psp_securedisplay_terminate(psp);
2449 psp_rap_terminate(psp);
2450 psp_dtm_terminate(psp);
2451 psp_hdcp_terminate(psp);
2454 psp_asd_unload(psp);
2456 psp_tmr_terminate(psp);
2457 psp_ring_destroy(psp, PSP_RING_TYPE__KM);
2459 amdgpu_bo_free_kernel(&psp->fw_pri_bo,
2460 &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
2461 amdgpu_bo_free_kernel(&psp->fence_buf_bo,
2462 &psp->fence_buf_mc_addr, &psp->fence_buf);
2463 amdgpu_bo_free_kernel(&psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
2464 (void **)&psp->cmd_buf_mem);
2472 static int psp_suspend(void *handle)
2475 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2476 struct psp_context *psp = &adev->psp;
2478 if (adev->gmc.xgmi.num_physical_nodes > 1 &&
2479 psp->xgmi_context.initialized == 1) {
2480 ret = psp_xgmi_terminate(psp);
2482 DRM_ERROR("Failed to terminate xgmi ta\n");
2487 if (psp->adev->psp.ta_fw) {
2488 ret = psp_ras_terminate(psp);
2490 DRM_ERROR("Failed to terminate ras ta\n");
2493 ret = psp_hdcp_terminate(psp);
2495 DRM_ERROR("Failed to terminate hdcp ta\n");
2498 ret = psp_dtm_terminate(psp);
2500 DRM_ERROR("Failed to terminate dtm ta\n");
2503 ret = psp_rap_terminate(psp);
2505 DRM_ERROR("Failed to terminate rap ta\n");
2508 ret = psp_securedisplay_terminate(psp);
2510 DRM_ERROR("Failed to terminate securedisplay ta\n");
2515 ret = psp_asd_unload(psp);
2517 DRM_ERROR("Failed to unload asd\n");
2521 ret = psp_tmr_terminate(psp);
2523 DRM_ERROR("Failed to terminate tmr\n");
2527 ret = psp_ring_stop(psp, PSP_RING_TYPE__KM);
2529 DRM_ERROR("PSP ring stop failed\n");
2536 static int psp_resume(void *handle)
2539 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2540 struct psp_context *psp = &adev->psp;
2542 DRM_INFO("PSP is resuming...\n");
2544 ret = psp_mem_training(psp, PSP_MEM_TRAIN_RESUME);
2546 DRM_ERROR("Failed to process memory training!\n");
2550 mutex_lock(&adev->firmware.mutex);
2552 ret = psp_hw_start(psp);
2556 ret = psp_np_fw_load(psp);
2560 ret = psp_asd_load(psp);
2562 DRM_ERROR("PSP load asd failed!\n");
2566 if (adev->gmc.xgmi.num_physical_nodes > 1) {
2567 ret = psp_xgmi_initialize(psp);
2568 /* Warning the XGMI seesion initialize failure
2569 * Instead of stop driver initialization
2572 dev_err(psp->adev->dev,
2573 "XGMI: Failed to initialize XGMI session\n");
2576 if (psp->adev->psp.ta_fw) {
2577 ret = psp_ras_initialize(psp);
2579 dev_err(psp->adev->dev,
2580 "RAS: Failed to initialize RAS\n");
2582 ret = psp_hdcp_initialize(psp);
2584 dev_err(psp->adev->dev,
2585 "HDCP: Failed to initialize HDCP\n");
2587 ret = psp_dtm_initialize(psp);
2589 dev_err(psp->adev->dev,
2590 "DTM: Failed to initialize DTM\n");
2592 ret = psp_rap_initialize(psp);
2594 dev_err(psp->adev->dev,
2595 "RAP: Failed to initialize RAP\n");
2597 ret = psp_securedisplay_initialize(psp);
2599 dev_err(psp->adev->dev,
2600 "SECUREDISPLAY: Failed to initialize SECUREDISPLAY\n");
2603 mutex_unlock(&adev->firmware.mutex);
2608 DRM_ERROR("PSP resume failed\n");
2609 mutex_unlock(&adev->firmware.mutex);
2613 int psp_gpu_reset(struct amdgpu_device *adev)
2617 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
2620 mutex_lock(&adev->psp.mutex);
2621 ret = psp_mode1_reset(&adev->psp);
2622 mutex_unlock(&adev->psp.mutex);
2627 int psp_rlc_autoload_start(struct psp_context *psp)
2630 struct psp_gfx_cmd_resp *cmd;
2632 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
2636 cmd->cmd_id = GFX_CMD_ID_AUTOLOAD_RLC;
2638 ret = psp_cmd_submit_buf(psp, NULL, cmd,
2639 psp->fence_buf_mc_addr);
2644 int psp_update_vcn_sram(struct amdgpu_device *adev, int inst_idx,
2645 uint64_t cmd_gpu_addr, int cmd_size)
2647 struct amdgpu_firmware_info ucode = {0};
2649 ucode.ucode_id = inst_idx ? AMDGPU_UCODE_ID_VCN1_RAM :
2650 AMDGPU_UCODE_ID_VCN0_RAM;
2651 ucode.mc_addr = cmd_gpu_addr;
2652 ucode.ucode_size = cmd_size;
2654 return psp_execute_np_fw_load(&adev->psp, &ucode);
2657 int psp_ring_cmd_submit(struct psp_context *psp,
2658 uint64_t cmd_buf_mc_addr,
2659 uint64_t fence_mc_addr,
2662 unsigned int psp_write_ptr_reg = 0;
2663 struct psp_gfx_rb_frame *write_frame;
2664 struct psp_ring *ring = &psp->km_ring;
2665 struct psp_gfx_rb_frame *ring_buffer_start = ring->ring_mem;
2666 struct psp_gfx_rb_frame *ring_buffer_end = ring_buffer_start +
2667 ring->ring_size / sizeof(struct psp_gfx_rb_frame) - 1;
2668 struct amdgpu_device *adev = psp->adev;
2669 uint32_t ring_size_dw = ring->ring_size / 4;
2670 uint32_t rb_frame_size_dw = sizeof(struct psp_gfx_rb_frame) / 4;
2672 /* KM (GPCOM) prepare write pointer */
2673 psp_write_ptr_reg = psp_ring_get_wptr(psp);
2675 /* Update KM RB frame pointer to new frame */
2676 /* write_frame ptr increments by size of rb_frame in bytes */
2677 /* psp_write_ptr_reg increments by size of rb_frame in DWORDs */
2678 if ((psp_write_ptr_reg % ring_size_dw) == 0)
2679 write_frame = ring_buffer_start;
2681 write_frame = ring_buffer_start + (psp_write_ptr_reg / rb_frame_size_dw);
2682 /* Check invalid write_frame ptr address */
2683 if ((write_frame < ring_buffer_start) || (ring_buffer_end < write_frame)) {
2684 DRM_ERROR("ring_buffer_start = %p; ring_buffer_end = %p; write_frame = %p\n",
2685 ring_buffer_start, ring_buffer_end, write_frame);
2686 DRM_ERROR("write_frame is pointing to address out of bounds\n");
2690 /* Initialize KM RB frame */
2691 memset(write_frame, 0, sizeof(struct psp_gfx_rb_frame));
2693 /* Update KM RB frame */
2694 write_frame->cmd_buf_addr_hi = upper_32_bits(cmd_buf_mc_addr);
2695 write_frame->cmd_buf_addr_lo = lower_32_bits(cmd_buf_mc_addr);
2696 write_frame->fence_addr_hi = upper_32_bits(fence_mc_addr);
2697 write_frame->fence_addr_lo = lower_32_bits(fence_mc_addr);
2698 write_frame->fence_value = index;
2699 amdgpu_asic_flush_hdp(adev, NULL);
2701 /* Update the write Pointer in DWORDs */
2702 psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) % ring_size_dw;
2703 psp_ring_set_wptr(psp, psp_write_ptr_reg);
2707 int psp_init_asd_microcode(struct psp_context *psp,
2708 const char *chip_name)
2710 struct amdgpu_device *adev = psp->adev;
2711 char fw_name[PSP_FW_NAME_LEN];
2712 const struct psp_firmware_header_v1_0 *asd_hdr;
2716 dev_err(adev->dev, "invalid chip name for asd microcode\n");
2720 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_asd.bin", chip_name);
2721 err = request_firmware(&adev->psp.asd_fw, fw_name, adev->dev);
2725 err = amdgpu_ucode_validate(adev->psp.asd_fw);
2729 asd_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.asd_fw->data;
2730 adev->psp.asd_fw_version = le32_to_cpu(asd_hdr->header.ucode_version);
2731 adev->psp.asd_feature_version = le32_to_cpu(asd_hdr->ucode_feature_version);
2732 adev->psp.asd_ucode_size = le32_to_cpu(asd_hdr->header.ucode_size_bytes);
2733 adev->psp.asd_start_addr = (uint8_t *)asd_hdr +
2734 le32_to_cpu(asd_hdr->header.ucode_array_offset_bytes);
2737 dev_err(adev->dev, "fail to initialize asd microcode\n");
2738 release_firmware(adev->psp.asd_fw);
2739 adev->psp.asd_fw = NULL;
2743 int psp_init_toc_microcode(struct psp_context *psp,
2744 const char *chip_name)
2746 struct amdgpu_device *adev = psp->adev;
2748 const struct psp_firmware_header_v1_0 *toc_hdr;
2752 dev_err(adev->dev, "invalid chip name for toc microcode\n");
2756 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_toc.bin", chip_name);
2757 err = request_firmware(&adev->psp.toc_fw, fw_name, adev->dev);
2761 err = amdgpu_ucode_validate(adev->psp.toc_fw);
2765 toc_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.toc_fw->data;
2766 adev->psp.toc_fw_version = le32_to_cpu(toc_hdr->header.ucode_version);
2767 adev->psp.toc_feature_version = le32_to_cpu(toc_hdr->ucode_feature_version);
2768 adev->psp.toc_bin_size = le32_to_cpu(toc_hdr->header.ucode_size_bytes);
2769 adev->psp.toc_start_addr = (uint8_t *)toc_hdr +
2770 le32_to_cpu(toc_hdr->header.ucode_array_offset_bytes);
2773 dev_err(adev->dev, "fail to request/validate toc microcode\n");
2774 release_firmware(adev->psp.toc_fw);
2775 adev->psp.toc_fw = NULL;
2779 int psp_init_sos_microcode(struct psp_context *psp,
2780 const char *chip_name)
2782 struct amdgpu_device *adev = psp->adev;
2783 char fw_name[PSP_FW_NAME_LEN];
2784 const struct psp_firmware_header_v1_0 *sos_hdr;
2785 const struct psp_firmware_header_v1_1 *sos_hdr_v1_1;
2786 const struct psp_firmware_header_v1_2 *sos_hdr_v1_2;
2787 const struct psp_firmware_header_v1_3 *sos_hdr_v1_3;
2791 dev_err(adev->dev, "invalid chip name for sos microcode\n");
2795 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_sos.bin", chip_name);
2796 err = request_firmware(&adev->psp.sos_fw, fw_name, adev->dev);
2800 err = amdgpu_ucode_validate(adev->psp.sos_fw);
2804 sos_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.sos_fw->data;
2805 amdgpu_ucode_print_psp_hdr(&sos_hdr->header);
2807 switch (sos_hdr->header.header_version_major) {
2809 adev->psp.sos_fw_version = le32_to_cpu(sos_hdr->header.ucode_version);
2810 adev->psp.sos_feature_version = le32_to_cpu(sos_hdr->ucode_feature_version);
2811 adev->psp.sos_bin_size = le32_to_cpu(sos_hdr->sos_size_bytes);
2812 adev->psp.sys_bin_size = le32_to_cpu(sos_hdr->sos_offset_bytes);
2813 adev->psp.sys_start_addr = (uint8_t *)sos_hdr +
2814 le32_to_cpu(sos_hdr->header.ucode_array_offset_bytes);
2815 adev->psp.sos_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2816 le32_to_cpu(sos_hdr->sos_offset_bytes);
2817 if (sos_hdr->header.header_version_minor == 1) {
2818 sos_hdr_v1_1 = (const struct psp_firmware_header_v1_1 *)adev->psp.sos_fw->data;
2819 adev->psp.toc_bin_size = le32_to_cpu(sos_hdr_v1_1->toc_size_bytes);
2820 adev->psp.toc_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2821 le32_to_cpu(sos_hdr_v1_1->toc_offset_bytes);
2822 adev->psp.kdb_bin_size = le32_to_cpu(sos_hdr_v1_1->kdb_size_bytes);
2823 adev->psp.kdb_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2824 le32_to_cpu(sos_hdr_v1_1->kdb_offset_bytes);
2826 if (sos_hdr->header.header_version_minor == 2) {
2827 sos_hdr_v1_2 = (const struct psp_firmware_header_v1_2 *)adev->psp.sos_fw->data;
2828 adev->psp.kdb_bin_size = le32_to_cpu(sos_hdr_v1_2->kdb_size_bytes);
2829 adev->psp.kdb_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2830 le32_to_cpu(sos_hdr_v1_2->kdb_offset_bytes);
2832 if (sos_hdr->header.header_version_minor == 3) {
2833 sos_hdr_v1_3 = (const struct psp_firmware_header_v1_3 *)adev->psp.sos_fw->data;
2834 adev->psp.toc_bin_size = le32_to_cpu(sos_hdr_v1_3->v1_1.toc_size_bytes);
2835 adev->psp.toc_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2836 le32_to_cpu(sos_hdr_v1_3->v1_1.toc_offset_bytes);
2837 adev->psp.kdb_bin_size = le32_to_cpu(sos_hdr_v1_3->v1_1.kdb_size_bytes);
2838 adev->psp.kdb_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2839 le32_to_cpu(sos_hdr_v1_3->v1_1.kdb_offset_bytes);
2840 adev->psp.spl_bin_size = le32_to_cpu(sos_hdr_v1_3->spl_size_bytes);
2841 adev->psp.spl_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2842 le32_to_cpu(sos_hdr_v1_3->spl_offset_bytes);
2843 adev->psp.rl_bin_size = le32_to_cpu(sos_hdr_v1_3->rl_size_bytes);
2844 adev->psp.rl_start_addr = (uint8_t *)adev->psp.sys_start_addr +
2845 le32_to_cpu(sos_hdr_v1_3->rl_offset_bytes);
2850 "unsupported psp sos firmware\n");
2858 "failed to init sos firmware\n");
2859 release_firmware(adev->psp.sos_fw);
2860 adev->psp.sos_fw = NULL;
2865 static int parse_ta_bin_descriptor(struct psp_context *psp,
2866 const struct ta_fw_bin_desc *desc,
2867 const struct ta_firmware_header_v2_0 *ta_hdr)
2869 uint8_t *ucode_start_addr = NULL;
2871 if (!psp || !desc || !ta_hdr)
2874 ucode_start_addr = (uint8_t *)ta_hdr +
2875 le32_to_cpu(desc->offset_bytes) +
2876 le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
2878 switch (desc->fw_type) {
2879 case TA_FW_TYPE_PSP_ASD:
2880 psp->asd_fw_version = le32_to_cpu(desc->fw_version);
2881 psp->asd_feature_version = le32_to_cpu(desc->fw_version);
2882 psp->asd_ucode_size = le32_to_cpu(desc->size_bytes);
2883 psp->asd_start_addr = ucode_start_addr;
2885 case TA_FW_TYPE_PSP_XGMI:
2886 psp->ta_xgmi_ucode_version = le32_to_cpu(desc->fw_version);
2887 psp->ta_xgmi_ucode_size = le32_to_cpu(desc->size_bytes);
2888 psp->ta_xgmi_start_addr = ucode_start_addr;
2890 case TA_FW_TYPE_PSP_RAS:
2891 psp->ta_ras_ucode_version = le32_to_cpu(desc->fw_version);
2892 psp->ta_ras_ucode_size = le32_to_cpu(desc->size_bytes);
2893 psp->ta_ras_start_addr = ucode_start_addr;
2895 case TA_FW_TYPE_PSP_HDCP:
2896 psp->ta_hdcp_ucode_version = le32_to_cpu(desc->fw_version);
2897 psp->ta_hdcp_ucode_size = le32_to_cpu(desc->size_bytes);
2898 psp->ta_hdcp_start_addr = ucode_start_addr;
2900 case TA_FW_TYPE_PSP_DTM:
2901 psp->ta_dtm_ucode_version = le32_to_cpu(desc->fw_version);
2902 psp->ta_dtm_ucode_size = le32_to_cpu(desc->size_bytes);
2903 psp->ta_dtm_start_addr = ucode_start_addr;
2905 case TA_FW_TYPE_PSP_RAP:
2906 psp->ta_rap_ucode_version = le32_to_cpu(desc->fw_version);
2907 psp->ta_rap_ucode_size = le32_to_cpu(desc->size_bytes);
2908 psp->ta_rap_start_addr = ucode_start_addr;
2910 case TA_FW_TYPE_PSP_SECUREDISPLAY:
2911 psp->ta_securedisplay_ucode_version = le32_to_cpu(desc->fw_version);
2912 psp->ta_securedisplay_ucode_size = le32_to_cpu(desc->size_bytes);
2913 psp->ta_securedisplay_start_addr = ucode_start_addr;
2916 dev_warn(psp->adev->dev, "Unsupported TA type: %d\n", desc->fw_type);
2923 int psp_init_ta_microcode(struct psp_context *psp,
2924 const char *chip_name)
2926 struct amdgpu_device *adev = psp->adev;
2927 char fw_name[PSP_FW_NAME_LEN];
2928 const struct ta_firmware_header_v2_0 *ta_hdr;
2933 dev_err(adev->dev, "invalid chip name for ta microcode\n");
2937 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ta.bin", chip_name);
2938 err = request_firmware(&adev->psp.ta_fw, fw_name, adev->dev);
2942 err = amdgpu_ucode_validate(adev->psp.ta_fw);
2946 ta_hdr = (const struct ta_firmware_header_v2_0 *)adev->psp.ta_fw->data;
2948 if (le16_to_cpu(ta_hdr->header.header_version_major) != 2) {
2949 dev_err(adev->dev, "unsupported TA header version\n");
2954 if (le32_to_cpu(ta_hdr->ta_fw_bin_count) >= UCODE_MAX_TA_PACKAGING) {
2955 dev_err(adev->dev, "packed TA count exceeds maximum limit\n");
2960 for (ta_index = 0; ta_index < le32_to_cpu(ta_hdr->ta_fw_bin_count); ta_index++) {
2961 err = parse_ta_bin_descriptor(psp,
2962 &ta_hdr->ta_fw_bin[ta_index],
2970 dev_err(adev->dev, "fail to initialize ta microcode\n");
2971 release_firmware(adev->psp.ta_fw);
2972 adev->psp.ta_fw = NULL;
2976 static int psp_set_clockgating_state(void *handle,
2977 enum amd_clockgating_state state)
2982 static int psp_set_powergating_state(void *handle,
2983 enum amd_powergating_state state)
2988 static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev,
2989 struct device_attribute *attr,
2992 struct drm_device *ddev = dev_get_drvdata(dev);
2993 struct amdgpu_device *adev = drm_to_adev(ddev);
2997 if (!adev->ip_blocks[AMD_IP_BLOCK_TYPE_PSP].status.late_initialized) {
2998 DRM_INFO("PSP block is not ready yet.");
3002 mutex_lock(&adev->psp.mutex);
3003 ret = psp_read_usbc_pd_fw(&adev->psp, &fw_ver);
3004 mutex_unlock(&adev->psp.mutex);
3007 DRM_ERROR("Failed to read USBC PD FW, err = %d", ret);
3011 return sysfs_emit(buf, "%x\n", fw_ver);
3014 static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,
3015 struct device_attribute *attr,
3019 struct drm_device *ddev = dev_get_drvdata(dev);
3020 struct amdgpu_device *adev = drm_to_adev(ddev);
3022 dma_addr_t dma_addr;
3025 const struct firmware *usbc_pd_fw;
3027 if (!adev->ip_blocks[AMD_IP_BLOCK_TYPE_PSP].status.late_initialized) {
3028 DRM_INFO("PSP block is not ready yet.");
3032 snprintf(fw_name, sizeof(fw_name), "amdgpu/%s", buf);
3033 ret = request_firmware(&usbc_pd_fw, fw_name, adev->dev);
3037 /* We need contiguous physical mem to place the FW for psp to access */
3038 cpu_addr = dma_alloc_coherent(adev->dev, usbc_pd_fw->size, &dma_addr, GFP_KERNEL);
3040 ret = dma_mapping_error(adev->dev, dma_addr);
3044 memcpy_toio(cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);
3047 * x86 specific workaround.
3048 * Without it the buffer is invisible in PSP.
3050 * TODO Remove once PSP starts snooping CPU cache
3053 clflush_cache_range(cpu_addr, (usbc_pd_fw->size & ~(L1_CACHE_BYTES - 1)));
3056 mutex_lock(&adev->psp.mutex);
3057 ret = psp_load_usbc_pd_fw(&adev->psp, dma_addr);
3058 mutex_unlock(&adev->psp.mutex);
3061 dma_free_coherent(adev->dev, usbc_pd_fw->size, cpu_addr, dma_addr);
3062 release_firmware(usbc_pd_fw);
3066 DRM_ERROR("Failed to load USBC PD FW, err = %d", ret);
3073 static DEVICE_ATTR(usbc_pd_fw, S_IRUGO | S_IWUSR,
3074 psp_usbc_pd_fw_sysfs_read,
3075 psp_usbc_pd_fw_sysfs_write);
3079 const struct amd_ip_funcs psp_ip_funcs = {
3081 .early_init = psp_early_init,
3083 .sw_init = psp_sw_init,
3084 .sw_fini = psp_sw_fini,
3085 .hw_init = psp_hw_init,
3086 .hw_fini = psp_hw_fini,
3087 .suspend = psp_suspend,
3088 .resume = psp_resume,
3090 .check_soft_reset = NULL,
3091 .wait_for_idle = NULL,
3093 .set_clockgating_state = psp_set_clockgating_state,
3094 .set_powergating_state = psp_set_powergating_state,
3097 static int psp_sysfs_init(struct amdgpu_device *adev)
3099 int ret = device_create_file(adev->dev, &dev_attr_usbc_pd_fw);
3102 DRM_ERROR("Failed to create USBC PD FW control file!");
3107 static void psp_sysfs_fini(struct amdgpu_device *adev)
3109 device_remove_file(adev->dev, &dev_attr_usbc_pd_fw);
3112 const struct amdgpu_ip_block_version psp_v3_1_ip_block =
3114 .type = AMD_IP_BLOCK_TYPE_PSP,
3118 .funcs = &psp_ip_funcs,
3121 const struct amdgpu_ip_block_version psp_v10_0_ip_block =
3123 .type = AMD_IP_BLOCK_TYPE_PSP,
3127 .funcs = &psp_ip_funcs,
3130 const struct amdgpu_ip_block_version psp_v11_0_ip_block =
3132 .type = AMD_IP_BLOCK_TYPE_PSP,
3136 .funcs = &psp_ip_funcs,
3139 const struct amdgpu_ip_block_version psp_v12_0_ip_block =
3141 .type = AMD_IP_BLOCK_TYPE_PSP,
3145 .funcs = &psp_ip_funcs,
3148 const struct amdgpu_ip_block_version psp_v13_0_ip_block = {
3149 .type = AMD_IP_BLOCK_TYPE_PSP,
3153 .funcs = &psp_ip_funcs,