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 <drm/drm_drv.h>
30 #include "amdgpu_psp.h"
31 #include "amdgpu_ucode.h"
32 #include "amdgpu_xgmi.h"
33 #include "soc15_common.h"
35 #include "psp_v10_0.h"
36 #include "psp_v11_0.h"
37 #include "psp_v11_0_8.h"
38 #include "psp_v12_0.h"
39 #include "psp_v13_0.h"
40 #include "psp_v13_0_4.h"
41 #include "psp_v14_0.h"
43 #include "amdgpu_ras.h"
44 #include "amdgpu_securedisplay.h"
45 #include "amdgpu_atomfirmware.h"
47 #define AMD_VBIOS_FILE_MAX_SIZE_B (1024*1024*3)
49 static int psp_load_smu_fw(struct psp_context *psp);
50 static int psp_rap_terminate(struct psp_context *psp);
51 static int psp_securedisplay_terminate(struct psp_context *psp);
53 static int psp_ring_init(struct psp_context *psp,
54 enum psp_ring_type ring_type)
57 struct psp_ring *ring;
58 struct amdgpu_device *adev = psp->adev;
62 ring->ring_type = ring_type;
64 /* allocate 4k Page of Local Frame Buffer memory for ring */
65 ring->ring_size = 0x1000;
66 ret = amdgpu_bo_create_kernel(adev, ring->ring_size, PAGE_SIZE,
67 AMDGPU_GEM_DOMAIN_VRAM |
68 AMDGPU_GEM_DOMAIN_GTT,
70 &ring->ring_mem_mc_addr,
71 (void **)&ring->ring_mem);
81 * Due to DF Cstate management centralized to PMFW, the firmware
82 * loading sequence will be updated as below:
88 * - Load other non-psp fw
90 * - Load XGMI/RAS/HDCP/DTM TA if any
92 * This new sequence is required for
93 * - Arcturus and onwards
95 static void psp_check_pmfw_centralized_cstate_management(struct psp_context *psp)
97 struct amdgpu_device *adev = psp->adev;
99 if (amdgpu_sriov_vf(adev)) {
100 psp->pmfw_centralized_cstate_management = false;
104 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
105 case IP_VERSION(11, 0, 0):
106 case IP_VERSION(11, 0, 4):
107 case IP_VERSION(11, 0, 5):
108 case IP_VERSION(11, 0, 7):
109 case IP_VERSION(11, 0, 9):
110 case IP_VERSION(11, 0, 11):
111 case IP_VERSION(11, 0, 12):
112 case IP_VERSION(11, 0, 13):
113 case IP_VERSION(13, 0, 0):
114 case IP_VERSION(13, 0, 2):
115 case IP_VERSION(13, 0, 7):
116 psp->pmfw_centralized_cstate_management = true;
119 psp->pmfw_centralized_cstate_management = false;
124 static int psp_init_sriov_microcode(struct psp_context *psp)
126 struct amdgpu_device *adev = psp->adev;
127 char ucode_prefix[30];
130 amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));
132 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
133 case IP_VERSION(9, 0, 0):
134 case IP_VERSION(11, 0, 7):
135 case IP_VERSION(11, 0, 9):
136 adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
137 ret = psp_init_cap_microcode(psp, ucode_prefix);
139 case IP_VERSION(13, 0, 2):
140 adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
141 ret = psp_init_cap_microcode(psp, ucode_prefix);
142 ret &= psp_init_ta_microcode(psp, ucode_prefix);
144 case IP_VERSION(13, 0, 0):
145 adev->virt.autoload_ucode_id = 0;
147 case IP_VERSION(13, 0, 6):
148 case IP_VERSION(13, 0, 14):
149 ret = psp_init_cap_microcode(psp, ucode_prefix);
150 ret &= psp_init_ta_microcode(psp, ucode_prefix);
152 case IP_VERSION(13, 0, 10):
153 adev->virt.autoload_ucode_id = AMDGPU_UCODE_ID_CP_MES1_DATA;
154 ret = psp_init_cap_microcode(psp, ucode_prefix);
162 static int psp_early_init(struct amdgpu_ip_block *ip_block)
164 struct amdgpu_device *adev = ip_block->adev;
165 struct psp_context *psp = &adev->psp;
167 psp->autoload_supported = true;
168 psp->boot_time_tmr = true;
170 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
171 case IP_VERSION(9, 0, 0):
172 psp_v3_1_set_psp_funcs(psp);
173 psp->autoload_supported = false;
174 psp->boot_time_tmr = false;
176 case IP_VERSION(10, 0, 0):
177 case IP_VERSION(10, 0, 1):
178 psp_v10_0_set_psp_funcs(psp);
179 psp->autoload_supported = false;
180 psp->boot_time_tmr = false;
182 case IP_VERSION(11, 0, 2):
183 case IP_VERSION(11, 0, 4):
184 psp_v11_0_set_psp_funcs(psp);
185 psp->autoload_supported = false;
186 psp->boot_time_tmr = false;
188 case IP_VERSION(11, 0, 0):
189 case IP_VERSION(11, 0, 7):
190 adev->psp.sup_pd_fw_up = !amdgpu_sriov_vf(adev);
192 case IP_VERSION(11, 0, 5):
193 case IP_VERSION(11, 0, 9):
194 case IP_VERSION(11, 0, 11):
195 case IP_VERSION(11, 5, 0):
196 case IP_VERSION(11, 0, 12):
197 case IP_VERSION(11, 0, 13):
198 psp_v11_0_set_psp_funcs(psp);
199 psp->boot_time_tmr = false;
201 case IP_VERSION(11, 0, 3):
202 case IP_VERSION(12, 0, 1):
203 psp_v12_0_set_psp_funcs(psp);
204 psp->autoload_supported = false;
205 psp->boot_time_tmr = false;
207 case IP_VERSION(13, 0, 2):
208 psp->boot_time_tmr = false;
210 case IP_VERSION(13, 0, 6):
211 case IP_VERSION(13, 0, 12):
212 case IP_VERSION(13, 0, 14):
213 psp_v13_0_set_psp_funcs(psp);
214 psp->autoload_supported = false;
216 case IP_VERSION(13, 0, 1):
217 case IP_VERSION(13, 0, 3):
218 case IP_VERSION(13, 0, 5):
219 case IP_VERSION(13, 0, 8):
220 case IP_VERSION(13, 0, 11):
221 case IP_VERSION(14, 0, 0):
222 case IP_VERSION(14, 0, 1):
223 case IP_VERSION(14, 0, 4):
224 psp_v13_0_set_psp_funcs(psp);
225 psp->boot_time_tmr = false;
227 case IP_VERSION(11, 0, 8):
228 if (adev->apu_flags & AMD_APU_IS_CYAN_SKILLFISH2) {
229 psp_v11_0_8_set_psp_funcs(psp);
231 psp->autoload_supported = false;
232 psp->boot_time_tmr = false;
234 case IP_VERSION(13, 0, 0):
235 case IP_VERSION(13, 0, 7):
236 case IP_VERSION(13, 0, 10):
237 psp_v13_0_set_psp_funcs(psp);
238 adev->psp.sup_ifwi_up = !amdgpu_sriov_vf(adev);
239 psp->boot_time_tmr = false;
241 case IP_VERSION(13, 0, 4):
242 psp_v13_0_4_set_psp_funcs(psp);
243 psp->boot_time_tmr = false;
245 case IP_VERSION(14, 0, 2):
246 case IP_VERSION(14, 0, 3):
247 psp_v14_0_set_psp_funcs(psp);
255 adev->psp_timeout = 20000;
257 psp_check_pmfw_centralized_cstate_management(psp);
259 if (amdgpu_sriov_vf(adev))
260 return psp_init_sriov_microcode(psp);
262 return psp_init_microcode(psp);
265 void psp_ta_free_shared_buf(struct ta_mem_context *mem_ctx)
267 amdgpu_bo_free_kernel(&mem_ctx->shared_bo, &mem_ctx->shared_mc_addr,
268 &mem_ctx->shared_buf);
269 mem_ctx->shared_bo = NULL;
272 static void psp_free_shared_bufs(struct psp_context *psp)
277 /* free TMR memory buffer */
278 pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
279 amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
282 /* free xgmi shared memory */
283 psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context);
285 /* free ras shared memory */
286 psp_ta_free_shared_buf(&psp->ras_context.context.mem_context);
288 /* free hdcp shared memory */
289 psp_ta_free_shared_buf(&psp->hdcp_context.context.mem_context);
291 /* free dtm shared memory */
292 psp_ta_free_shared_buf(&psp->dtm_context.context.mem_context);
294 /* free rap shared memory */
295 psp_ta_free_shared_buf(&psp->rap_context.context.mem_context);
297 /* free securedisplay shared memory */
298 psp_ta_free_shared_buf(&psp->securedisplay_context.context.mem_context);
303 static void psp_memory_training_fini(struct psp_context *psp)
305 struct psp_memory_training_context *ctx = &psp->mem_train_ctx;
307 ctx->init = PSP_MEM_TRAIN_NOT_SUPPORT;
308 kfree(ctx->sys_cache);
309 ctx->sys_cache = NULL;
312 static int psp_memory_training_init(struct psp_context *psp)
315 struct psp_memory_training_context *ctx = &psp->mem_train_ctx;
317 if (ctx->init != PSP_MEM_TRAIN_RESERVE_SUCCESS) {
318 dev_dbg(psp->adev->dev, "memory training is not supported!\n");
322 ctx->sys_cache = kzalloc(ctx->train_data_size, GFP_KERNEL);
323 if (ctx->sys_cache == NULL) {
324 dev_err(psp->adev->dev, "alloc mem_train_ctx.sys_cache failed!\n");
329 dev_dbg(psp->adev->dev,
330 "train_data_size:%llx,p2c_train_data_offset:%llx,c2p_train_data_offset:%llx.\n",
331 ctx->train_data_size,
332 ctx->p2c_train_data_offset,
333 ctx->c2p_train_data_offset);
334 ctx->init = PSP_MEM_TRAIN_INIT_SUCCESS;
338 psp_memory_training_fini(psp);
343 * Helper funciton to query psp runtime database entry
345 * @adev: amdgpu_device pointer
346 * @entry_type: the type of psp runtime database entry
347 * @db_entry: runtime database entry pointer
349 * Return false if runtime database doesn't exit or entry is invalid
350 * or true if the specific database entry is found, and copy to @db_entry
352 static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,
353 enum psp_runtime_entry_type entry_type,
356 uint64_t db_header_pos, db_dir_pos;
357 struct psp_runtime_data_header db_header = {0};
358 struct psp_runtime_data_directory db_dir = {0};
362 if (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 6) ||
363 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 12) ||
364 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 14))
367 db_header_pos = adev->gmc.mc_vram_size - PSP_RUNTIME_DB_OFFSET;
368 db_dir_pos = db_header_pos + sizeof(struct psp_runtime_data_header);
370 /* read runtime db header from vram */
371 amdgpu_device_vram_access(adev, db_header_pos, (uint32_t *)&db_header,
372 sizeof(struct psp_runtime_data_header), false);
374 if (db_header.cookie != PSP_RUNTIME_DB_COOKIE_ID) {
375 /* runtime db doesn't exist, exit */
376 dev_dbg(adev->dev, "PSP runtime database doesn't exist\n");
380 /* read runtime database entry from vram */
381 amdgpu_device_vram_access(adev, db_dir_pos, (uint32_t *)&db_dir,
382 sizeof(struct psp_runtime_data_directory), false);
384 if (db_dir.entry_count >= PSP_RUNTIME_DB_DIAG_ENTRY_MAX_COUNT) {
385 /* invalid db entry count, exit */
386 dev_warn(adev->dev, "Invalid PSP runtime database entry count\n");
390 /* look up for requested entry type */
391 for (i = 0; i < db_dir.entry_count && !ret; i++) {
392 if (db_dir.entry_list[i].entry_type == entry_type) {
393 switch (entry_type) {
394 case PSP_RUNTIME_ENTRY_TYPE_BOOT_CONFIG:
395 if (db_dir.entry_list[i].size < sizeof(struct psp_runtime_boot_cfg_entry)) {
396 /* invalid db entry size */
397 dev_warn(adev->dev, "Invalid PSP runtime database boot cfg entry size\n");
400 /* read runtime database entry */
401 amdgpu_device_vram_access(adev, db_header_pos + db_dir.entry_list[i].offset,
402 (uint32_t *)db_entry, sizeof(struct psp_runtime_boot_cfg_entry), false);
405 case PSP_RUNTIME_ENTRY_TYPE_PPTABLE_ERR_STATUS:
406 if (db_dir.entry_list[i].size < sizeof(struct psp_runtime_scpm_entry)) {
407 /* invalid db entry size */
408 dev_warn(adev->dev, "Invalid PSP runtime database scpm entry size\n");
411 /* read runtime database entry */
412 amdgpu_device_vram_access(adev, db_header_pos + db_dir.entry_list[i].offset,
413 (uint32_t *)db_entry, sizeof(struct psp_runtime_scpm_entry), false);
426 static int psp_sw_init(struct amdgpu_ip_block *ip_block)
428 struct amdgpu_device *adev = ip_block->adev;
429 struct psp_context *psp = &adev->psp;
431 struct psp_runtime_boot_cfg_entry boot_cfg_entry;
432 struct psp_memory_training_context *mem_training_ctx = &psp->mem_train_ctx;
433 struct psp_runtime_scpm_entry scpm_entry;
435 psp->cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
437 dev_err(adev->dev, "Failed to allocate memory to command buffer!\n");
441 adev->psp.xgmi_context.supports_extended_data =
442 !adev->gmc.xgmi.connected_to_cpu &&
443 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 2);
445 memset(&scpm_entry, 0, sizeof(scpm_entry));
446 if ((psp_get_runtime_db_entry(adev,
447 PSP_RUNTIME_ENTRY_TYPE_PPTABLE_ERR_STATUS,
449 (scpm_entry.scpm_status != SCPM_DISABLE)) {
450 adev->scpm_enabled = true;
451 adev->scpm_status = scpm_entry.scpm_status;
453 adev->scpm_enabled = false;
454 adev->scpm_status = SCPM_DISABLE;
457 /* TODO: stop gpu driver services and print alarm if scpm is enabled with error status */
459 memset(&boot_cfg_entry, 0, sizeof(boot_cfg_entry));
460 if (psp_get_runtime_db_entry(adev,
461 PSP_RUNTIME_ENTRY_TYPE_BOOT_CONFIG,
463 psp->boot_cfg_bitmask = boot_cfg_entry.boot_cfg_bitmask;
464 if ((psp->boot_cfg_bitmask) &
465 BOOT_CFG_FEATURE_TWO_STAGE_DRAM_TRAINING) {
466 /* If psp runtime database exists, then
467 * only enable two stage memory training
468 * when TWO_STAGE_DRAM_TRAINING bit is set
469 * in runtime database
471 mem_training_ctx->enable_mem_training = true;
475 /* If psp runtime database doesn't exist or is
476 * invalid, force enable two stage memory training
478 mem_training_ctx->enable_mem_training = true;
481 if (mem_training_ctx->enable_mem_training) {
482 ret = psp_memory_training_init(psp);
484 dev_err(adev->dev, "Failed to initialize memory training!\n");
488 ret = psp_mem_training(psp, PSP_MEM_TRAIN_COLD_BOOT);
490 dev_err(adev->dev, "Failed to process memory training!\n");
495 ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG,
496 (amdgpu_sriov_vf(adev) || adev->debug_use_vram_fw_buf) ?
497 AMDGPU_GEM_DOMAIN_VRAM : AMDGPU_GEM_DOMAIN_GTT,
499 &psp->fw_pri_mc_addr,
504 ret = amdgpu_bo_create_kernel(adev, PSP_FENCE_BUFFER_SIZE, PAGE_SIZE,
505 AMDGPU_GEM_DOMAIN_VRAM |
506 AMDGPU_GEM_DOMAIN_GTT,
508 &psp->fence_buf_mc_addr,
513 ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
514 AMDGPU_GEM_DOMAIN_VRAM |
515 AMDGPU_GEM_DOMAIN_GTT,
516 &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
517 (void **)&psp->cmd_buf_mem);
524 amdgpu_bo_free_kernel(&psp->fence_buf_bo,
525 &psp->fence_buf_mc_addr, &psp->fence_buf);
527 amdgpu_bo_free_kernel(&psp->fw_pri_bo,
528 &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
532 static int psp_sw_fini(struct amdgpu_ip_block *ip_block)
534 struct amdgpu_device *adev = ip_block->adev;
535 struct psp_context *psp = &adev->psp;
536 struct psp_gfx_cmd_resp *cmd = psp->cmd;
538 psp_memory_training_fini(psp);
540 amdgpu_ucode_release(&psp->sos_fw);
541 amdgpu_ucode_release(&psp->asd_fw);
542 amdgpu_ucode_release(&psp->ta_fw);
543 amdgpu_ucode_release(&psp->cap_fw);
544 amdgpu_ucode_release(&psp->toc_fw);
549 psp_free_shared_bufs(psp);
551 if (psp->km_ring.ring_mem)
552 amdgpu_bo_free_kernel(&adev->firmware.rbuf,
553 &psp->km_ring.ring_mem_mc_addr,
554 (void **)&psp->km_ring.ring_mem);
556 amdgpu_bo_free_kernel(&psp->fw_pri_bo,
557 &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
558 amdgpu_bo_free_kernel(&psp->fence_buf_bo,
559 &psp->fence_buf_mc_addr, &psp->fence_buf);
560 amdgpu_bo_free_kernel(&psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
561 (void **)&psp->cmd_buf_mem);
566 int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
567 uint32_t reg_val, uint32_t mask, bool check_changed)
571 struct amdgpu_device *adev = psp->adev;
573 if (psp->adev->no_hw_access)
576 for (i = 0; i < adev->usec_timeout; i++) {
577 val = RREG32(reg_index);
582 if ((val & mask) == reg_val)
591 int psp_wait_for_spirom_update(struct psp_context *psp, uint32_t reg_index,
592 uint32_t reg_val, uint32_t mask, uint32_t msec_timeout)
596 struct amdgpu_device *adev = psp->adev;
598 if (psp->adev->no_hw_access)
601 for (i = 0; i < msec_timeout; i++) {
602 val = RREG32(reg_index);
603 if ((val & mask) == reg_val)
611 static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id cmd_id)
614 case GFX_CMD_ID_LOAD_TA:
616 case GFX_CMD_ID_UNLOAD_TA:
618 case GFX_CMD_ID_INVOKE_CMD:
620 case GFX_CMD_ID_LOAD_ASD:
622 case GFX_CMD_ID_SETUP_TMR:
624 case GFX_CMD_ID_LOAD_IP_FW:
626 case GFX_CMD_ID_DESTROY_TMR:
627 return "DESTROY_TMR";
628 case GFX_CMD_ID_SAVE_RESTORE:
629 return "SAVE_RESTORE_IP_FW";
630 case GFX_CMD_ID_SETUP_VMR:
632 case GFX_CMD_ID_DESTROY_VMR:
633 return "DESTROY_VMR";
634 case GFX_CMD_ID_PROG_REG:
636 case GFX_CMD_ID_GET_FW_ATTESTATION:
637 return "GET_FW_ATTESTATION";
638 case GFX_CMD_ID_LOAD_TOC:
639 return "ID_LOAD_TOC";
640 case GFX_CMD_ID_AUTOLOAD_RLC:
641 return "AUTOLOAD_RLC";
642 case GFX_CMD_ID_BOOT_CFG:
644 case GFX_CMD_ID_CONFIG_SQ_PERFMON:
645 return "CONFIG_SQ_PERFMON";
647 return "UNKNOWN CMD";
651 static bool psp_err_warn(struct psp_context *psp)
653 struct psp_gfx_cmd_resp *cmd = psp->cmd_buf_mem;
655 /* This response indicates reg list is already loaded */
656 if (amdgpu_ip_version(psp->adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 2) &&
657 cmd->cmd_id == GFX_CMD_ID_LOAD_IP_FW &&
658 cmd->cmd.cmd_load_ip_fw.fw_type == GFX_FW_TYPE_REG_LIST &&
659 cmd->resp.status == TEE_ERROR_CANCEL)
666 psp_cmd_submit_buf(struct psp_context *psp,
667 struct amdgpu_firmware_info *ucode,
668 struct psp_gfx_cmd_resp *cmd, uint64_t fence_mc_addr)
672 int timeout = psp->adev->psp_timeout;
673 bool ras_intr = false;
674 bool skip_unsupport = false;
676 if (psp->adev->no_hw_access)
679 memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
681 memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
683 index = atomic_inc_return(&psp->fence_value);
684 ret = psp_ring_cmd_submit(psp, psp->cmd_buf_mc_addr, fence_mc_addr, index);
686 atomic_dec(&psp->fence_value);
690 amdgpu_device_invalidate_hdp(psp->adev, NULL);
691 while (*((unsigned int *)psp->fence_buf) != index) {
695 * Shouldn't wait for timeout when err_event_athub occurs,
696 * because gpu reset thread triggered and lock resource should
697 * be released for psp resume sequence.
699 ras_intr = amdgpu_ras_intr_triggered();
702 usleep_range(10, 100);
703 amdgpu_device_invalidate_hdp(psp->adev, NULL);
706 /* We allow TEE_ERROR_NOT_SUPPORTED for VMR command and PSP_ERR_UNKNOWN_COMMAND in SRIOV */
707 skip_unsupport = (psp->cmd_buf_mem->resp.status == TEE_ERROR_NOT_SUPPORTED ||
708 psp->cmd_buf_mem->resp.status == PSP_ERR_UNKNOWN_COMMAND) && amdgpu_sriov_vf(psp->adev);
710 memcpy(&cmd->resp, &psp->cmd_buf_mem->resp, sizeof(struct psp_gfx_resp));
712 /* In some cases, psp response status is not 0 even there is no
713 * problem while the command is submitted. Some version of PSP FW
714 * doesn't write 0 to that field.
715 * So here we would like to only print a warning instead of an error
716 * during psp initialization to avoid breaking hw_init and it doesn't
719 if (!skip_unsupport && (psp->cmd_buf_mem->resp.status || !timeout) && !ras_intr) {
721 dev_warn(psp->adev->dev,
722 "failed to load ucode %s(0x%X) ",
723 amdgpu_ucode_name(ucode->ucode_id), ucode->ucode_id);
724 if (psp_err_warn(psp))
727 "psp gfx command %s(0x%X) failed and response status is (0x%X)\n",
728 psp_gfx_cmd_name(psp->cmd_buf_mem->cmd_id),
729 psp->cmd_buf_mem->cmd_id,
730 psp->cmd_buf_mem->resp.status);
731 /* If any firmware (including CAP) load fails under SRIOV, it should
732 * return failure to stop the VF from initializing.
733 * Also return failure in case of timeout
735 if ((ucode && amdgpu_sriov_vf(psp->adev)) || !timeout) {
742 ucode->tmr_mc_addr_lo = psp->cmd_buf_mem->resp.fw_addr_lo;
743 ucode->tmr_mc_addr_hi = psp->cmd_buf_mem->resp.fw_addr_hi;
750 static struct psp_gfx_cmd_resp *acquire_psp_cmd_buf(struct psp_context *psp)
752 struct psp_gfx_cmd_resp *cmd = psp->cmd;
754 mutex_lock(&psp->mutex);
756 memset(cmd, 0, sizeof(struct psp_gfx_cmd_resp));
761 static void release_psp_cmd_buf(struct psp_context *psp)
763 mutex_unlock(&psp->mutex);
766 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
767 struct psp_gfx_cmd_resp *cmd,
768 uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
770 struct amdgpu_device *adev = psp->adev;
775 size = amdgpu_bo_size(tmr_bo);
776 tmr_pa = amdgpu_gmc_vram_pa(adev, tmr_bo);
779 if (amdgpu_sriov_vf(psp->adev))
780 cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
782 cmd->cmd_id = GFX_CMD_ID_SETUP_TMR;
783 cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
784 cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
785 cmd->cmd.cmd_setup_tmr.buf_size = size;
786 cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
787 cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
788 cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
791 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
792 uint64_t pri_buf_mc, uint32_t size)
794 cmd->cmd_id = GFX_CMD_ID_LOAD_TOC;
795 cmd->cmd.cmd_load_toc.toc_phy_addr_lo = lower_32_bits(pri_buf_mc);
796 cmd->cmd.cmd_load_toc.toc_phy_addr_hi = upper_32_bits(pri_buf_mc);
797 cmd->cmd.cmd_load_toc.toc_size = size;
800 /* Issue LOAD TOC cmd to PSP to part toc and calculate tmr size needed */
801 static int psp_load_toc(struct psp_context *psp,
805 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
807 /* Copy toc to psp firmware private buffer */
808 psp_copy_fw(psp, psp->toc.start_addr, psp->toc.size_bytes);
810 psp_prep_load_toc_cmd_buf(cmd, psp->fw_pri_mc_addr, psp->toc.size_bytes);
812 ret = psp_cmd_submit_buf(psp, NULL, cmd,
813 psp->fence_buf_mc_addr);
815 *tmr_size = psp->cmd_buf_mem->resp.tmr_size;
817 release_psp_cmd_buf(psp);
822 /* Set up Trusted Memory Region */
823 static int psp_tmr_init(struct psp_context *psp)
831 * According to HW engineer, they prefer the TMR address be "naturally
832 * aligned" , e.g. the start address be an integer divide of TMR size.
834 * Note: this memory need be reserved till the driver
837 tmr_size = PSP_TMR_SIZE(psp->adev);
839 /* For ASICs support RLC autoload, psp will parse the toc
840 * and calculate the total size of TMR needed
842 if (!amdgpu_sriov_vf(psp->adev) &&
843 psp->toc.start_addr &&
844 psp->toc.size_bytes &&
846 ret = psp_load_toc(psp, &tmr_size);
848 dev_err(psp->adev->dev, "Failed to load toc\n");
853 if (!psp->tmr_bo && !psp->boot_time_tmr) {
854 pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
855 ret = amdgpu_bo_create_kernel(psp->adev, tmr_size,
857 AMDGPU_HAS_VRAM(psp->adev) ?
858 AMDGPU_GEM_DOMAIN_VRAM :
859 AMDGPU_GEM_DOMAIN_GTT,
860 &psp->tmr_bo, &psp->tmr_mc_addr,
867 static bool psp_skip_tmr(struct psp_context *psp)
869 switch (amdgpu_ip_version(psp->adev, MP0_HWIP, 0)) {
870 case IP_VERSION(11, 0, 9):
871 case IP_VERSION(11, 0, 7):
872 case IP_VERSION(13, 0, 2):
873 case IP_VERSION(13, 0, 6):
874 case IP_VERSION(13, 0, 10):
875 case IP_VERSION(13, 0, 12):
876 case IP_VERSION(13, 0, 14):
883 static int psp_tmr_load(struct psp_context *psp)
886 struct psp_gfx_cmd_resp *cmd;
888 /* For Navi12 and CHIP_SIENNA_CICHLID SRIOV, do not set up TMR.
889 * Already set up by host driver.
891 if (amdgpu_sriov_vf(psp->adev) && psp_skip_tmr(psp))
894 cmd = acquire_psp_cmd_buf(psp);
896 psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
898 dev_info(psp->adev->dev, "reserve 0x%lx from 0x%llx for PSP TMR\n",
899 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
901 ret = psp_cmd_submit_buf(psp, NULL, cmd,
902 psp->fence_buf_mc_addr);
904 release_psp_cmd_buf(psp);
909 static void psp_prep_tmr_unload_cmd_buf(struct psp_context *psp,
910 struct psp_gfx_cmd_resp *cmd)
912 if (amdgpu_sriov_vf(psp->adev))
913 cmd->cmd_id = GFX_CMD_ID_DESTROY_VMR;
915 cmd->cmd_id = GFX_CMD_ID_DESTROY_TMR;
918 static int psp_tmr_unload(struct psp_context *psp)
921 struct psp_gfx_cmd_resp *cmd;
923 /* skip TMR unload for Navi12 and CHIP_SIENNA_CICHLID SRIOV,
924 * as TMR is not loaded at all
926 if (amdgpu_sriov_vf(psp->adev) && psp_skip_tmr(psp))
929 cmd = acquire_psp_cmd_buf(psp);
931 psp_prep_tmr_unload_cmd_buf(psp, cmd);
932 dev_dbg(psp->adev->dev, "free PSP TMR buffer\n");
934 ret = psp_cmd_submit_buf(psp, NULL, cmd,
935 psp->fence_buf_mc_addr);
937 release_psp_cmd_buf(psp);
942 static int psp_tmr_terminate(struct psp_context *psp)
944 return psp_tmr_unload(psp);
947 int psp_get_fw_attestation_records_addr(struct psp_context *psp,
948 uint64_t *output_ptr)
951 struct psp_gfx_cmd_resp *cmd;
956 if (amdgpu_sriov_vf(psp->adev))
959 cmd = acquire_psp_cmd_buf(psp);
961 cmd->cmd_id = GFX_CMD_ID_GET_FW_ATTESTATION;
963 ret = psp_cmd_submit_buf(psp, NULL, cmd,
964 psp->fence_buf_mc_addr);
967 *output_ptr = ((uint64_t)cmd->resp.uresp.fwar_db_info.fwar_db_addr_lo) +
968 ((uint64_t)cmd->resp.uresp.fwar_db_info.fwar_db_addr_hi << 32);
971 release_psp_cmd_buf(psp);
976 static int psp_boot_config_get(struct amdgpu_device *adev, uint32_t *boot_cfg)
978 struct psp_context *psp = &adev->psp;
979 struct psp_gfx_cmd_resp *cmd;
982 if (amdgpu_sriov_vf(adev))
985 cmd = acquire_psp_cmd_buf(psp);
987 cmd->cmd_id = GFX_CMD_ID_BOOT_CFG;
988 cmd->cmd.boot_cfg.sub_cmd = BOOTCFG_CMD_GET;
990 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
993 (cmd->resp.uresp.boot_cfg.boot_cfg & BOOT_CONFIG_GECC) ? 1 : 0;
996 release_psp_cmd_buf(psp);
1001 static int psp_boot_config_set(struct amdgpu_device *adev, uint32_t boot_cfg)
1004 struct psp_context *psp = &adev->psp;
1005 struct psp_gfx_cmd_resp *cmd;
1007 if (amdgpu_sriov_vf(adev))
1010 cmd = acquire_psp_cmd_buf(psp);
1012 cmd->cmd_id = GFX_CMD_ID_BOOT_CFG;
1013 cmd->cmd.boot_cfg.sub_cmd = BOOTCFG_CMD_SET;
1014 cmd->cmd.boot_cfg.boot_config = boot_cfg;
1015 cmd->cmd.boot_cfg.boot_config_valid = boot_cfg;
1017 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1019 release_psp_cmd_buf(psp);
1024 static int psp_rl_load(struct amdgpu_device *adev)
1027 struct psp_context *psp = &adev->psp;
1028 struct psp_gfx_cmd_resp *cmd;
1030 if (!is_psp_fw_valid(psp->rl))
1033 cmd = acquire_psp_cmd_buf(psp);
1035 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
1036 memcpy(psp->fw_pri_buf, psp->rl.start_addr, psp->rl.size_bytes);
1038 cmd->cmd_id = GFX_CMD_ID_LOAD_IP_FW;
1039 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_lo = lower_32_bits(psp->fw_pri_mc_addr);
1040 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_hi = upper_32_bits(psp->fw_pri_mc_addr);
1041 cmd->cmd.cmd_load_ip_fw.fw_size = psp->rl.size_bytes;
1042 cmd->cmd.cmd_load_ip_fw.fw_type = GFX_FW_TYPE_REG_LIST;
1044 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1046 release_psp_cmd_buf(psp);
1051 int psp_memory_partition(struct psp_context *psp, int mode)
1053 struct psp_gfx_cmd_resp *cmd;
1056 if (amdgpu_sriov_vf(psp->adev))
1059 cmd = acquire_psp_cmd_buf(psp);
1061 cmd->cmd_id = GFX_CMD_ID_FB_NPS_MODE;
1062 cmd->cmd.cmd_memory_part.mode = mode;
1064 dev_info(psp->adev->dev,
1065 "Requesting %d memory partition change through PSP", mode);
1066 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1068 dev_err(psp->adev->dev,
1069 "PSP request failed to change to NPS%d mode\n", mode);
1071 release_psp_cmd_buf(psp);
1076 int psp_spatial_partition(struct psp_context *psp, int mode)
1078 struct psp_gfx_cmd_resp *cmd;
1081 if (amdgpu_sriov_vf(psp->adev))
1084 cmd = acquire_psp_cmd_buf(psp);
1086 cmd->cmd_id = GFX_CMD_ID_SRIOV_SPATIAL_PART;
1087 cmd->cmd.cmd_spatial_part.mode = mode;
1089 dev_info(psp->adev->dev, "Requesting %d partitions through PSP", mode);
1090 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1092 release_psp_cmd_buf(psp);
1097 static int psp_asd_initialize(struct psp_context *psp)
1101 /* If PSP version doesn't match ASD version, asd loading will be failed.
1102 * add workaround to bypass it for sriov now.
1103 * TODO: add version check to make it common
1105 if (amdgpu_sriov_vf(psp->adev) || !psp->asd_context.bin_desc.size_bytes)
1108 /* bypass asd if display hardware is not available */
1109 if (!amdgpu_device_has_display_hardware(psp->adev) &&
1110 amdgpu_ip_version(psp->adev, MP0_HWIP, 0) >= IP_VERSION(13, 0, 10))
1113 psp->asd_context.mem_context.shared_mc_addr = 0;
1114 psp->asd_context.mem_context.shared_mem_size = PSP_ASD_SHARED_MEM_SIZE;
1115 psp->asd_context.ta_load_type = GFX_CMD_ID_LOAD_ASD;
1117 ret = psp_ta_load(psp, &psp->asd_context);
1119 psp->asd_context.initialized = true;
1124 static void psp_prep_ta_unload_cmd_buf(struct psp_gfx_cmd_resp *cmd,
1125 uint32_t session_id)
1127 cmd->cmd_id = GFX_CMD_ID_UNLOAD_TA;
1128 cmd->cmd.cmd_unload_ta.session_id = session_id;
1131 int psp_ta_unload(struct psp_context *psp, struct ta_context *context)
1134 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
1136 psp_prep_ta_unload_cmd_buf(cmd, context->session_id);
1138 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1140 context->resp_status = cmd->resp.status;
1142 release_psp_cmd_buf(psp);
1147 static int psp_asd_terminate(struct psp_context *psp)
1151 if (amdgpu_sriov_vf(psp->adev))
1154 if (!psp->asd_context.initialized)
1157 ret = psp_ta_unload(psp, &psp->asd_context);
1159 psp->asd_context.initialized = false;
1164 static void psp_prep_reg_prog_cmd_buf(struct psp_gfx_cmd_resp *cmd,
1165 uint32_t id, uint32_t value)
1167 cmd->cmd_id = GFX_CMD_ID_PROG_REG;
1168 cmd->cmd.cmd_setup_reg_prog.reg_value = value;
1169 cmd->cmd.cmd_setup_reg_prog.reg_id = id;
1172 int psp_reg_program(struct psp_context *psp, enum psp_reg_prog_id reg,
1175 struct psp_gfx_cmd_resp *cmd;
1178 if (reg >= PSP_REG_LAST)
1181 cmd = acquire_psp_cmd_buf(psp);
1183 psp_prep_reg_prog_cmd_buf(cmd, reg, value);
1184 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
1186 dev_err(psp->adev->dev, "PSP failed to program reg id %d\n", reg);
1188 release_psp_cmd_buf(psp);
1193 static void psp_prep_ta_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
1195 struct ta_context *context)
1197 cmd->cmd_id = context->ta_load_type;
1198 cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(ta_bin_mc);
1199 cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(ta_bin_mc);
1200 cmd->cmd.cmd_load_ta.app_len = context->bin_desc.size_bytes;
1202 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo =
1203 lower_32_bits(context->mem_context.shared_mc_addr);
1204 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi =
1205 upper_32_bits(context->mem_context.shared_mc_addr);
1206 cmd->cmd.cmd_load_ta.cmd_buf_len = context->mem_context.shared_mem_size;
1209 int psp_ta_init_shared_buf(struct psp_context *psp,
1210 struct ta_mem_context *mem_ctx)
1213 * Allocate 16k memory aligned to 4k from Frame Buffer (local
1214 * physical) for ta to host memory
1216 return amdgpu_bo_create_kernel(psp->adev, mem_ctx->shared_mem_size,
1217 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM |
1218 AMDGPU_GEM_DOMAIN_GTT,
1219 &mem_ctx->shared_bo,
1220 &mem_ctx->shared_mc_addr,
1221 &mem_ctx->shared_buf);
1224 static void psp_prep_ta_invoke_cmd_buf(struct psp_gfx_cmd_resp *cmd,
1226 uint32_t session_id)
1228 cmd->cmd_id = GFX_CMD_ID_INVOKE_CMD;
1229 cmd->cmd.cmd_invoke_cmd.session_id = session_id;
1230 cmd->cmd.cmd_invoke_cmd.ta_cmd_id = ta_cmd_id;
1233 int psp_ta_invoke(struct psp_context *psp,
1235 struct ta_context *context)
1238 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
1240 psp_prep_ta_invoke_cmd_buf(cmd, ta_cmd_id, context->session_id);
1242 ret = psp_cmd_submit_buf(psp, NULL, cmd,
1243 psp->fence_buf_mc_addr);
1245 context->resp_status = cmd->resp.status;
1247 release_psp_cmd_buf(psp);
1252 int psp_ta_load(struct psp_context *psp, struct ta_context *context)
1255 struct psp_gfx_cmd_resp *cmd;
1257 cmd = acquire_psp_cmd_buf(psp);
1259 psp_copy_fw(psp, context->bin_desc.start_addr,
1260 context->bin_desc.size_bytes);
1262 psp_prep_ta_load_cmd_buf(cmd, psp->fw_pri_mc_addr, context);
1264 ret = psp_cmd_submit_buf(psp, NULL, cmd,
1265 psp->fence_buf_mc_addr);
1267 context->resp_status = cmd->resp.status;
1270 context->session_id = cmd->resp.session_id;
1272 release_psp_cmd_buf(psp);
1277 int psp_xgmi_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1279 return psp_ta_invoke(psp, ta_cmd_id, &psp->xgmi_context.context);
1282 int psp_xgmi_terminate(struct psp_context *psp)
1285 struct amdgpu_device *adev = psp->adev;
1287 /* XGMI TA unload currently is not supported on Arcturus/Aldebaran A+A */
1288 if (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(11, 0, 4) ||
1289 (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 2) &&
1290 adev->gmc.xgmi.connected_to_cpu))
1293 if (!psp->xgmi_context.context.initialized)
1296 ret = psp_ta_unload(psp, &psp->xgmi_context.context);
1298 psp->xgmi_context.context.initialized = false;
1303 int psp_xgmi_initialize(struct psp_context *psp, bool set_extended_data, bool load_ta)
1305 struct ta_xgmi_shared_memory *xgmi_cmd;
1309 !psp->xgmi_context.context.bin_desc.size_bytes ||
1310 !psp->xgmi_context.context.bin_desc.start_addr)
1316 psp->xgmi_context.context.mem_context.shared_mem_size = PSP_XGMI_SHARED_MEM_SIZE;
1317 psp->xgmi_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
1319 if (!psp->xgmi_context.context.mem_context.shared_buf) {
1320 ret = psp_ta_init_shared_buf(psp, &psp->xgmi_context.context.mem_context);
1326 ret = psp_ta_load(psp, &psp->xgmi_context.context);
1328 psp->xgmi_context.context.initialized = true;
1333 /* Initialize XGMI session */
1334 xgmi_cmd = (struct ta_xgmi_shared_memory *)(psp->xgmi_context.context.mem_context.shared_buf);
1335 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
1336 xgmi_cmd->flag_extend_link_record = set_extended_data;
1337 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__INITIALIZE;
1339 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
1340 /* note down the capbility flag for XGMI TA */
1341 psp->xgmi_context.xgmi_ta_caps = xgmi_cmd->caps_flag;
1346 int psp_xgmi_get_hive_id(struct psp_context *psp, uint64_t *hive_id)
1348 struct ta_xgmi_shared_memory *xgmi_cmd;
1351 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.context.mem_context.shared_buf;
1352 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
1354 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_HIVE_ID;
1356 /* Invoke xgmi ta to get hive id */
1357 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
1361 *hive_id = xgmi_cmd->xgmi_out_message.get_hive_id.hive_id;
1366 int psp_xgmi_get_node_id(struct psp_context *psp, uint64_t *node_id)
1368 struct ta_xgmi_shared_memory *xgmi_cmd;
1371 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.context.mem_context.shared_buf;
1372 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
1374 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_NODE_ID;
1376 /* Invoke xgmi ta to get the node id */
1377 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
1381 *node_id = xgmi_cmd->xgmi_out_message.get_node_id.node_id;
1386 static bool psp_xgmi_peer_link_info_supported(struct psp_context *psp)
1388 return (amdgpu_ip_version(psp->adev, MP0_HWIP, 0) ==
1389 IP_VERSION(13, 0, 2) &&
1390 psp->xgmi_context.context.bin_desc.fw_version >= 0x2000000b) ||
1391 amdgpu_ip_version(psp->adev, MP0_HWIP, 0) >=
1392 IP_VERSION(13, 0, 6);
1396 * Chips that support extended topology information require the driver to
1397 * reflect topology information in the opposite direction. This is
1398 * because the TA has already exceeded its link record limit and if the
1399 * TA holds bi-directional information, the driver would have to do
1400 * multiple fetches instead of just two.
1402 static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
1403 struct psp_xgmi_node_info node_info)
1405 struct amdgpu_device *mirror_adev;
1406 struct amdgpu_hive_info *hive;
1407 uint64_t src_node_id = psp->adev->gmc.xgmi.node_id;
1408 uint64_t dst_node_id = node_info.node_id;
1409 uint8_t dst_num_hops = node_info.num_hops;
1410 uint8_t dst_num_links = node_info.num_links;
1412 hive = amdgpu_get_xgmi_hive(psp->adev);
1416 list_for_each_entry(mirror_adev, &hive->device_list, gmc.xgmi.head) {
1417 struct psp_xgmi_topology_info *mirror_top_info;
1420 if (mirror_adev->gmc.xgmi.node_id != dst_node_id)
1423 mirror_top_info = &mirror_adev->psp.xgmi_context.top_info;
1424 for (j = 0; j < mirror_top_info->num_nodes; j++) {
1425 if (mirror_top_info->nodes[j].node_id != src_node_id)
1428 mirror_top_info->nodes[j].num_hops = dst_num_hops;
1430 * prevent 0 num_links value re-reflection since reflection
1431 * criteria is based on num_hops (direct or indirect).
1435 mirror_top_info->nodes[j].num_links = dst_num_links;
1443 amdgpu_put_xgmi_hive(hive);
1446 int psp_xgmi_get_topology_info(struct psp_context *psp,
1448 struct psp_xgmi_topology_info *topology,
1449 bool get_extended_data)
1451 struct ta_xgmi_shared_memory *xgmi_cmd;
1452 struct ta_xgmi_cmd_get_topology_info_input *topology_info_input;
1453 struct ta_xgmi_cmd_get_topology_info_output *topology_info_output;
1457 if (!topology || topology->num_nodes > TA_XGMI__MAX_CONNECTED_NODES)
1460 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.context.mem_context.shared_buf;
1461 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
1462 xgmi_cmd->flag_extend_link_record = get_extended_data;
1464 /* Fill in the shared memory with topology information as input */
1465 topology_info_input = &xgmi_cmd->xgmi_in_message.get_topology_info;
1466 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_TOPOLOGY_INFO;
1467 topology_info_input->num_nodes = number_devices;
1469 for (i = 0; i < topology_info_input->num_nodes; i++) {
1470 topology_info_input->nodes[i].node_id = topology->nodes[i].node_id;
1471 topology_info_input->nodes[i].num_hops = topology->nodes[i].num_hops;
1472 topology_info_input->nodes[i].is_sharing_enabled = topology->nodes[i].is_sharing_enabled;
1473 topology_info_input->nodes[i].sdma_engine = topology->nodes[i].sdma_engine;
1476 /* Invoke xgmi ta to get the topology information */
1477 ret = psp_xgmi_invoke(psp, TA_COMMAND_XGMI__GET_TOPOLOGY_INFO);
1481 /* Read the output topology information from the shared memory */
1482 topology_info_output = &xgmi_cmd->xgmi_out_message.get_topology_info;
1483 topology->num_nodes = xgmi_cmd->xgmi_out_message.get_topology_info.num_nodes;
1484 for (i = 0; i < topology->num_nodes; i++) {
1485 /* extended data will either be 0 or equal to non-extended data */
1486 if (topology_info_output->nodes[i].num_hops)
1487 topology->nodes[i].num_hops = topology_info_output->nodes[i].num_hops;
1489 /* non-extended data gets everything here so no need to update */
1490 if (!get_extended_data) {
1491 topology->nodes[i].node_id = topology_info_output->nodes[i].node_id;
1492 topology->nodes[i].is_sharing_enabled =
1493 topology_info_output->nodes[i].is_sharing_enabled;
1494 topology->nodes[i].sdma_engine =
1495 topology_info_output->nodes[i].sdma_engine;
1500 /* Invoke xgmi ta again to get the link information */
1501 if (psp_xgmi_peer_link_info_supported(psp)) {
1502 struct ta_xgmi_cmd_get_peer_link_info *link_info_output;
1503 struct ta_xgmi_cmd_get_extend_peer_link_info *link_extend_info_output;
1504 bool requires_reflection =
1505 (psp->xgmi_context.supports_extended_data &&
1506 get_extended_data) ||
1507 amdgpu_ip_version(psp->adev, MP0_HWIP, 0) ==
1508 IP_VERSION(13, 0, 6) ||
1509 amdgpu_ip_version(psp->adev, MP0_HWIP, 0) ==
1510 IP_VERSION(13, 0, 14);
1511 bool ta_port_num_support = amdgpu_sriov_vf(psp->adev) ? 0 :
1512 psp->xgmi_context.xgmi_ta_caps & EXTEND_PEER_LINK_INFO_CMD_FLAG;
1514 /* popluate the shared output buffer rather than the cmd input buffer
1515 * with node_ids as the input for GET_PEER_LINKS command execution.
1516 * This is required for GET_PEER_LINKS per xgmi ta implementation.
1517 * The same requirement for GET_EXTEND_PEER_LINKS command.
1519 if (ta_port_num_support) {
1520 link_extend_info_output = &xgmi_cmd->xgmi_out_message.get_extend_link_info;
1522 for (i = 0; i < topology->num_nodes; i++)
1523 link_extend_info_output->nodes[i].node_id = topology->nodes[i].node_id;
1525 link_extend_info_output->num_nodes = topology->num_nodes;
1526 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_EXTEND_PEER_LINKS;
1528 link_info_output = &xgmi_cmd->xgmi_out_message.get_link_info;
1530 for (i = 0; i < topology->num_nodes; i++)
1531 link_info_output->nodes[i].node_id = topology->nodes[i].node_id;
1533 link_info_output->num_nodes = topology->num_nodes;
1534 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_PEER_LINKS;
1537 ret = psp_xgmi_invoke(psp, xgmi_cmd->cmd_id);
1541 for (i = 0; i < topology->num_nodes; i++) {
1542 uint8_t node_num_links = ta_port_num_support ?
1543 link_extend_info_output->nodes[i].num_links : link_info_output->nodes[i].num_links;
1544 /* accumulate num_links on extended data */
1545 if (get_extended_data) {
1546 topology->nodes[i].num_links = topology->nodes[i].num_links + node_num_links;
1548 topology->nodes[i].num_links = (requires_reflection && topology->nodes[i].num_links) ?
1549 topology->nodes[i].num_links : node_num_links;
1551 /* popluate the connected port num info if supported and available */
1552 if (ta_port_num_support && topology->nodes[i].num_links) {
1553 memcpy(topology->nodes[i].port_num, link_extend_info_output->nodes[i].port_num,
1554 sizeof(struct xgmi_connected_port_num) * TA_XGMI__MAX_PORT_NUM);
1557 /* reflect the topology information for bi-directionality */
1558 if (requires_reflection && topology->nodes[i].num_hops)
1559 psp_xgmi_reflect_topology_info(psp, topology->nodes[i]);
1566 int psp_xgmi_set_topology_info(struct psp_context *psp,
1568 struct psp_xgmi_topology_info *topology)
1570 struct ta_xgmi_shared_memory *xgmi_cmd;
1571 struct ta_xgmi_cmd_get_topology_info_input *topology_info_input;
1574 if (!topology || topology->num_nodes > TA_XGMI__MAX_CONNECTED_NODES)
1577 xgmi_cmd = (struct ta_xgmi_shared_memory *)psp->xgmi_context.context.mem_context.shared_buf;
1578 memset(xgmi_cmd, 0, sizeof(struct ta_xgmi_shared_memory));
1580 topology_info_input = &xgmi_cmd->xgmi_in_message.get_topology_info;
1581 xgmi_cmd->cmd_id = TA_COMMAND_XGMI__SET_TOPOLOGY_INFO;
1582 topology_info_input->num_nodes = number_devices;
1584 for (i = 0; i < topology_info_input->num_nodes; i++) {
1585 topology_info_input->nodes[i].node_id = topology->nodes[i].node_id;
1586 topology_info_input->nodes[i].num_hops = topology->nodes[i].num_hops;
1587 topology_info_input->nodes[i].is_sharing_enabled = 1;
1588 topology_info_input->nodes[i].sdma_engine = topology->nodes[i].sdma_engine;
1591 /* Invoke xgmi ta to set topology information */
1592 return psp_xgmi_invoke(psp, TA_COMMAND_XGMI__SET_TOPOLOGY_INFO);
1596 static void psp_ras_ta_check_status(struct psp_context *psp)
1598 struct ta_ras_shared_memory *ras_cmd =
1599 (struct ta_ras_shared_memory *)psp->ras_context.context.mem_context.shared_buf;
1601 switch (ras_cmd->ras_status) {
1602 case TA_RAS_STATUS__ERROR_UNSUPPORTED_IP:
1603 dev_warn(psp->adev->dev,
1604 "RAS WARNING: cmd failed due to unsupported ip\n");
1606 case TA_RAS_STATUS__ERROR_UNSUPPORTED_ERROR_INJ:
1607 dev_warn(psp->adev->dev,
1608 "RAS WARNING: cmd failed due to unsupported error injection\n");
1610 case TA_RAS_STATUS__SUCCESS:
1612 case TA_RAS_STATUS__TEE_ERROR_ACCESS_DENIED:
1613 if (ras_cmd->cmd_id == TA_RAS_COMMAND__TRIGGER_ERROR)
1614 dev_warn(psp->adev->dev,
1615 "RAS WARNING: Inject error to critical region is not allowed\n");
1618 dev_warn(psp->adev->dev,
1619 "RAS WARNING: ras status = 0x%X\n", ras_cmd->ras_status);
1624 static int psp_ras_send_cmd(struct psp_context *psp,
1625 enum ras_command cmd_id, void *in, void *out)
1627 struct ta_ras_shared_memory *ras_cmd;
1628 uint32_t cmd = cmd_id;
1634 mutex_lock(&psp->ras_context.mutex);
1635 ras_cmd = (struct ta_ras_shared_memory *)psp->ras_context.context.mem_context.shared_buf;
1636 memset(ras_cmd, 0, sizeof(struct ta_ras_shared_memory));
1639 case TA_RAS_COMMAND__ENABLE_FEATURES:
1640 case TA_RAS_COMMAND__DISABLE_FEATURES:
1641 memcpy(&ras_cmd->ras_in_message,
1642 in, sizeof(ras_cmd->ras_in_message));
1644 case TA_RAS_COMMAND__TRIGGER_ERROR:
1645 memcpy(&ras_cmd->ras_in_message.trigger_error,
1646 in, sizeof(ras_cmd->ras_in_message.trigger_error));
1648 case TA_RAS_COMMAND__QUERY_ADDRESS:
1649 memcpy(&ras_cmd->ras_in_message.address,
1650 in, sizeof(ras_cmd->ras_in_message.address));
1653 dev_err(psp->adev->dev, "Invalid ras cmd id: %u\n", cmd);
1658 ras_cmd->cmd_id = cmd;
1659 ret = psp_ras_invoke(psp, ras_cmd->cmd_id);
1662 case TA_RAS_COMMAND__TRIGGER_ERROR:
1664 memcpy(out, &ras_cmd->ras_status, sizeof(ras_cmd->ras_status));
1666 case TA_RAS_COMMAND__QUERY_ADDRESS:
1667 if (ret || ras_cmd->ras_status || psp->cmd_buf_mem->resp.status)
1671 &ras_cmd->ras_out_message.address,
1672 sizeof(ras_cmd->ras_out_message.address));
1679 mutex_unlock(&psp->ras_context.mutex);
1684 int psp_ras_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1686 struct ta_ras_shared_memory *ras_cmd;
1689 ras_cmd = (struct ta_ras_shared_memory *)psp->ras_context.context.mem_context.shared_buf;
1692 * TODO: bypass the loading in sriov for now
1694 if (amdgpu_sriov_vf(psp->adev))
1697 ret = psp_ta_invoke(psp, ta_cmd_id, &psp->ras_context.context);
1699 if (amdgpu_ras_intr_triggered())
1702 if (ras_cmd->if_version > RAS_TA_HOST_IF_VER) {
1703 dev_warn(psp->adev->dev, "RAS: Unsupported Interface\n");
1708 if (ras_cmd->ras_out_message.flags.err_inject_switch_disable_flag) {
1709 dev_warn(psp->adev->dev, "ECC switch disabled\n");
1711 ras_cmd->ras_status = TA_RAS_STATUS__ERROR_RAS_NOT_AVAILABLE;
1712 } else if (ras_cmd->ras_out_message.flags.reg_access_failure_flag)
1713 dev_warn(psp->adev->dev,
1714 "RAS internal register access blocked\n");
1716 psp_ras_ta_check_status(psp);
1722 int psp_ras_enable_features(struct psp_context *psp,
1723 union ta_ras_cmd_input *info, bool enable)
1725 enum ras_command cmd_id;
1728 if (!psp->ras_context.context.initialized || !info)
1732 TA_RAS_COMMAND__ENABLE_FEATURES : TA_RAS_COMMAND__DISABLE_FEATURES;
1733 ret = psp_ras_send_cmd(psp, cmd_id, info, NULL);
1740 int psp_ras_terminate(struct psp_context *psp)
1745 * TODO: bypass the terminate in sriov for now
1747 if (amdgpu_sriov_vf(psp->adev))
1750 if (!psp->ras_context.context.initialized)
1753 ret = psp_ta_unload(psp, &psp->ras_context.context);
1755 psp->ras_context.context.initialized = false;
1757 mutex_destroy(&psp->ras_context.mutex);
1762 int psp_ras_initialize(struct psp_context *psp)
1765 uint32_t boot_cfg = 0xFF;
1766 struct amdgpu_device *adev = psp->adev;
1767 struct ta_ras_shared_memory *ras_cmd;
1770 * TODO: bypass the initialize in sriov for now
1772 if (amdgpu_sriov_vf(adev))
1775 if (!adev->psp.ras_context.context.bin_desc.size_bytes ||
1776 !adev->psp.ras_context.context.bin_desc.start_addr) {
1777 dev_info(adev->dev, "RAS: optional ras ta ucode is not available\n");
1781 if (amdgpu_atomfirmware_dynamic_boot_config_supported(adev)) {
1782 /* query GECC enablement status from boot config
1783 * boot_cfg: 1: GECC is enabled or 0: GECC is disabled
1785 ret = psp_boot_config_get(adev, &boot_cfg);
1787 dev_warn(adev->dev, "PSP get boot config failed\n");
1789 if (!amdgpu_ras_is_supported(psp->adev, AMDGPU_RAS_BLOCK__UMC)) {
1791 dev_info(adev->dev, "GECC is disabled\n");
1793 /* disable GECC in next boot cycle if ras is
1794 * disabled by module parameter amdgpu_ras_enable
1795 * and/or amdgpu_ras_mask, or boot_config_get call
1798 ret = psp_boot_config_set(adev, 0);
1800 dev_warn(adev->dev, "PSP set boot config failed\n");
1802 dev_warn(adev->dev, "GECC will be disabled in next boot cycle if set amdgpu_ras_enable and/or amdgpu_ras_mask to 0x0\n");
1805 if (boot_cfg == 1) {
1806 dev_info(adev->dev, "GECC is enabled\n");
1808 /* enable GECC in next boot cycle if it is disabled
1809 * in boot config, or force enable GECC if failed to
1810 * get boot configuration
1812 ret = psp_boot_config_set(adev, BOOT_CONFIG_GECC);
1814 dev_warn(adev->dev, "PSP set boot config failed\n");
1816 dev_warn(adev->dev, "GECC will be enabled in next boot cycle\n");
1821 psp->ras_context.context.mem_context.shared_mem_size = PSP_RAS_SHARED_MEM_SIZE;
1822 psp->ras_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
1824 if (!psp->ras_context.context.mem_context.shared_buf) {
1825 ret = psp_ta_init_shared_buf(psp, &psp->ras_context.context.mem_context);
1830 ras_cmd = (struct ta_ras_shared_memory *)psp->ras_context.context.mem_context.shared_buf;
1831 memset(ras_cmd, 0, sizeof(struct ta_ras_shared_memory));
1833 if (amdgpu_ras_is_poison_mode_supported(adev))
1834 ras_cmd->ras_in_message.init_flags.poison_mode_en = 1;
1835 if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu)
1836 ras_cmd->ras_in_message.init_flags.dgpu_mode = 1;
1837 ras_cmd->ras_in_message.init_flags.xcc_mask =
1839 ras_cmd->ras_in_message.init_flags.channel_dis_num = hweight32(adev->gmc.m_half_use) * 2;
1840 if (adev->gmc.gmc_funcs->query_mem_partition_mode)
1841 ras_cmd->ras_in_message.init_flags.nps_mode =
1842 adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
1844 ret = psp_ta_load(psp, &psp->ras_context.context);
1846 if (!ret && !ras_cmd->ras_status) {
1847 psp->ras_context.context.initialized = true;
1848 mutex_init(&psp->ras_context.mutex);
1850 if (ras_cmd->ras_status)
1851 dev_warn(adev->dev, "RAS Init Status: 0x%X\n", ras_cmd->ras_status);
1853 /* fail to load RAS TA */
1854 psp->ras_context.context.initialized = false;
1860 int psp_ras_trigger_error(struct psp_context *psp,
1861 struct ta_ras_trigger_error_input *info, uint32_t instance_mask)
1863 struct amdgpu_device *adev = psp->adev;
1866 uint32_t ras_status = 0;
1868 if (!psp->ras_context.context.initialized || !info)
1871 switch (info->block_id) {
1872 case TA_RAS_BLOCK__GFX:
1873 dev_mask = GET_MASK(GC, instance_mask);
1875 case TA_RAS_BLOCK__SDMA:
1876 dev_mask = GET_MASK(SDMA0, instance_mask);
1878 case TA_RAS_BLOCK__VCN:
1879 case TA_RAS_BLOCK__JPEG:
1880 dev_mask = GET_MASK(VCN, instance_mask);
1883 dev_mask = instance_mask;
1887 /* reuse sub_block_index for backward compatibility */
1888 dev_mask <<= AMDGPU_RAS_INST_SHIFT;
1889 dev_mask &= AMDGPU_RAS_INST_MASK;
1890 info->sub_block_index |= dev_mask;
1892 ret = psp_ras_send_cmd(psp,
1893 TA_RAS_COMMAND__TRIGGER_ERROR, info, &ras_status);
1897 /* If err_event_athub occurs error inject was successful, however
1898 * return status from TA is no long reliable
1900 if (amdgpu_ras_intr_triggered())
1903 if (ras_status == TA_RAS_STATUS__TEE_ERROR_ACCESS_DENIED)
1905 else if (ras_status)
1911 int psp_ras_query_address(struct psp_context *psp,
1912 struct ta_ras_query_address_input *addr_in,
1913 struct ta_ras_query_address_output *addr_out)
1917 if (!psp->ras_context.context.initialized ||
1918 !addr_in || !addr_out)
1921 ret = psp_ras_send_cmd(psp,
1922 TA_RAS_COMMAND__QUERY_ADDRESS, addr_in, addr_out);
1929 static int psp_hdcp_initialize(struct psp_context *psp)
1934 * TODO: bypass the initialize in sriov for now
1936 if (amdgpu_sriov_vf(psp->adev))
1939 /* bypass hdcp initialization if dmu is harvested */
1940 if (!amdgpu_device_has_display_hardware(psp->adev))
1943 if (!psp->hdcp_context.context.bin_desc.size_bytes ||
1944 !psp->hdcp_context.context.bin_desc.start_addr) {
1945 dev_info(psp->adev->dev, "HDCP: optional hdcp ta ucode is not available\n");
1949 psp->hdcp_context.context.mem_context.shared_mem_size = PSP_HDCP_SHARED_MEM_SIZE;
1950 psp->hdcp_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
1952 if (!psp->hdcp_context.context.mem_context.shared_buf) {
1953 ret = psp_ta_init_shared_buf(psp, &psp->hdcp_context.context.mem_context);
1958 ret = psp_ta_load(psp, &psp->hdcp_context.context);
1960 psp->hdcp_context.context.initialized = true;
1961 mutex_init(&psp->hdcp_context.mutex);
1967 int psp_hdcp_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1970 * TODO: bypass the loading in sriov for now
1972 if (amdgpu_sriov_vf(psp->adev))
1975 if (!psp->hdcp_context.context.initialized)
1978 return psp_ta_invoke(psp, ta_cmd_id, &psp->hdcp_context.context);
1981 static int psp_hdcp_terminate(struct psp_context *psp)
1986 * TODO: bypass the terminate in sriov for now
1988 if (amdgpu_sriov_vf(psp->adev))
1991 if (!psp->hdcp_context.context.initialized)
1994 ret = psp_ta_unload(psp, &psp->hdcp_context.context);
1996 psp->hdcp_context.context.initialized = false;
2003 static int psp_dtm_initialize(struct psp_context *psp)
2008 * TODO: bypass the initialize in sriov for now
2010 if (amdgpu_sriov_vf(psp->adev))
2013 /* bypass dtm initialization if dmu is harvested */
2014 if (!amdgpu_device_has_display_hardware(psp->adev))
2017 if (!psp->dtm_context.context.bin_desc.size_bytes ||
2018 !psp->dtm_context.context.bin_desc.start_addr) {
2019 dev_info(psp->adev->dev, "DTM: optional dtm ta ucode is not available\n");
2023 psp->dtm_context.context.mem_context.shared_mem_size = PSP_DTM_SHARED_MEM_SIZE;
2024 psp->dtm_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
2026 if (!psp->dtm_context.context.mem_context.shared_buf) {
2027 ret = psp_ta_init_shared_buf(psp, &psp->dtm_context.context.mem_context);
2032 ret = psp_ta_load(psp, &psp->dtm_context.context);
2034 psp->dtm_context.context.initialized = true;
2035 mutex_init(&psp->dtm_context.mutex);
2041 int psp_dtm_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
2044 * TODO: bypass the loading in sriov for now
2046 if (amdgpu_sriov_vf(psp->adev))
2049 if (!psp->dtm_context.context.initialized)
2052 return psp_ta_invoke(psp, ta_cmd_id, &psp->dtm_context.context);
2055 static int psp_dtm_terminate(struct psp_context *psp)
2060 * TODO: bypass the terminate in sriov for now
2062 if (amdgpu_sriov_vf(psp->adev))
2065 if (!psp->dtm_context.context.initialized)
2068 ret = psp_ta_unload(psp, &psp->dtm_context.context);
2070 psp->dtm_context.context.initialized = false;
2077 static int psp_rap_initialize(struct psp_context *psp)
2080 enum ta_rap_status status = TA_RAP_STATUS__SUCCESS;
2083 * TODO: bypass the initialize in sriov for now
2085 if (amdgpu_sriov_vf(psp->adev))
2088 if (!psp->rap_context.context.bin_desc.size_bytes ||
2089 !psp->rap_context.context.bin_desc.start_addr) {
2090 dev_info(psp->adev->dev, "RAP: optional rap ta ucode is not available\n");
2094 psp->rap_context.context.mem_context.shared_mem_size = PSP_RAP_SHARED_MEM_SIZE;
2095 psp->rap_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
2097 if (!psp->rap_context.context.mem_context.shared_buf) {
2098 ret = psp_ta_init_shared_buf(psp, &psp->rap_context.context.mem_context);
2103 ret = psp_ta_load(psp, &psp->rap_context.context);
2105 psp->rap_context.context.initialized = true;
2106 mutex_init(&psp->rap_context.mutex);
2110 ret = psp_rap_invoke(psp, TA_CMD_RAP__INITIALIZE, &status);
2111 if (ret || status != TA_RAP_STATUS__SUCCESS) {
2112 psp_rap_terminate(psp);
2113 /* free rap shared memory */
2114 psp_ta_free_shared_buf(&psp->rap_context.context.mem_context);
2116 dev_warn(psp->adev->dev, "RAP TA initialize fail (%d) status %d.\n",
2125 static int psp_rap_terminate(struct psp_context *psp)
2129 if (!psp->rap_context.context.initialized)
2132 ret = psp_ta_unload(psp, &psp->rap_context.context);
2134 psp->rap_context.context.initialized = false;
2139 int psp_rap_invoke(struct psp_context *psp, uint32_t ta_cmd_id, enum ta_rap_status *status)
2141 struct ta_rap_shared_memory *rap_cmd;
2144 if (!psp->rap_context.context.initialized)
2147 if (ta_cmd_id != TA_CMD_RAP__INITIALIZE &&
2148 ta_cmd_id != TA_CMD_RAP__VALIDATE_L0)
2151 mutex_lock(&psp->rap_context.mutex);
2153 rap_cmd = (struct ta_rap_shared_memory *)
2154 psp->rap_context.context.mem_context.shared_buf;
2155 memset(rap_cmd, 0, sizeof(struct ta_rap_shared_memory));
2157 rap_cmd->cmd_id = ta_cmd_id;
2158 rap_cmd->validation_method_id = METHOD_A;
2160 ret = psp_ta_invoke(psp, rap_cmd->cmd_id, &psp->rap_context.context);
2165 *status = rap_cmd->rap_status;
2168 mutex_unlock(&psp->rap_context.mutex);
2174 /* securedisplay start */
2175 static int psp_securedisplay_initialize(struct psp_context *psp)
2178 struct ta_securedisplay_cmd *securedisplay_cmd;
2181 * TODO: bypass the initialize in sriov for now
2183 if (amdgpu_sriov_vf(psp->adev))
2186 /* bypass securedisplay initialization if dmu is harvested */
2187 if (!amdgpu_device_has_display_hardware(psp->adev))
2190 if (!psp->securedisplay_context.context.bin_desc.size_bytes ||
2191 !psp->securedisplay_context.context.bin_desc.start_addr) {
2192 dev_info(psp->adev->dev, "SECUREDISPLAY: securedisplay ta ucode is not available\n");
2196 psp->securedisplay_context.context.mem_context.shared_mem_size =
2197 PSP_SECUREDISPLAY_SHARED_MEM_SIZE;
2198 psp->securedisplay_context.context.ta_load_type = GFX_CMD_ID_LOAD_TA;
2200 if (!psp->securedisplay_context.context.initialized) {
2201 ret = psp_ta_init_shared_buf(psp,
2202 &psp->securedisplay_context.context.mem_context);
2207 ret = psp_ta_load(psp, &psp->securedisplay_context.context);
2209 psp->securedisplay_context.context.initialized = true;
2210 mutex_init(&psp->securedisplay_context.mutex);
2214 mutex_lock(&psp->securedisplay_context.mutex);
2216 psp_prep_securedisplay_cmd_buf(psp, &securedisplay_cmd,
2217 TA_SECUREDISPLAY_COMMAND__QUERY_TA);
2219 ret = psp_securedisplay_invoke(psp, TA_SECUREDISPLAY_COMMAND__QUERY_TA);
2221 mutex_unlock(&psp->securedisplay_context.mutex);
2224 psp_securedisplay_terminate(psp);
2225 /* free securedisplay shared memory */
2226 psp_ta_free_shared_buf(&psp->securedisplay_context.context.mem_context);
2227 dev_err(psp->adev->dev, "SECUREDISPLAY TA initialize fail.\n");
2231 if (securedisplay_cmd->status != TA_SECUREDISPLAY_STATUS__SUCCESS) {
2232 psp_securedisplay_parse_resp_status(psp, securedisplay_cmd->status);
2233 dev_err(psp->adev->dev, "SECUREDISPLAY: query securedisplay TA failed. ret 0x%x\n",
2234 securedisplay_cmd->securedisplay_out_message.query_ta.query_cmd_ret);
2235 /* don't try again */
2236 psp->securedisplay_context.context.bin_desc.size_bytes = 0;
2242 static int psp_securedisplay_terminate(struct psp_context *psp)
2247 * TODO:bypass the terminate in sriov for now
2249 if (amdgpu_sriov_vf(psp->adev))
2252 if (!psp->securedisplay_context.context.initialized)
2255 ret = psp_ta_unload(psp, &psp->securedisplay_context.context);
2257 psp->securedisplay_context.context.initialized = false;
2262 int psp_securedisplay_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
2266 if (!psp->securedisplay_context.context.initialized)
2269 if (ta_cmd_id != TA_SECUREDISPLAY_COMMAND__QUERY_TA &&
2270 ta_cmd_id != TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC &&
2271 ta_cmd_id != TA_SECUREDISPLAY_COMMAND__SEND_ROI_CRC_V2)
2274 ret = psp_ta_invoke(psp, ta_cmd_id, &psp->securedisplay_context.context);
2278 /* SECUREDISPLAY end */
2280 int amdgpu_psp_wait_for_bootloader(struct amdgpu_device *adev)
2282 struct psp_context *psp = &adev->psp;
2285 if (!amdgpu_sriov_vf(adev) && psp->funcs && psp->funcs->wait_for_bootloader != NULL)
2286 ret = psp->funcs->wait_for_bootloader(psp);
2291 bool amdgpu_psp_get_ras_capability(struct psp_context *psp)
2294 psp->funcs->get_ras_capability) {
2295 return psp->funcs->get_ras_capability(psp);
2301 bool amdgpu_psp_tos_reload_needed(struct amdgpu_device *adev)
2303 struct psp_context *psp = &adev->psp;
2305 if (amdgpu_sriov_vf(adev) || (adev->flags & AMD_IS_APU))
2308 if (psp->funcs && psp->funcs->is_reload_needed)
2309 return psp->funcs->is_reload_needed(psp);
2314 static int psp_hw_start(struct psp_context *psp)
2316 struct amdgpu_device *adev = psp->adev;
2319 if (!amdgpu_sriov_vf(adev)) {
2320 if ((is_psp_fw_valid(psp->kdb)) &&
2321 (psp->funcs->bootloader_load_kdb != NULL)) {
2322 ret = psp_bootloader_load_kdb(psp);
2324 dev_err(adev->dev, "PSP load kdb failed!\n");
2329 if ((is_psp_fw_valid(psp->spl)) &&
2330 (psp->funcs->bootloader_load_spl != NULL)) {
2331 ret = psp_bootloader_load_spl(psp);
2333 dev_err(adev->dev, "PSP load spl failed!\n");
2338 if ((is_psp_fw_valid(psp->sys)) &&
2339 (psp->funcs->bootloader_load_sysdrv != NULL)) {
2340 ret = psp_bootloader_load_sysdrv(psp);
2342 dev_err(adev->dev, "PSP load sys drv failed!\n");
2347 if ((is_psp_fw_valid(psp->soc_drv)) &&
2348 (psp->funcs->bootloader_load_soc_drv != NULL)) {
2349 ret = psp_bootloader_load_soc_drv(psp);
2351 dev_err(adev->dev, "PSP load soc drv failed!\n");
2356 if ((is_psp_fw_valid(psp->intf_drv)) &&
2357 (psp->funcs->bootloader_load_intf_drv != NULL)) {
2358 ret = psp_bootloader_load_intf_drv(psp);
2360 dev_err(adev->dev, "PSP load intf drv failed!\n");
2365 if ((is_psp_fw_valid(psp->dbg_drv)) &&
2366 (psp->funcs->bootloader_load_dbg_drv != NULL)) {
2367 ret = psp_bootloader_load_dbg_drv(psp);
2369 dev_err(adev->dev, "PSP load dbg drv failed!\n");
2374 if ((is_psp_fw_valid(psp->ras_drv)) &&
2375 (psp->funcs->bootloader_load_ras_drv != NULL)) {
2376 ret = psp_bootloader_load_ras_drv(psp);
2378 dev_err(adev->dev, "PSP load ras_drv failed!\n");
2383 if ((is_psp_fw_valid(psp->ipkeymgr_drv)) &&
2384 (psp->funcs->bootloader_load_ipkeymgr_drv != NULL)) {
2385 ret = psp_bootloader_load_ipkeymgr_drv(psp);
2387 dev_err(adev->dev, "PSP load ipkeymgr_drv failed!\n");
2392 if ((is_psp_fw_valid(psp->spdm_drv)) &&
2393 (psp->funcs->bootloader_load_spdm_drv != NULL)) {
2394 ret = psp_bootloader_load_spdm_drv(psp);
2396 dev_err(adev->dev, "PSP load spdm_drv failed!\n");
2401 if ((is_psp_fw_valid(psp->sos)) &&
2402 (psp->funcs->bootloader_load_sos != NULL)) {
2403 ret = psp_bootloader_load_sos(psp);
2405 dev_err(adev->dev, "PSP load sos failed!\n");
2411 ret = psp_ring_create(psp, PSP_RING_TYPE__KM);
2413 dev_err(adev->dev, "PSP create ring failed!\n");
2417 if (amdgpu_sriov_vf(adev) && amdgpu_in_reset(adev))
2420 if (!psp->boot_time_tmr || psp->autoload_supported) {
2421 ret = psp_tmr_init(psp);
2423 dev_err(adev->dev, "PSP tmr init failed!\n");
2430 * For ASICs with DF Cstate management centralized
2431 * to PMFW, TMR setup should be performed after PMFW
2432 * loaded and before other non-psp firmware loaded.
2434 if (psp->pmfw_centralized_cstate_management) {
2435 ret = psp_load_smu_fw(psp);
2440 if (!psp->boot_time_tmr || !psp->autoload_supported) {
2441 ret = psp_tmr_load(psp);
2443 dev_err(adev->dev, "PSP load tmr failed!\n");
2451 static int psp_get_fw_type(struct amdgpu_firmware_info *ucode,
2452 enum psp_gfx_fw_type *type)
2454 switch (ucode->ucode_id) {
2455 case AMDGPU_UCODE_ID_CAP:
2456 *type = GFX_FW_TYPE_CAP;
2458 case AMDGPU_UCODE_ID_SDMA0:
2459 *type = GFX_FW_TYPE_SDMA0;
2461 case AMDGPU_UCODE_ID_SDMA1:
2462 *type = GFX_FW_TYPE_SDMA1;
2464 case AMDGPU_UCODE_ID_SDMA2:
2465 *type = GFX_FW_TYPE_SDMA2;
2467 case AMDGPU_UCODE_ID_SDMA3:
2468 *type = GFX_FW_TYPE_SDMA3;
2470 case AMDGPU_UCODE_ID_SDMA4:
2471 *type = GFX_FW_TYPE_SDMA4;
2473 case AMDGPU_UCODE_ID_SDMA5:
2474 *type = GFX_FW_TYPE_SDMA5;
2476 case AMDGPU_UCODE_ID_SDMA6:
2477 *type = GFX_FW_TYPE_SDMA6;
2479 case AMDGPU_UCODE_ID_SDMA7:
2480 *type = GFX_FW_TYPE_SDMA7;
2482 case AMDGPU_UCODE_ID_CP_MES:
2483 *type = GFX_FW_TYPE_CP_MES;
2485 case AMDGPU_UCODE_ID_CP_MES_DATA:
2486 *type = GFX_FW_TYPE_MES_STACK;
2488 case AMDGPU_UCODE_ID_CP_MES1:
2489 *type = GFX_FW_TYPE_CP_MES_KIQ;
2491 case AMDGPU_UCODE_ID_CP_MES1_DATA:
2492 *type = GFX_FW_TYPE_MES_KIQ_STACK;
2494 case AMDGPU_UCODE_ID_CP_CE:
2495 *type = GFX_FW_TYPE_CP_CE;
2497 case AMDGPU_UCODE_ID_CP_PFP:
2498 *type = GFX_FW_TYPE_CP_PFP;
2500 case AMDGPU_UCODE_ID_CP_ME:
2501 *type = GFX_FW_TYPE_CP_ME;
2503 case AMDGPU_UCODE_ID_CP_MEC1:
2504 *type = GFX_FW_TYPE_CP_MEC;
2506 case AMDGPU_UCODE_ID_CP_MEC1_JT:
2507 *type = GFX_FW_TYPE_CP_MEC_ME1;
2509 case AMDGPU_UCODE_ID_CP_MEC2:
2510 *type = GFX_FW_TYPE_CP_MEC;
2512 case AMDGPU_UCODE_ID_CP_MEC2_JT:
2513 *type = GFX_FW_TYPE_CP_MEC_ME2;
2515 case AMDGPU_UCODE_ID_RLC_P:
2516 *type = GFX_FW_TYPE_RLC_P;
2518 case AMDGPU_UCODE_ID_RLC_V:
2519 *type = GFX_FW_TYPE_RLC_V;
2521 case AMDGPU_UCODE_ID_RLC_G:
2522 *type = GFX_FW_TYPE_RLC_G;
2524 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_CNTL:
2525 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_CNTL;
2527 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_GPM_MEM:
2528 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_GPM_MEM;
2530 case AMDGPU_UCODE_ID_RLC_RESTORE_LIST_SRM_MEM:
2531 *type = GFX_FW_TYPE_RLC_RESTORE_LIST_SRM_MEM;
2533 case AMDGPU_UCODE_ID_RLC_IRAM:
2534 *type = GFX_FW_TYPE_RLC_IRAM;
2536 case AMDGPU_UCODE_ID_RLC_DRAM:
2537 *type = GFX_FW_TYPE_RLC_DRAM_BOOT;
2539 case AMDGPU_UCODE_ID_GLOBAL_TAP_DELAYS:
2540 *type = GFX_FW_TYPE_GLOBAL_TAP_DELAYS;
2542 case AMDGPU_UCODE_ID_SE0_TAP_DELAYS:
2543 *type = GFX_FW_TYPE_SE0_TAP_DELAYS;
2545 case AMDGPU_UCODE_ID_SE1_TAP_DELAYS:
2546 *type = GFX_FW_TYPE_SE1_TAP_DELAYS;
2548 case AMDGPU_UCODE_ID_SE2_TAP_DELAYS:
2549 *type = GFX_FW_TYPE_SE2_TAP_DELAYS;
2551 case AMDGPU_UCODE_ID_SE3_TAP_DELAYS:
2552 *type = GFX_FW_TYPE_SE3_TAP_DELAYS;
2554 case AMDGPU_UCODE_ID_SMC:
2555 *type = GFX_FW_TYPE_SMU;
2557 case AMDGPU_UCODE_ID_PPTABLE:
2558 *type = GFX_FW_TYPE_PPTABLE;
2560 case AMDGPU_UCODE_ID_UVD:
2561 *type = GFX_FW_TYPE_UVD;
2563 case AMDGPU_UCODE_ID_UVD1:
2564 *type = GFX_FW_TYPE_UVD1;
2566 case AMDGPU_UCODE_ID_VCE:
2567 *type = GFX_FW_TYPE_VCE;
2569 case AMDGPU_UCODE_ID_VCN:
2570 *type = GFX_FW_TYPE_VCN;
2572 case AMDGPU_UCODE_ID_VCN1:
2573 *type = GFX_FW_TYPE_VCN1;
2575 case AMDGPU_UCODE_ID_DMCU_ERAM:
2576 *type = GFX_FW_TYPE_DMCU_ERAM;
2578 case AMDGPU_UCODE_ID_DMCU_INTV:
2579 *type = GFX_FW_TYPE_DMCU_ISR;
2581 case AMDGPU_UCODE_ID_VCN0_RAM:
2582 *type = GFX_FW_TYPE_VCN0_RAM;
2584 case AMDGPU_UCODE_ID_VCN1_RAM:
2585 *type = GFX_FW_TYPE_VCN1_RAM;
2587 case AMDGPU_UCODE_ID_DMCUB:
2588 *type = GFX_FW_TYPE_DMUB;
2590 case AMDGPU_UCODE_ID_SDMA_UCODE_TH0:
2591 case AMDGPU_UCODE_ID_SDMA_RS64:
2592 *type = GFX_FW_TYPE_SDMA_UCODE_TH0;
2594 case AMDGPU_UCODE_ID_SDMA_UCODE_TH1:
2595 *type = GFX_FW_TYPE_SDMA_UCODE_TH1;
2597 case AMDGPU_UCODE_ID_IMU_I:
2598 *type = GFX_FW_TYPE_IMU_I;
2600 case AMDGPU_UCODE_ID_IMU_D:
2601 *type = GFX_FW_TYPE_IMU_D;
2603 case AMDGPU_UCODE_ID_CP_RS64_PFP:
2604 *type = GFX_FW_TYPE_RS64_PFP;
2606 case AMDGPU_UCODE_ID_CP_RS64_ME:
2607 *type = GFX_FW_TYPE_RS64_ME;
2609 case AMDGPU_UCODE_ID_CP_RS64_MEC:
2610 *type = GFX_FW_TYPE_RS64_MEC;
2612 case AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK:
2613 *type = GFX_FW_TYPE_RS64_PFP_P0_STACK;
2615 case AMDGPU_UCODE_ID_CP_RS64_PFP_P1_STACK:
2616 *type = GFX_FW_TYPE_RS64_PFP_P1_STACK;
2618 case AMDGPU_UCODE_ID_CP_RS64_ME_P0_STACK:
2619 *type = GFX_FW_TYPE_RS64_ME_P0_STACK;
2621 case AMDGPU_UCODE_ID_CP_RS64_ME_P1_STACK:
2622 *type = GFX_FW_TYPE_RS64_ME_P1_STACK;
2624 case AMDGPU_UCODE_ID_CP_RS64_MEC_P0_STACK:
2625 *type = GFX_FW_TYPE_RS64_MEC_P0_STACK;
2627 case AMDGPU_UCODE_ID_CP_RS64_MEC_P1_STACK:
2628 *type = GFX_FW_TYPE_RS64_MEC_P1_STACK;
2630 case AMDGPU_UCODE_ID_CP_RS64_MEC_P2_STACK:
2631 *type = GFX_FW_TYPE_RS64_MEC_P2_STACK;
2633 case AMDGPU_UCODE_ID_CP_RS64_MEC_P3_STACK:
2634 *type = GFX_FW_TYPE_RS64_MEC_P3_STACK;
2636 case AMDGPU_UCODE_ID_VPE_CTX:
2637 *type = GFX_FW_TYPE_VPEC_FW1;
2639 case AMDGPU_UCODE_ID_VPE_CTL:
2640 *type = GFX_FW_TYPE_VPEC_FW2;
2642 case AMDGPU_UCODE_ID_VPE:
2643 *type = GFX_FW_TYPE_VPE;
2645 case AMDGPU_UCODE_ID_UMSCH_MM_UCODE:
2646 *type = GFX_FW_TYPE_UMSCH_UCODE;
2648 case AMDGPU_UCODE_ID_UMSCH_MM_DATA:
2649 *type = GFX_FW_TYPE_UMSCH_DATA;
2651 case AMDGPU_UCODE_ID_UMSCH_MM_CMD_BUFFER:
2652 *type = GFX_FW_TYPE_UMSCH_CMD_BUFFER;
2654 case AMDGPU_UCODE_ID_P2S_TABLE:
2655 *type = GFX_FW_TYPE_P2S_TABLE;
2657 case AMDGPU_UCODE_ID_JPEG_RAM:
2658 *type = GFX_FW_TYPE_JPEG_RAM;
2660 case AMDGPU_UCODE_ID_ISP:
2661 *type = GFX_FW_TYPE_ISP;
2663 case AMDGPU_UCODE_ID_MAXIMUM:
2671 static void psp_print_fw_hdr(struct psp_context *psp,
2672 struct amdgpu_firmware_info *ucode)
2674 struct amdgpu_device *adev = psp->adev;
2675 struct common_firmware_header *hdr;
2677 switch (ucode->ucode_id) {
2678 case AMDGPU_UCODE_ID_SDMA0:
2679 case AMDGPU_UCODE_ID_SDMA1:
2680 case AMDGPU_UCODE_ID_SDMA2:
2681 case AMDGPU_UCODE_ID_SDMA3:
2682 case AMDGPU_UCODE_ID_SDMA4:
2683 case AMDGPU_UCODE_ID_SDMA5:
2684 case AMDGPU_UCODE_ID_SDMA6:
2685 case AMDGPU_UCODE_ID_SDMA7:
2686 hdr = (struct common_firmware_header *)
2687 adev->sdma.instance[ucode->ucode_id - AMDGPU_UCODE_ID_SDMA0].fw->data;
2688 amdgpu_ucode_print_sdma_hdr(hdr);
2690 case AMDGPU_UCODE_ID_CP_CE:
2691 hdr = (struct common_firmware_header *)adev->gfx.ce_fw->data;
2692 amdgpu_ucode_print_gfx_hdr(hdr);
2694 case AMDGPU_UCODE_ID_CP_PFP:
2695 hdr = (struct common_firmware_header *)adev->gfx.pfp_fw->data;
2696 amdgpu_ucode_print_gfx_hdr(hdr);
2698 case AMDGPU_UCODE_ID_CP_ME:
2699 hdr = (struct common_firmware_header *)adev->gfx.me_fw->data;
2700 amdgpu_ucode_print_gfx_hdr(hdr);
2702 case AMDGPU_UCODE_ID_CP_MEC1:
2703 hdr = (struct common_firmware_header *)adev->gfx.mec_fw->data;
2704 amdgpu_ucode_print_gfx_hdr(hdr);
2706 case AMDGPU_UCODE_ID_RLC_G:
2707 hdr = (struct common_firmware_header *)adev->gfx.rlc_fw->data;
2708 amdgpu_ucode_print_rlc_hdr(hdr);
2710 case AMDGPU_UCODE_ID_SMC:
2711 hdr = (struct common_firmware_header *)adev->pm.fw->data;
2712 amdgpu_ucode_print_smc_hdr(hdr);
2719 static int psp_prep_load_ip_fw_cmd_buf(struct psp_context *psp,
2720 struct amdgpu_firmware_info *ucode,
2721 struct psp_gfx_cmd_resp *cmd)
2724 uint64_t fw_mem_mc_addr = ucode->mc_addr;
2726 cmd->cmd_id = GFX_CMD_ID_LOAD_IP_FW;
2727 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_lo = lower_32_bits(fw_mem_mc_addr);
2728 cmd->cmd.cmd_load_ip_fw.fw_phy_addr_hi = upper_32_bits(fw_mem_mc_addr);
2729 cmd->cmd.cmd_load_ip_fw.fw_size = ucode->ucode_size;
2731 ret = psp_get_fw_type(ucode, &cmd->cmd.cmd_load_ip_fw.fw_type);
2733 dev_err(psp->adev->dev, "Unknown firmware type\n");
2738 int psp_execute_ip_fw_load(struct psp_context *psp,
2739 struct amdgpu_firmware_info *ucode)
2742 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
2744 ret = psp_prep_load_ip_fw_cmd_buf(psp, ucode, cmd);
2746 ret = psp_cmd_submit_buf(psp, ucode, cmd,
2747 psp->fence_buf_mc_addr);
2750 release_psp_cmd_buf(psp);
2755 static int psp_load_p2s_table(struct psp_context *psp)
2758 struct amdgpu_device *adev = psp->adev;
2759 struct amdgpu_firmware_info *ucode =
2760 &adev->firmware.ucode[AMDGPU_UCODE_ID_P2S_TABLE];
2762 if (adev->in_runpm && ((adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) ||
2763 (adev->pm.rpm_mode == AMDGPU_RUNPM_BAMACO)))
2766 if (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 6) ||
2767 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(13, 0, 14)) {
2768 uint32_t supp_vers = adev->flags & AMD_IS_APU ? 0x0036013D :
2770 if (psp->sos.fw_version < supp_vers)
2774 if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
2777 ret = psp_execute_ip_fw_load(psp, ucode);
2782 static int psp_load_smu_fw(struct psp_context *psp)
2785 struct amdgpu_device *adev = psp->adev;
2786 struct amdgpu_firmware_info *ucode =
2787 &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
2788 struct amdgpu_ras *ras = psp->ras_context.ras;
2791 * Skip SMU FW reloading in case of using BACO for runpm only,
2792 * as SMU is always alive.
2794 if (adev->in_runpm && ((adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) ||
2795 (adev->pm.rpm_mode == AMDGPU_RUNPM_BAMACO)))
2798 if (!ucode->fw || amdgpu_sriov_vf(psp->adev))
2801 if ((amdgpu_in_reset(adev) && ras && adev->ras_enabled &&
2802 (amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(11, 0, 4) ||
2803 amdgpu_ip_version(adev, MP0_HWIP, 0) == IP_VERSION(11, 0, 2)))) {
2804 ret = amdgpu_dpm_set_mp1_state(adev, PP_MP1_STATE_UNLOAD);
2806 dev_err(adev->dev, "Failed to set MP1 state prepare for reload\n");
2809 ret = psp_execute_ip_fw_load(psp, ucode);
2812 dev_err(adev->dev, "PSP load smu failed!\n");
2817 static bool fw_load_skip_check(struct psp_context *psp,
2818 struct amdgpu_firmware_info *ucode)
2820 if (!ucode->fw || !ucode->ucode_size)
2823 if (ucode->ucode_id == AMDGPU_UCODE_ID_P2S_TABLE)
2826 if (ucode->ucode_id == AMDGPU_UCODE_ID_SMC &&
2827 (psp_smu_reload_quirk(psp) ||
2828 psp->autoload_supported ||
2829 psp->pmfw_centralized_cstate_management))
2832 if (amdgpu_sriov_vf(psp->adev) &&
2833 amdgpu_virt_fw_load_skip_check(psp->adev, ucode->ucode_id))
2836 if (psp->autoload_supported &&
2837 (ucode->ucode_id == AMDGPU_UCODE_ID_CP_MEC1_JT ||
2838 ucode->ucode_id == AMDGPU_UCODE_ID_CP_MEC2_JT))
2839 /* skip mec JT when autoload is enabled */
2845 int psp_load_fw_list(struct psp_context *psp,
2846 struct amdgpu_firmware_info **ucode_list, int ucode_count)
2849 struct amdgpu_firmware_info *ucode;
2851 for (i = 0; i < ucode_count; ++i) {
2852 ucode = ucode_list[i];
2853 psp_print_fw_hdr(psp, ucode);
2854 ret = psp_execute_ip_fw_load(psp, ucode);
2861 static int psp_load_non_psp_fw(struct psp_context *psp)
2864 struct amdgpu_firmware_info *ucode;
2865 struct amdgpu_device *adev = psp->adev;
2867 if (psp->autoload_supported &&
2868 !psp->pmfw_centralized_cstate_management) {
2869 ret = psp_load_smu_fw(psp);
2874 /* Load P2S table first if it's available */
2875 psp_load_p2s_table(psp);
2877 for (i = 0; i < adev->firmware.max_ucodes; i++) {
2878 ucode = &adev->firmware.ucode[i];
2880 if (ucode->ucode_id == AMDGPU_UCODE_ID_SMC &&
2881 !fw_load_skip_check(psp, ucode)) {
2882 ret = psp_load_smu_fw(psp);
2888 if (fw_load_skip_check(psp, ucode))
2891 if (psp->autoload_supported &&
2892 (amdgpu_ip_version(adev, MP0_HWIP, 0) ==
2893 IP_VERSION(11, 0, 7) ||
2894 amdgpu_ip_version(adev, MP0_HWIP, 0) ==
2895 IP_VERSION(11, 0, 11) ||
2896 amdgpu_ip_version(adev, MP0_HWIP, 0) ==
2897 IP_VERSION(11, 0, 12)) &&
2898 (ucode->ucode_id == AMDGPU_UCODE_ID_SDMA1 ||
2899 ucode->ucode_id == AMDGPU_UCODE_ID_SDMA2 ||
2900 ucode->ucode_id == AMDGPU_UCODE_ID_SDMA3))
2901 /* PSP only receive one SDMA fw for sienna_cichlid,
2902 * as all four sdma fw are same
2906 psp_print_fw_hdr(psp, ucode);
2908 ret = psp_execute_ip_fw_load(psp, ucode);
2912 /* Start rlc autoload after psp received all the gfx firmware */
2913 if (psp->autoload_supported && ucode->ucode_id == (amdgpu_sriov_vf(adev) ?
2914 adev->virt.autoload_ucode_id : AMDGPU_UCODE_ID_RLC_G)) {
2915 ret = psp_rlc_autoload_start(psp);
2917 dev_err(adev->dev, "Failed to start rlc autoload\n");
2926 static int psp_load_fw(struct amdgpu_device *adev)
2929 struct psp_context *psp = &adev->psp;
2931 if (amdgpu_sriov_vf(adev) && amdgpu_in_reset(adev)) {
2932 /* should not destroy ring, only stop */
2933 psp_ring_stop(psp, PSP_RING_TYPE__KM);
2935 memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);
2937 ret = psp_ring_init(psp, PSP_RING_TYPE__KM);
2939 dev_err(adev->dev, "PSP ring init failed!\n");
2944 ret = psp_hw_start(psp);
2948 ret = psp_load_non_psp_fw(psp);
2952 ret = psp_asd_initialize(psp);
2954 dev_err(adev->dev, "PSP load asd failed!\n");
2958 ret = psp_rl_load(adev);
2960 dev_err(adev->dev, "PSP load RL failed!\n");
2964 if (amdgpu_sriov_vf(adev) && amdgpu_in_reset(adev)) {
2965 if (adev->gmc.xgmi.num_physical_nodes > 1) {
2966 ret = psp_xgmi_initialize(psp, false, true);
2967 /* Warning the XGMI seesion initialize failure
2968 * Instead of stop driver initialization
2971 dev_err(psp->adev->dev,
2972 "XGMI: Failed to initialize XGMI session\n");
2977 ret = psp_ras_initialize(psp);
2979 dev_err(psp->adev->dev,
2980 "RAS: Failed to initialize RAS\n");
2982 ret = psp_hdcp_initialize(psp);
2984 dev_err(psp->adev->dev,
2985 "HDCP: Failed to initialize HDCP\n");
2987 ret = psp_dtm_initialize(psp);
2989 dev_err(psp->adev->dev,
2990 "DTM: Failed to initialize DTM\n");
2992 ret = psp_rap_initialize(psp);
2994 dev_err(psp->adev->dev,
2995 "RAP: Failed to initialize RAP\n");
2997 ret = psp_securedisplay_initialize(psp);
2999 dev_err(psp->adev->dev,
3000 "SECUREDISPLAY: Failed to initialize SECUREDISPLAY\n");
3006 psp_free_shared_bufs(psp);
3009 * all cleanup jobs (xgmi terminate, ras terminate,
3010 * ring destroy, cmd/fence/fw buffers destory,
3011 * psp->cmd destory) are delayed to psp_hw_fini
3013 psp_ring_destroy(psp, PSP_RING_TYPE__KM);
3017 static int psp_hw_init(struct amdgpu_ip_block *ip_block)
3020 struct amdgpu_device *adev = ip_block->adev;
3022 mutex_lock(&adev->firmware.mutex);
3024 ret = amdgpu_ucode_init_bo(adev);
3028 ret = psp_load_fw(adev);
3030 dev_err(adev->dev, "PSP firmware loading failed\n");
3034 mutex_unlock(&adev->firmware.mutex);
3038 adev->firmware.load_type = AMDGPU_FW_LOAD_DIRECT;
3039 mutex_unlock(&adev->firmware.mutex);
3043 static int psp_hw_fini(struct amdgpu_ip_block *ip_block)
3045 struct amdgpu_device *adev = ip_block->adev;
3046 struct psp_context *psp = &adev->psp;
3049 psp_ras_terminate(psp);
3050 psp_securedisplay_terminate(psp);
3051 psp_rap_terminate(psp);
3052 psp_dtm_terminate(psp);
3053 psp_hdcp_terminate(psp);
3055 if (adev->gmc.xgmi.num_physical_nodes > 1)
3056 psp_xgmi_terminate(psp);
3059 psp_asd_terminate(psp);
3060 psp_tmr_terminate(psp);
3062 psp_ring_destroy(psp, PSP_RING_TYPE__KM);
3067 static int psp_suspend(struct amdgpu_ip_block *ip_block)
3070 struct amdgpu_device *adev = ip_block->adev;
3071 struct psp_context *psp = &adev->psp;
3073 if (adev->gmc.xgmi.num_physical_nodes > 1 &&
3074 psp->xgmi_context.context.initialized) {
3075 ret = psp_xgmi_terminate(psp);
3077 dev_err(adev->dev, "Failed to terminate xgmi ta\n");
3083 ret = psp_ras_terminate(psp);
3085 dev_err(adev->dev, "Failed to terminate ras ta\n");
3088 ret = psp_hdcp_terminate(psp);
3090 dev_err(adev->dev, "Failed to terminate hdcp ta\n");
3093 ret = psp_dtm_terminate(psp);
3095 dev_err(adev->dev, "Failed to terminate dtm ta\n");
3098 ret = psp_rap_terminate(psp);
3100 dev_err(adev->dev, "Failed to terminate rap ta\n");
3103 ret = psp_securedisplay_terminate(psp);
3105 dev_err(adev->dev, "Failed to terminate securedisplay ta\n");
3110 ret = psp_asd_terminate(psp);
3112 dev_err(adev->dev, "Failed to terminate asd\n");
3116 ret = psp_tmr_terminate(psp);
3118 dev_err(adev->dev, "Failed to terminate tmr\n");
3122 ret = psp_ring_stop(psp, PSP_RING_TYPE__KM);
3124 dev_err(adev->dev, "PSP ring stop failed\n");
3130 static int psp_resume(struct amdgpu_ip_block *ip_block)
3133 struct amdgpu_device *adev = ip_block->adev;
3134 struct psp_context *psp = &adev->psp;
3136 dev_info(adev->dev, "PSP is resuming...\n");
3138 if (psp->mem_train_ctx.enable_mem_training) {
3139 ret = psp_mem_training(psp, PSP_MEM_TRAIN_RESUME);
3141 dev_err(adev->dev, "Failed to process memory training!\n");
3146 mutex_lock(&adev->firmware.mutex);
3148 ret = amdgpu_ucode_init_bo(adev);
3152 ret = psp_hw_start(psp);
3156 ret = psp_load_non_psp_fw(psp);
3160 ret = psp_asd_initialize(psp);
3162 dev_err(adev->dev, "PSP load asd failed!\n");
3166 ret = psp_rl_load(adev);
3168 dev_err(adev->dev, "PSP load RL failed!\n");
3172 if (adev->gmc.xgmi.num_physical_nodes > 1) {
3173 ret = psp_xgmi_initialize(psp, false, true);
3174 /* Warning the XGMI seesion initialize failure
3175 * Instead of stop driver initialization
3178 dev_err(psp->adev->dev,
3179 "XGMI: Failed to initialize XGMI session\n");
3183 ret = psp_ras_initialize(psp);
3185 dev_err(psp->adev->dev,
3186 "RAS: Failed to initialize RAS\n");
3188 ret = psp_hdcp_initialize(psp);
3190 dev_err(psp->adev->dev,
3191 "HDCP: Failed to initialize HDCP\n");
3193 ret = psp_dtm_initialize(psp);
3195 dev_err(psp->adev->dev,
3196 "DTM: Failed to initialize DTM\n");
3198 ret = psp_rap_initialize(psp);
3200 dev_err(psp->adev->dev,
3201 "RAP: Failed to initialize RAP\n");
3203 ret = psp_securedisplay_initialize(psp);
3205 dev_err(psp->adev->dev,
3206 "SECUREDISPLAY: Failed to initialize SECUREDISPLAY\n");
3209 mutex_unlock(&adev->firmware.mutex);
3214 dev_err(adev->dev, "PSP resume failed\n");
3215 mutex_unlock(&adev->firmware.mutex);
3219 int psp_gpu_reset(struct amdgpu_device *adev)
3223 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
3226 mutex_lock(&adev->psp.mutex);
3227 ret = psp_mode1_reset(&adev->psp);
3228 mutex_unlock(&adev->psp.mutex);
3233 int psp_rlc_autoload_start(struct psp_context *psp)
3236 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
3238 cmd->cmd_id = GFX_CMD_ID_AUTOLOAD_RLC;
3240 ret = psp_cmd_submit_buf(psp, NULL, cmd,
3241 psp->fence_buf_mc_addr);
3243 release_psp_cmd_buf(psp);
3248 int psp_ring_cmd_submit(struct psp_context *psp,
3249 uint64_t cmd_buf_mc_addr,
3250 uint64_t fence_mc_addr,
3253 unsigned int psp_write_ptr_reg = 0;
3254 struct psp_gfx_rb_frame *write_frame;
3255 struct psp_ring *ring = &psp->km_ring;
3256 struct psp_gfx_rb_frame *ring_buffer_start = ring->ring_mem;
3257 struct psp_gfx_rb_frame *ring_buffer_end = ring_buffer_start +
3258 ring->ring_size / sizeof(struct psp_gfx_rb_frame) - 1;
3259 struct amdgpu_device *adev = psp->adev;
3260 uint32_t ring_size_dw = ring->ring_size / 4;
3261 uint32_t rb_frame_size_dw = sizeof(struct psp_gfx_rb_frame) / 4;
3263 /* KM (GPCOM) prepare write pointer */
3264 psp_write_ptr_reg = psp_ring_get_wptr(psp);
3266 /* Update KM RB frame pointer to new frame */
3267 /* write_frame ptr increments by size of rb_frame in bytes */
3268 /* psp_write_ptr_reg increments by size of rb_frame in DWORDs */
3269 if ((psp_write_ptr_reg % ring_size_dw) == 0)
3270 write_frame = ring_buffer_start;
3272 write_frame = ring_buffer_start + (psp_write_ptr_reg / rb_frame_size_dw);
3273 /* Check invalid write_frame ptr address */
3274 if ((write_frame < ring_buffer_start) || (ring_buffer_end < write_frame)) {
3276 "ring_buffer_start = %p; ring_buffer_end = %p; write_frame = %p\n",
3277 ring_buffer_start, ring_buffer_end, write_frame);
3279 "write_frame is pointing to address out of bounds\n");
3283 /* Initialize KM RB frame */
3284 memset(write_frame, 0, sizeof(struct psp_gfx_rb_frame));
3286 /* Update KM RB frame */
3287 write_frame->cmd_buf_addr_hi = upper_32_bits(cmd_buf_mc_addr);
3288 write_frame->cmd_buf_addr_lo = lower_32_bits(cmd_buf_mc_addr);
3289 write_frame->fence_addr_hi = upper_32_bits(fence_mc_addr);
3290 write_frame->fence_addr_lo = lower_32_bits(fence_mc_addr);
3291 write_frame->fence_value = index;
3292 amdgpu_device_flush_hdp(adev, NULL);
3294 /* Update the write Pointer in DWORDs */
3295 psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) % ring_size_dw;
3296 psp_ring_set_wptr(psp, psp_write_ptr_reg);
3300 int psp_init_asd_microcode(struct psp_context *psp, const char *chip_name)
3302 struct amdgpu_device *adev = psp->adev;
3303 const struct psp_firmware_header_v1_0 *asd_hdr;
3306 err = amdgpu_ucode_request(adev, &adev->psp.asd_fw, AMDGPU_UCODE_REQUIRED,
3307 "amdgpu/%s_asd.bin", chip_name);
3311 asd_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.asd_fw->data;
3312 adev->psp.asd_context.bin_desc.fw_version = le32_to_cpu(asd_hdr->header.ucode_version);
3313 adev->psp.asd_context.bin_desc.feature_version = le32_to_cpu(asd_hdr->sos.fw_version);
3314 adev->psp.asd_context.bin_desc.size_bytes = le32_to_cpu(asd_hdr->header.ucode_size_bytes);
3315 adev->psp.asd_context.bin_desc.start_addr = (uint8_t *)asd_hdr +
3316 le32_to_cpu(asd_hdr->header.ucode_array_offset_bytes);
3319 amdgpu_ucode_release(&adev->psp.asd_fw);
3323 int psp_init_toc_microcode(struct psp_context *psp, const char *chip_name)
3325 struct amdgpu_device *adev = psp->adev;
3326 const struct psp_firmware_header_v1_0 *toc_hdr;
3329 err = amdgpu_ucode_request(adev, &adev->psp.toc_fw, AMDGPU_UCODE_REQUIRED,
3330 "amdgpu/%s_toc.bin", chip_name);
3334 toc_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.toc_fw->data;
3335 adev->psp.toc.fw_version = le32_to_cpu(toc_hdr->header.ucode_version);
3336 adev->psp.toc.feature_version = le32_to_cpu(toc_hdr->sos.fw_version);
3337 adev->psp.toc.size_bytes = le32_to_cpu(toc_hdr->header.ucode_size_bytes);
3338 adev->psp.toc.start_addr = (uint8_t *)toc_hdr +
3339 le32_to_cpu(toc_hdr->header.ucode_array_offset_bytes);
3342 amdgpu_ucode_release(&adev->psp.toc_fw);
3346 static int parse_sos_bin_descriptor(struct psp_context *psp,
3347 const struct psp_fw_bin_desc *desc,
3348 const struct psp_firmware_header_v2_0 *sos_hdr)
3350 uint8_t *ucode_start_addr = NULL;
3352 if (!psp || !desc || !sos_hdr)
3355 ucode_start_addr = (uint8_t *)sos_hdr +
3356 le32_to_cpu(desc->offset_bytes) +
3357 le32_to_cpu(sos_hdr->header.ucode_array_offset_bytes);
3359 switch (desc->fw_type) {
3360 case PSP_FW_TYPE_PSP_SOS:
3361 psp->sos.fw_version = le32_to_cpu(desc->fw_version);
3362 psp->sos.feature_version = le32_to_cpu(desc->fw_version);
3363 psp->sos.size_bytes = le32_to_cpu(desc->size_bytes);
3364 psp->sos.start_addr = ucode_start_addr;
3366 case PSP_FW_TYPE_PSP_SYS_DRV:
3367 psp->sys.fw_version = le32_to_cpu(desc->fw_version);
3368 psp->sys.feature_version = le32_to_cpu(desc->fw_version);
3369 psp->sys.size_bytes = le32_to_cpu(desc->size_bytes);
3370 psp->sys.start_addr = ucode_start_addr;
3372 case PSP_FW_TYPE_PSP_KDB:
3373 psp->kdb.fw_version = le32_to_cpu(desc->fw_version);
3374 psp->kdb.feature_version = le32_to_cpu(desc->fw_version);
3375 psp->kdb.size_bytes = le32_to_cpu(desc->size_bytes);
3376 psp->kdb.start_addr = ucode_start_addr;
3378 case PSP_FW_TYPE_PSP_TOC:
3379 psp->toc.fw_version = le32_to_cpu(desc->fw_version);
3380 psp->toc.feature_version = le32_to_cpu(desc->fw_version);
3381 psp->toc.size_bytes = le32_to_cpu(desc->size_bytes);
3382 psp->toc.start_addr = ucode_start_addr;
3384 case PSP_FW_TYPE_PSP_SPL:
3385 psp->spl.fw_version = le32_to_cpu(desc->fw_version);
3386 psp->spl.feature_version = le32_to_cpu(desc->fw_version);
3387 psp->spl.size_bytes = le32_to_cpu(desc->size_bytes);
3388 psp->spl.start_addr = ucode_start_addr;
3390 case PSP_FW_TYPE_PSP_RL:
3391 psp->rl.fw_version = le32_to_cpu(desc->fw_version);
3392 psp->rl.feature_version = le32_to_cpu(desc->fw_version);
3393 psp->rl.size_bytes = le32_to_cpu(desc->size_bytes);
3394 psp->rl.start_addr = ucode_start_addr;
3396 case PSP_FW_TYPE_PSP_SOC_DRV:
3397 psp->soc_drv.fw_version = le32_to_cpu(desc->fw_version);
3398 psp->soc_drv.feature_version = le32_to_cpu(desc->fw_version);
3399 psp->soc_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3400 psp->soc_drv.start_addr = ucode_start_addr;
3402 case PSP_FW_TYPE_PSP_INTF_DRV:
3403 psp->intf_drv.fw_version = le32_to_cpu(desc->fw_version);
3404 psp->intf_drv.feature_version = le32_to_cpu(desc->fw_version);
3405 psp->intf_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3406 psp->intf_drv.start_addr = ucode_start_addr;
3408 case PSP_FW_TYPE_PSP_DBG_DRV:
3409 psp->dbg_drv.fw_version = le32_to_cpu(desc->fw_version);
3410 psp->dbg_drv.feature_version = le32_to_cpu(desc->fw_version);
3411 psp->dbg_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3412 psp->dbg_drv.start_addr = ucode_start_addr;
3414 case PSP_FW_TYPE_PSP_RAS_DRV:
3415 psp->ras_drv.fw_version = le32_to_cpu(desc->fw_version);
3416 psp->ras_drv.feature_version = le32_to_cpu(desc->fw_version);
3417 psp->ras_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3418 psp->ras_drv.start_addr = ucode_start_addr;
3420 case PSP_FW_TYPE_PSP_IPKEYMGR_DRV:
3421 psp->ipkeymgr_drv.fw_version = le32_to_cpu(desc->fw_version);
3422 psp->ipkeymgr_drv.feature_version = le32_to_cpu(desc->fw_version);
3423 psp->ipkeymgr_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3424 psp->ipkeymgr_drv.start_addr = ucode_start_addr;
3426 case PSP_FW_TYPE_PSP_SPDM_DRV:
3427 psp->spdm_drv.fw_version = le32_to_cpu(desc->fw_version);
3428 psp->spdm_drv.feature_version = le32_to_cpu(desc->fw_version);
3429 psp->spdm_drv.size_bytes = le32_to_cpu(desc->size_bytes);
3430 psp->spdm_drv.start_addr = ucode_start_addr;
3433 dev_warn(psp->adev->dev, "Unsupported PSP FW type: %d\n", desc->fw_type);
3440 static int psp_init_sos_base_fw(struct amdgpu_device *adev)
3442 const struct psp_firmware_header_v1_0 *sos_hdr;
3443 const struct psp_firmware_header_v1_3 *sos_hdr_v1_3;
3444 uint8_t *ucode_array_start_addr;
3446 sos_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.sos_fw->data;
3447 ucode_array_start_addr = (uint8_t *)sos_hdr +
3448 le32_to_cpu(sos_hdr->header.ucode_array_offset_bytes);
3450 if (adev->gmc.xgmi.connected_to_cpu ||
3451 (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 2))) {
3452 adev->psp.sos.fw_version = le32_to_cpu(sos_hdr->header.ucode_version);
3453 adev->psp.sos.feature_version = le32_to_cpu(sos_hdr->sos.fw_version);
3455 adev->psp.sys.size_bytes = le32_to_cpu(sos_hdr->sos.offset_bytes);
3456 adev->psp.sys.start_addr = ucode_array_start_addr;
3458 adev->psp.sos.size_bytes = le32_to_cpu(sos_hdr->sos.size_bytes);
3459 adev->psp.sos.start_addr = ucode_array_start_addr +
3460 le32_to_cpu(sos_hdr->sos.offset_bytes);
3462 /* Load alternate PSP SOS FW */
3463 sos_hdr_v1_3 = (const struct psp_firmware_header_v1_3 *)adev->psp.sos_fw->data;
3465 adev->psp.sos.fw_version = le32_to_cpu(sos_hdr_v1_3->sos_aux.fw_version);
3466 adev->psp.sos.feature_version = le32_to_cpu(sos_hdr_v1_3->sos_aux.fw_version);
3468 adev->psp.sys.size_bytes = le32_to_cpu(sos_hdr_v1_3->sys_drv_aux.size_bytes);
3469 adev->psp.sys.start_addr = ucode_array_start_addr +
3470 le32_to_cpu(sos_hdr_v1_3->sys_drv_aux.offset_bytes);
3472 adev->psp.sos.size_bytes = le32_to_cpu(sos_hdr_v1_3->sos_aux.size_bytes);
3473 adev->psp.sos.start_addr = ucode_array_start_addr +
3474 le32_to_cpu(sos_hdr_v1_3->sos_aux.offset_bytes);
3477 if ((adev->psp.sys.size_bytes == 0) || (adev->psp.sos.size_bytes == 0)) {
3478 dev_warn(adev->dev, "PSP SOS FW not available");
3485 int psp_init_sos_microcode(struct psp_context *psp, const char *chip_name)
3487 struct amdgpu_device *adev = psp->adev;
3488 const struct psp_firmware_header_v1_0 *sos_hdr;
3489 const struct psp_firmware_header_v1_1 *sos_hdr_v1_1;
3490 const struct psp_firmware_header_v1_2 *sos_hdr_v1_2;
3491 const struct psp_firmware_header_v1_3 *sos_hdr_v1_3;
3492 const struct psp_firmware_header_v2_0 *sos_hdr_v2_0;
3493 const struct psp_firmware_header_v2_1 *sos_hdr_v2_1;
3494 int fw_index, fw_bin_count, start_index = 0;
3495 const struct psp_fw_bin_desc *fw_bin;
3496 uint8_t *ucode_array_start_addr;
3499 err = amdgpu_ucode_request(adev, &adev->psp.sos_fw, AMDGPU_UCODE_REQUIRED,
3500 "amdgpu/%s_sos.bin", chip_name);
3504 sos_hdr = (const struct psp_firmware_header_v1_0 *)adev->psp.sos_fw->data;
3505 ucode_array_start_addr = (uint8_t *)sos_hdr +
3506 le32_to_cpu(sos_hdr->header.ucode_array_offset_bytes);
3507 amdgpu_ucode_print_psp_hdr(&sos_hdr->header);
3509 switch (sos_hdr->header.header_version_major) {
3511 err = psp_init_sos_base_fw(adev);
3515 if (sos_hdr->header.header_version_minor == 1) {
3516 sos_hdr_v1_1 = (const struct psp_firmware_header_v1_1 *)adev->psp.sos_fw->data;
3517 adev->psp.toc.size_bytes = le32_to_cpu(sos_hdr_v1_1->toc.size_bytes);
3518 adev->psp.toc.start_addr = (uint8_t *)adev->psp.sys.start_addr +
3519 le32_to_cpu(sos_hdr_v1_1->toc.offset_bytes);
3520 adev->psp.kdb.size_bytes = le32_to_cpu(sos_hdr_v1_1->kdb.size_bytes);
3521 adev->psp.kdb.start_addr = (uint8_t *)adev->psp.sys.start_addr +
3522 le32_to_cpu(sos_hdr_v1_1->kdb.offset_bytes);
3524 if (sos_hdr->header.header_version_minor == 2) {
3525 sos_hdr_v1_2 = (const struct psp_firmware_header_v1_2 *)adev->psp.sos_fw->data;
3526 adev->psp.kdb.size_bytes = le32_to_cpu(sos_hdr_v1_2->kdb.size_bytes);
3527 adev->psp.kdb.start_addr = (uint8_t *)adev->psp.sys.start_addr +
3528 le32_to_cpu(sos_hdr_v1_2->kdb.offset_bytes);
3530 if (sos_hdr->header.header_version_minor == 3) {
3531 sos_hdr_v1_3 = (const struct psp_firmware_header_v1_3 *)adev->psp.sos_fw->data;
3532 adev->psp.toc.size_bytes = le32_to_cpu(sos_hdr_v1_3->v1_1.toc.size_bytes);
3533 adev->psp.toc.start_addr = ucode_array_start_addr +
3534 le32_to_cpu(sos_hdr_v1_3->v1_1.toc.offset_bytes);
3535 adev->psp.kdb.size_bytes = le32_to_cpu(sos_hdr_v1_3->v1_1.kdb.size_bytes);
3536 adev->psp.kdb.start_addr = ucode_array_start_addr +
3537 le32_to_cpu(sos_hdr_v1_3->v1_1.kdb.offset_bytes);
3538 adev->psp.spl.size_bytes = le32_to_cpu(sos_hdr_v1_3->spl.size_bytes);
3539 adev->psp.spl.start_addr = ucode_array_start_addr +
3540 le32_to_cpu(sos_hdr_v1_3->spl.offset_bytes);
3541 adev->psp.rl.size_bytes = le32_to_cpu(sos_hdr_v1_3->rl.size_bytes);
3542 adev->psp.rl.start_addr = ucode_array_start_addr +
3543 le32_to_cpu(sos_hdr_v1_3->rl.offset_bytes);
3547 sos_hdr_v2_0 = (const struct psp_firmware_header_v2_0 *)adev->psp.sos_fw->data;
3549 fw_bin_count = le32_to_cpu(sos_hdr_v2_0->psp_fw_bin_count);
3551 if (fw_bin_count >= UCODE_MAX_PSP_PACKAGING) {
3552 dev_err(adev->dev, "packed SOS count exceeds maximum limit\n");
3557 if (sos_hdr_v2_0->header.header_version_minor == 1) {
3558 sos_hdr_v2_1 = (const struct psp_firmware_header_v2_1 *)adev->psp.sos_fw->data;
3560 fw_bin = sos_hdr_v2_1->psp_fw_bin;
3562 if (psp_is_aux_sos_load_required(psp))
3563 start_index = le32_to_cpu(sos_hdr_v2_1->psp_aux_fw_bin_index);
3565 fw_bin_count -= le32_to_cpu(sos_hdr_v2_1->psp_aux_fw_bin_index);
3568 fw_bin = sos_hdr_v2_0->psp_fw_bin;
3571 for (fw_index = start_index; fw_index < fw_bin_count; fw_index++) {
3572 err = parse_sos_bin_descriptor(psp, fw_bin + fw_index,
3580 "unsupported psp sos firmware\n");
3587 amdgpu_ucode_release(&adev->psp.sos_fw);
3592 static bool is_ta_fw_applicable(struct psp_context *psp,
3593 const struct psp_fw_bin_desc *desc)
3595 struct amdgpu_device *adev = psp->adev;
3596 uint32_t fw_version;
3598 switch (desc->fw_type) {
3599 case TA_FW_TYPE_PSP_XGMI:
3600 case TA_FW_TYPE_PSP_XGMI_AUX:
3601 /* for now, AUX TA only exists on 13.0.6 ta bin,
3604 if (amdgpu_ip_version(adev, MP0_HWIP, 0) ==
3605 IP_VERSION(13, 0, 6)) {
3606 fw_version = le32_to_cpu(desc->fw_version);
3608 if (adev->flags & AMD_IS_APU &&
3609 (fw_version & 0xff) >= 0x14)
3610 return desc->fw_type == TA_FW_TYPE_PSP_XGMI_AUX;
3612 return desc->fw_type == TA_FW_TYPE_PSP_XGMI;
3622 static int parse_ta_bin_descriptor(struct psp_context *psp,
3623 const struct psp_fw_bin_desc *desc,
3624 const struct ta_firmware_header_v2_0 *ta_hdr)
3626 uint8_t *ucode_start_addr = NULL;
3628 if (!psp || !desc || !ta_hdr)
3631 if (!is_ta_fw_applicable(psp, desc))
3634 ucode_start_addr = (uint8_t *)ta_hdr +
3635 le32_to_cpu(desc->offset_bytes) +
3636 le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
3638 switch (desc->fw_type) {
3639 case TA_FW_TYPE_PSP_ASD:
3640 psp->asd_context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3641 psp->asd_context.bin_desc.feature_version = le32_to_cpu(desc->fw_version);
3642 psp->asd_context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3643 psp->asd_context.bin_desc.start_addr = ucode_start_addr;
3645 case TA_FW_TYPE_PSP_XGMI:
3646 case TA_FW_TYPE_PSP_XGMI_AUX:
3647 psp->xgmi_context.context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3648 psp->xgmi_context.context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3649 psp->xgmi_context.context.bin_desc.start_addr = ucode_start_addr;
3651 case TA_FW_TYPE_PSP_RAS:
3652 psp->ras_context.context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3653 psp->ras_context.context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3654 psp->ras_context.context.bin_desc.start_addr = ucode_start_addr;
3656 case TA_FW_TYPE_PSP_HDCP:
3657 psp->hdcp_context.context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3658 psp->hdcp_context.context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3659 psp->hdcp_context.context.bin_desc.start_addr = ucode_start_addr;
3661 case TA_FW_TYPE_PSP_DTM:
3662 psp->dtm_context.context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3663 psp->dtm_context.context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3664 psp->dtm_context.context.bin_desc.start_addr = ucode_start_addr;
3666 case TA_FW_TYPE_PSP_RAP:
3667 psp->rap_context.context.bin_desc.fw_version = le32_to_cpu(desc->fw_version);
3668 psp->rap_context.context.bin_desc.size_bytes = le32_to_cpu(desc->size_bytes);
3669 psp->rap_context.context.bin_desc.start_addr = ucode_start_addr;
3671 case TA_FW_TYPE_PSP_SECUREDISPLAY:
3672 psp->securedisplay_context.context.bin_desc.fw_version =
3673 le32_to_cpu(desc->fw_version);
3674 psp->securedisplay_context.context.bin_desc.size_bytes =
3675 le32_to_cpu(desc->size_bytes);
3676 psp->securedisplay_context.context.bin_desc.start_addr =
3680 dev_warn(psp->adev->dev, "Unsupported TA type: %d\n", desc->fw_type);
3687 static int parse_ta_v1_microcode(struct psp_context *psp)
3689 const struct ta_firmware_header_v1_0 *ta_hdr;
3690 struct amdgpu_device *adev = psp->adev;
3692 ta_hdr = (const struct ta_firmware_header_v1_0 *) adev->psp.ta_fw->data;
3694 if (le16_to_cpu(ta_hdr->header.header_version_major) != 1)
3697 adev->psp.xgmi_context.context.bin_desc.fw_version =
3698 le32_to_cpu(ta_hdr->xgmi.fw_version);
3699 adev->psp.xgmi_context.context.bin_desc.size_bytes =
3700 le32_to_cpu(ta_hdr->xgmi.size_bytes);
3701 adev->psp.xgmi_context.context.bin_desc.start_addr =
3703 le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
3705 adev->psp.ras_context.context.bin_desc.fw_version =
3706 le32_to_cpu(ta_hdr->ras.fw_version);
3707 adev->psp.ras_context.context.bin_desc.size_bytes =
3708 le32_to_cpu(ta_hdr->ras.size_bytes);
3709 adev->psp.ras_context.context.bin_desc.start_addr =
3710 (uint8_t *)adev->psp.xgmi_context.context.bin_desc.start_addr +
3711 le32_to_cpu(ta_hdr->ras.offset_bytes);
3713 adev->psp.hdcp_context.context.bin_desc.fw_version =
3714 le32_to_cpu(ta_hdr->hdcp.fw_version);
3715 adev->psp.hdcp_context.context.bin_desc.size_bytes =
3716 le32_to_cpu(ta_hdr->hdcp.size_bytes);
3717 adev->psp.hdcp_context.context.bin_desc.start_addr =
3719 le32_to_cpu(ta_hdr->header.ucode_array_offset_bytes);
3721 adev->psp.dtm_context.context.bin_desc.fw_version =
3722 le32_to_cpu(ta_hdr->dtm.fw_version);
3723 adev->psp.dtm_context.context.bin_desc.size_bytes =
3724 le32_to_cpu(ta_hdr->dtm.size_bytes);
3725 adev->psp.dtm_context.context.bin_desc.start_addr =
3726 (uint8_t *)adev->psp.hdcp_context.context.bin_desc.start_addr +
3727 le32_to_cpu(ta_hdr->dtm.offset_bytes);
3729 adev->psp.securedisplay_context.context.bin_desc.fw_version =
3730 le32_to_cpu(ta_hdr->securedisplay.fw_version);
3731 adev->psp.securedisplay_context.context.bin_desc.size_bytes =
3732 le32_to_cpu(ta_hdr->securedisplay.size_bytes);
3733 adev->psp.securedisplay_context.context.bin_desc.start_addr =
3734 (uint8_t *)adev->psp.hdcp_context.context.bin_desc.start_addr +
3735 le32_to_cpu(ta_hdr->securedisplay.offset_bytes);
3737 adev->psp.ta_fw_version = le32_to_cpu(ta_hdr->header.ucode_version);
3742 static int parse_ta_v2_microcode(struct psp_context *psp)
3744 const struct ta_firmware_header_v2_0 *ta_hdr;
3745 struct amdgpu_device *adev = psp->adev;
3749 ta_hdr = (const struct ta_firmware_header_v2_0 *)adev->psp.ta_fw->data;
3751 if (le16_to_cpu(ta_hdr->header.header_version_major) != 2)
3754 if (le32_to_cpu(ta_hdr->ta_fw_bin_count) >= UCODE_MAX_PSP_PACKAGING) {
3755 dev_err(adev->dev, "packed TA count exceeds maximum limit\n");
3759 for (ta_index = 0; ta_index < le32_to_cpu(ta_hdr->ta_fw_bin_count); ta_index++) {
3760 err = parse_ta_bin_descriptor(psp,
3761 &ta_hdr->ta_fw_bin[ta_index],
3770 int psp_init_ta_microcode(struct psp_context *psp, const char *chip_name)
3772 const struct common_firmware_header *hdr;
3773 struct amdgpu_device *adev = psp->adev;
3776 err = amdgpu_ucode_request(adev, &adev->psp.ta_fw, AMDGPU_UCODE_REQUIRED,
3777 "amdgpu/%s_ta.bin", chip_name);
3781 hdr = (const struct common_firmware_header *)adev->psp.ta_fw->data;
3782 switch (le16_to_cpu(hdr->header_version_major)) {
3784 err = parse_ta_v1_microcode(psp);
3787 err = parse_ta_v2_microcode(psp);
3790 dev_err(adev->dev, "unsupported TA header version\n");
3795 amdgpu_ucode_release(&adev->psp.ta_fw);
3800 int psp_init_cap_microcode(struct psp_context *psp, const char *chip_name)
3802 struct amdgpu_device *adev = psp->adev;
3803 const struct psp_firmware_header_v1_0 *cap_hdr_v1_0;
3804 struct amdgpu_firmware_info *info = NULL;
3807 if (!amdgpu_sriov_vf(adev)) {
3808 dev_err(adev->dev, "cap microcode should only be loaded under SRIOV\n");
3812 err = amdgpu_ucode_request(adev, &adev->psp.cap_fw, AMDGPU_UCODE_OPTIONAL,
3813 "amdgpu/%s_cap.bin", chip_name);
3815 if (err == -ENODEV) {
3816 dev_warn(adev->dev, "cap microcode does not exist, skip\n");
3820 dev_err(adev->dev, "fail to initialize cap microcode\n");
3823 info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CAP];
3824 info->ucode_id = AMDGPU_UCODE_ID_CAP;
3825 info->fw = adev->psp.cap_fw;
3826 cap_hdr_v1_0 = (const struct psp_firmware_header_v1_0 *)
3827 adev->psp.cap_fw->data;
3828 adev->firmware.fw_size += ALIGN(
3829 le32_to_cpu(cap_hdr_v1_0->header.ucode_size_bytes), PAGE_SIZE);
3830 adev->psp.cap_fw_version = le32_to_cpu(cap_hdr_v1_0->header.ucode_version);
3831 adev->psp.cap_feature_version = le32_to_cpu(cap_hdr_v1_0->sos.fw_version);
3832 adev->psp.cap_ucode_size = le32_to_cpu(cap_hdr_v1_0->header.ucode_size_bytes);
3837 amdgpu_ucode_release(&adev->psp.cap_fw);
3841 int psp_config_sq_perfmon(struct psp_context *psp,
3842 uint32_t xcp_id, bool core_override_enable,
3843 bool reg_override_enable, bool perfmon_override_enable)
3847 if (amdgpu_sriov_vf(psp->adev))
3850 if (xcp_id > MAX_XCP) {
3851 dev_err(psp->adev->dev, "invalid xcp_id %d\n", xcp_id);
3855 if (amdgpu_ip_version(psp->adev, MP0_HWIP, 0) != IP_VERSION(13, 0, 6)) {
3856 dev_err(psp->adev->dev, "Unsupported MP0 version 0x%x for CONFIG_SQ_PERFMON command\n",
3857 amdgpu_ip_version(psp->adev, MP0_HWIP, 0));
3860 struct psp_gfx_cmd_resp *cmd = acquire_psp_cmd_buf(psp);
3862 cmd->cmd_id = GFX_CMD_ID_CONFIG_SQ_PERFMON;
3863 cmd->cmd.config_sq_perfmon.gfx_xcp_mask = BIT_MASK(xcp_id);
3864 cmd->cmd.config_sq_perfmon.core_override = core_override_enable;
3865 cmd->cmd.config_sq_perfmon.reg_override = reg_override_enable;
3866 cmd->cmd.config_sq_perfmon.perfmon_override = perfmon_override_enable;
3868 ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
3870 dev_warn(psp->adev->dev, "PSP failed to config sq: xcp%d core%d reg%d perfmon%d\n",
3871 xcp_id, core_override_enable, reg_override_enable, perfmon_override_enable);
3873 release_psp_cmd_buf(psp);
3877 static int psp_set_clockgating_state(struct amdgpu_ip_block *ip_block,
3878 enum amd_clockgating_state state)
3883 static int psp_set_powergating_state(struct amdgpu_ip_block *ip_block,
3884 enum amd_powergating_state state)
3889 static ssize_t psp_usbc_pd_fw_sysfs_read(struct device *dev,
3890 struct device_attribute *attr,
3893 struct drm_device *ddev = dev_get_drvdata(dev);
3894 struct amdgpu_device *adev = drm_to_adev(ddev);
3895 struct amdgpu_ip_block *ip_block;
3899 ip_block = amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP);
3900 if (!ip_block || !ip_block->status.late_initialized) {
3901 dev_info(adev->dev, "PSP block is not ready yet\n.");
3905 mutex_lock(&adev->psp.mutex);
3906 ret = psp_read_usbc_pd_fw(&adev->psp, &fw_ver);
3907 mutex_unlock(&adev->psp.mutex);
3910 dev_err(adev->dev, "Failed to read USBC PD FW, err = %d\n", ret);
3914 return sysfs_emit(buf, "%x\n", fw_ver);
3917 static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,
3918 struct device_attribute *attr,
3922 struct drm_device *ddev = dev_get_drvdata(dev);
3923 struct amdgpu_device *adev = drm_to_adev(ddev);
3925 const struct firmware *usbc_pd_fw;
3926 struct amdgpu_bo *fw_buf_bo = NULL;
3927 uint64_t fw_pri_mc_addr;
3928 void *fw_pri_cpu_addr;
3929 struct amdgpu_ip_block *ip_block;
3931 ip_block = amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP);
3932 if (!ip_block || !ip_block->status.late_initialized) {
3933 dev_err(adev->dev, "PSP block is not ready yet.");
3937 if (!drm_dev_enter(ddev, &idx))
3940 ret = amdgpu_ucode_request(adev, &usbc_pd_fw, AMDGPU_UCODE_REQUIRED,
3945 /* LFB address which is aligned to 1MB boundary per PSP request */
3946 ret = amdgpu_bo_create_kernel(adev, usbc_pd_fw->size, 0x100000,
3947 AMDGPU_GEM_DOMAIN_VRAM |
3948 AMDGPU_GEM_DOMAIN_GTT,
3949 &fw_buf_bo, &fw_pri_mc_addr,
3954 memcpy_toio(fw_pri_cpu_addr, usbc_pd_fw->data, usbc_pd_fw->size);
3956 mutex_lock(&adev->psp.mutex);
3957 ret = psp_load_usbc_pd_fw(&adev->psp, fw_pri_mc_addr);
3958 mutex_unlock(&adev->psp.mutex);
3960 amdgpu_bo_free_kernel(&fw_buf_bo, &fw_pri_mc_addr, &fw_pri_cpu_addr);
3963 amdgpu_ucode_release(&usbc_pd_fw);
3966 dev_err(adev->dev, "Failed to load USBC PD FW, err = %d", ret);
3974 void psp_copy_fw(struct psp_context *psp, uint8_t *start_addr, uint32_t bin_size)
3978 if (!drm_dev_enter(adev_to_drm(psp->adev), &idx))
3981 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
3982 memcpy(psp->fw_pri_buf, start_addr, bin_size);
3989 * Reading from this file will retrieve the USB-C PD firmware version. Writing to
3990 * this file will trigger the update process.
3992 static DEVICE_ATTR(usbc_pd_fw, 0644,
3993 psp_usbc_pd_fw_sysfs_read,
3994 psp_usbc_pd_fw_sysfs_write);
3996 int is_psp_fw_valid(struct psp_bin_desc bin)
3998 return bin.size_bytes;
4001 static ssize_t amdgpu_psp_vbflash_write(struct file *filp, struct kobject *kobj,
4002 struct bin_attribute *bin_attr,
4003 char *buffer, loff_t pos, size_t count)
4005 struct device *dev = kobj_to_dev(kobj);
4006 struct drm_device *ddev = dev_get_drvdata(dev);
4007 struct amdgpu_device *adev = drm_to_adev(ddev);
4009 adev->psp.vbflash_done = false;
4011 /* Safeguard against memory drain */
4012 if (adev->psp.vbflash_image_size > AMD_VBIOS_FILE_MAX_SIZE_B) {
4013 dev_err(adev->dev, "File size cannot exceed %u\n", AMD_VBIOS_FILE_MAX_SIZE_B);
4014 kvfree(adev->psp.vbflash_tmp_buf);
4015 adev->psp.vbflash_tmp_buf = NULL;
4016 adev->psp.vbflash_image_size = 0;
4020 /* TODO Just allocate max for now and optimize to realloc later if needed */
4021 if (!adev->psp.vbflash_tmp_buf) {
4022 adev->psp.vbflash_tmp_buf = kvmalloc(AMD_VBIOS_FILE_MAX_SIZE_B, GFP_KERNEL);
4023 if (!adev->psp.vbflash_tmp_buf)
4027 mutex_lock(&adev->psp.mutex);
4028 memcpy(adev->psp.vbflash_tmp_buf + pos, buffer, count);
4029 adev->psp.vbflash_image_size += count;
4030 mutex_unlock(&adev->psp.mutex);
4032 dev_dbg(adev->dev, "IFWI staged for update\n");
4037 static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj,
4038 struct bin_attribute *bin_attr, char *buffer,
4039 loff_t pos, size_t count)
4041 struct device *dev = kobj_to_dev(kobj);
4042 struct drm_device *ddev = dev_get_drvdata(dev);
4043 struct amdgpu_device *adev = drm_to_adev(ddev);
4044 struct amdgpu_bo *fw_buf_bo = NULL;
4045 uint64_t fw_pri_mc_addr;
4046 void *fw_pri_cpu_addr;
4049 if (adev->psp.vbflash_image_size == 0)
4052 dev_dbg(adev->dev, "PSP IFWI flash process initiated\n");
4054 ret = amdgpu_bo_create_kernel(adev, adev->psp.vbflash_image_size,
4055 AMDGPU_GPU_PAGE_SIZE,
4056 AMDGPU_GEM_DOMAIN_VRAM,
4063 memcpy_toio(fw_pri_cpu_addr, adev->psp.vbflash_tmp_buf, adev->psp.vbflash_image_size);
4065 mutex_lock(&adev->psp.mutex);
4066 ret = psp_update_spirom(&adev->psp, fw_pri_mc_addr);
4067 mutex_unlock(&adev->psp.mutex);
4069 amdgpu_bo_free_kernel(&fw_buf_bo, &fw_pri_mc_addr, &fw_pri_cpu_addr);
4072 kvfree(adev->psp.vbflash_tmp_buf);
4073 adev->psp.vbflash_tmp_buf = NULL;
4074 adev->psp.vbflash_image_size = 0;
4077 dev_err(adev->dev, "Failed to load IFWI, err = %d\n", ret);
4081 dev_dbg(adev->dev, "PSP IFWI flash process done\n");
4087 * Writing to this file will stage an IFWI for update. Reading from this file
4088 * will trigger the update process.
4090 static struct bin_attribute psp_vbflash_bin_attr = {
4091 .attr = {.name = "psp_vbflash", .mode = 0660},
4093 .write = amdgpu_psp_vbflash_write,
4094 .read = amdgpu_psp_vbflash_read,
4098 * DOC: psp_vbflash_status
4099 * The status of the flash process.
4100 * 0: IFWI flash not complete.
4101 * 1: IFWI flash complete.
4103 static ssize_t amdgpu_psp_vbflash_status(struct device *dev,
4104 struct device_attribute *attr,
4107 struct drm_device *ddev = dev_get_drvdata(dev);
4108 struct amdgpu_device *adev = drm_to_adev(ddev);
4109 uint32_t vbflash_status;
4111 vbflash_status = psp_vbflash_status(&adev->psp);
4112 if (!adev->psp.vbflash_done)
4114 else if (adev->psp.vbflash_done && !(vbflash_status & 0x80000000))
4117 return sysfs_emit(buf, "0x%x\n", vbflash_status);
4119 static DEVICE_ATTR(psp_vbflash_status, 0440, amdgpu_psp_vbflash_status, NULL);
4121 static struct bin_attribute *bin_flash_attrs[] = {
4122 &psp_vbflash_bin_attr,
4126 static struct attribute *flash_attrs[] = {
4127 &dev_attr_psp_vbflash_status.attr,
4128 &dev_attr_usbc_pd_fw.attr,
4132 static umode_t amdgpu_flash_attr_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
4134 struct device *dev = kobj_to_dev(kobj);
4135 struct drm_device *ddev = dev_get_drvdata(dev);
4136 struct amdgpu_device *adev = drm_to_adev(ddev);
4138 if (attr == &dev_attr_usbc_pd_fw.attr)
4139 return adev->psp.sup_pd_fw_up ? 0660 : 0;
4141 return adev->psp.sup_ifwi_up ? 0440 : 0;
4144 static umode_t amdgpu_bin_flash_attr_is_visible(struct kobject *kobj,
4145 const struct bin_attribute *attr,
4148 struct device *dev = kobj_to_dev(kobj);
4149 struct drm_device *ddev = dev_get_drvdata(dev);
4150 struct amdgpu_device *adev = drm_to_adev(ddev);
4152 return adev->psp.sup_ifwi_up ? 0660 : 0;
4155 const struct attribute_group amdgpu_flash_attr_group = {
4156 .attrs = flash_attrs,
4157 .bin_attrs = bin_flash_attrs,
4158 .is_bin_visible = amdgpu_bin_flash_attr_is_visible,
4159 .is_visible = amdgpu_flash_attr_is_visible,
4162 const struct amd_ip_funcs psp_ip_funcs = {
4164 .early_init = psp_early_init,
4165 .sw_init = psp_sw_init,
4166 .sw_fini = psp_sw_fini,
4167 .hw_init = psp_hw_init,
4168 .hw_fini = psp_hw_fini,
4169 .suspend = psp_suspend,
4170 .resume = psp_resume,
4171 .set_clockgating_state = psp_set_clockgating_state,
4172 .set_powergating_state = psp_set_powergating_state,
4175 const struct amdgpu_ip_block_version psp_v3_1_ip_block = {
4176 .type = AMD_IP_BLOCK_TYPE_PSP,
4180 .funcs = &psp_ip_funcs,
4183 const struct amdgpu_ip_block_version psp_v10_0_ip_block = {
4184 .type = AMD_IP_BLOCK_TYPE_PSP,
4188 .funcs = &psp_ip_funcs,
4191 const struct amdgpu_ip_block_version psp_v11_0_ip_block = {
4192 .type = AMD_IP_BLOCK_TYPE_PSP,
4196 .funcs = &psp_ip_funcs,
4199 const struct amdgpu_ip_block_version psp_v11_0_8_ip_block = {
4200 .type = AMD_IP_BLOCK_TYPE_PSP,
4204 .funcs = &psp_ip_funcs,
4207 const struct amdgpu_ip_block_version psp_v12_0_ip_block = {
4208 .type = AMD_IP_BLOCK_TYPE_PSP,
4212 .funcs = &psp_ip_funcs,
4215 const struct amdgpu_ip_block_version psp_v13_0_ip_block = {
4216 .type = AMD_IP_BLOCK_TYPE_PSP,
4220 .funcs = &psp_ip_funcs,
4223 const struct amdgpu_ip_block_version psp_v13_0_4_ip_block = {
4224 .type = AMD_IP_BLOCK_TYPE_PSP,
4228 .funcs = &psp_ip_funcs,
4231 const struct amdgpu_ip_block_version psp_v14_0_ip_block = {
4232 .type = AMD_IP_BLOCK_TYPE_PSP,
4236 .funcs = &psp_ip_funcs,