···11+/*22+ * Copyright 2025 Advanced Micro Devices, Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ */2323+#include <drm/drm_drv.h>2424+#include <linux/vmalloc.h>2525+#include "amdgpu.h"2626+#include "amdgpu_psp.h"2727+#include "amdgpu_ucode.h"2828+#include "soc15_common.h"2929+#include "psp_v15_0.h"3030+3131+#include "mp/mp_15_0_0_offset.h"3232+#include "mp/mp_15_0_0_sh_mask.h"3333+3434+MODULE_FIRMWARE("amdgpu/psp_15_0_0_toc.bin");3535+3636+static int psp_v15_0_0_init_microcode(struct psp_context *psp)3737+{3838+ struct amdgpu_device *adev = psp->adev;3939+ char ucode_prefix[30];4040+ int err = 0;4141+4242+ amdgpu_ucode_ip_version_decode(adev, MP0_HWIP, ucode_prefix, sizeof(ucode_prefix));4343+4444+ err = psp_init_toc_microcode(psp, ucode_prefix);4545+ if (err)4646+ return err;4747+4848+ return 0;4949+}5050+5151+static int psp_v15_0_0_ring_stop(struct psp_context *psp,5252+ enum psp_ring_type ring_type)5353+{5454+ int ret = 0;5555+ struct amdgpu_device *adev = psp->adev;5656+5757+ if (amdgpu_sriov_vf(adev)) {5858+ /* Write the ring destroy command*/5959+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_101,6060+ GFX_CTRL_CMD_ID_DESTROY_GPCOM_RING);6161+ /* there might be handshake issue with hardware which needs delay */6262+ mdelay(20);6363+ /* Wait for response flag (bit 31) */6464+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMPASP_SMN_C2PMSG_101),6565+ 0x80000000, 0x80000000, false);6666+ } else {6767+ /* Write the ring destroy command*/6868+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_64,6969+ GFX_CTRL_CMD_ID_DESTROY_RINGS);7070+ /* there might be handshake issue with hardware which needs delay */7171+ mdelay(20);7272+ /* Wait for response flag (bit 31) */7373+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMPASP_SMN_C2PMSG_64),7474+ 0x80000000, 0x80000000, false);7575+ }7676+7777+ return ret;7878+}7979+8080+static int psp_v15_0_0_ring_create(struct psp_context *psp,8181+ enum psp_ring_type ring_type)8282+{8383+ int ret = 0;8484+ unsigned int psp_ring_reg = 0;8585+ struct psp_ring *ring = &psp->km_ring;8686+ struct amdgpu_device *adev = psp->adev;8787+8888+ if (amdgpu_sriov_vf(adev)) {8989+ ret = psp_v15_0_0_ring_stop(psp, ring_type);9090+ if (ret) {9191+ DRM_ERROR("psp_v14_0_ring_stop_sriov failed!\n");9292+ return ret;9393+ }9494+9595+ /* Write low address of the ring to C2PMSG_102 */9696+ psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);9797+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_102, psp_ring_reg);9898+ /* Write high address of the ring to C2PMSG_103 */9999+ psp_ring_reg = upper_32_bits(ring->ring_mem_mc_addr);100100+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_103, psp_ring_reg);101101+102102+ /* Write the ring initialization command to C2PMSG_101 */103103+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_101,104104+ GFX_CTRL_CMD_ID_INIT_GPCOM_RING);105105+106106+ /* there might be handshake issue with hardware which needs delay */107107+ mdelay(20);108108+109109+ /* Wait for response flag (bit 31) in C2PMSG_101 */110110+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMPASP_SMN_C2PMSG_101),111111+ 0x80000000, 0x8000FFFF, false);112112+113113+ } else {114114+ /* Wait for sOS ready for ring creation */115115+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMPASP_SMN_C2PMSG_64),116116+ 0x80000000, 0x80000000, false);117117+ if (ret) {118118+ DRM_ERROR("Failed to wait for trust OS ready for ring creation\n");119119+ return ret;120120+ }121121+122122+ /* Write low address of the ring to C2PMSG_69 */123123+ psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);124124+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_69, psp_ring_reg);125125+ /* Write high address of the ring to C2PMSG_70 */126126+ psp_ring_reg = upper_32_bits(ring->ring_mem_mc_addr);127127+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_70, psp_ring_reg);128128+ /* Write size of ring to C2PMSG_71 */129129+ psp_ring_reg = ring->ring_size;130130+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_71, psp_ring_reg);131131+ /* Write the ring initialization command to C2PMSG_64 */132132+ psp_ring_reg = ring_type;133133+ psp_ring_reg = psp_ring_reg << 16;134134+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_64, psp_ring_reg);135135+136136+ /* there might be handshake issue with hardware which needs delay */137137+ mdelay(20);138138+139139+ /* Wait for response flag (bit 31) in C2PMSG_64 */140140+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMPASP_SMN_C2PMSG_64),141141+ 0x80000000, 0x8000FFFF, false);142142+ }143143+144144+ return ret;145145+}146146+147147+static int psp_v15_0_0_ring_destroy(struct psp_context *psp,148148+ enum psp_ring_type ring_type)149149+{150150+ int ret = 0;151151+ struct psp_ring *ring = &psp->km_ring;152152+ struct amdgpu_device *adev = psp->adev;153153+154154+ ret = psp_v15_0_0_ring_stop(psp, ring_type);155155+ if (ret)156156+ DRM_ERROR("Fail to stop psp ring\n");157157+158158+ amdgpu_bo_free_kernel(&adev->firmware.rbuf,159159+ &ring->ring_mem_mc_addr,160160+ (void **)&ring->ring_mem);161161+162162+ return ret;163163+}164164+165165+static uint32_t psp_v15_0_0_ring_get_wptr(struct psp_context *psp)166166+{167167+ uint32_t data;168168+ struct amdgpu_device *adev = psp->adev;169169+170170+ if (amdgpu_sriov_vf(adev))171171+ data = RREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_102);172172+ else173173+ data = RREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_67);174174+175175+ return data;176176+}177177+178178+static void psp_v15_0_0_ring_set_wptr(struct psp_context *psp, uint32_t value)179179+{180180+ struct amdgpu_device *adev = psp->adev;181181+182182+ if (amdgpu_sriov_vf(adev)) {183183+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_102, value);184184+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_101,185185+ GFX_CTRL_CMD_ID_CONSUME_CMD);186186+ } else187187+ WREG32_SOC15(MP0, 0, regMPASP_SMN_C2PMSG_67, value);188188+}189189+190190+static const struct psp_funcs psp_v15_0_0_funcs = {191191+ .init_microcode = psp_v15_0_0_init_microcode,192192+ .ring_create = psp_v15_0_0_ring_create,193193+ .ring_stop = psp_v15_0_0_ring_stop,194194+ .ring_destroy = psp_v15_0_0_ring_destroy,195195+ .ring_get_wptr = psp_v15_0_0_ring_get_wptr,196196+ .ring_set_wptr = psp_v15_0_0_ring_set_wptr,197197+};198198+199199+void psp_v15_0_0_set_psp_funcs(struct psp_context *psp)200200+{201201+ psp->funcs = &psp_v15_0_0_funcs;202202+}
+30
drivers/gpu/drm/amd/amdgpu/psp_v15_0.h
···11+/*22+ * Copyright 2025 Advanced Micro Devices, Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ */2323+#ifndef __PSP_V15_0_0_H__2424+#define __PSP_V15_0_0_H__2525+2626+#include "amdgpu_psp.h"2727+2828+void psp_v15_0_0_set_psp_funcs(struct psp_context *psp);2929+3030+#endif