···11+/*22+ * Copyright 2021 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 "amdgpu.h"2424+#include "amdgpu_psp.h"2525+#include "amdgpu_ucode.h"2626+#include "soc15_common.h"2727+#include "psp_v11_0_8.h"2828+2929+#include "mp/mp_11_0_8_offset.h"3030+3131+static int psp_v11_0_8_ring_init(struct psp_context *psp,3232+ enum psp_ring_type ring_type)3333+{3434+ int ret = 0;3535+ struct psp_ring *ring;3636+ struct amdgpu_device *adev = psp->adev;3737+3838+ ring = &psp->km_ring;3939+4040+ ring->ring_type = ring_type;4141+4242+ /* allocate 4k Page of Local Frame Buffer memory for ring */4343+ ring->ring_size = 0x1000;4444+ ret = amdgpu_bo_create_kernel(adev, ring->ring_size, PAGE_SIZE,4545+ AMDGPU_GEM_DOMAIN_VRAM,4646+ &adev->firmware.rbuf,4747+ &ring->ring_mem_mc_addr,4848+ (void **)&ring->ring_mem);4949+ if (ret) {5050+ ring->ring_size = 0;5151+ return ret;5252+ }5353+5454+ return 0;5555+}5656+5757+static int psp_v11_0_8_ring_stop(struct psp_context *psp,5858+ enum psp_ring_type ring_type)5959+{6060+ int ret = 0;6161+ struct amdgpu_device *adev = psp->adev;6262+6363+ if (amdgpu_sriov_vf(adev)) {6464+ /* Write the ring destroy command*/6565+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101,6666+ GFX_CTRL_CMD_ID_DESTROY_GPCOM_RING);6767+ /* there might be handshake issue with hardware which needs delay */6868+ mdelay(20);6969+ /* Wait for response flag (bit 31) */7070+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_101),7171+ 0x80000000, 0x80000000, false);7272+ } else {7373+ /* Write the ring destroy command*/7474+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_64,7575+ GFX_CTRL_CMD_ID_DESTROY_RINGS);7676+ /* there might be handshake issue with hardware which needs delay */7777+ mdelay(20);7878+ /* Wait for response flag (bit 31) */7979+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64),8080+ 0x80000000, 0x80000000, false);8181+ }8282+8383+ return ret;8484+}8585+8686+static int psp_v11_0_8_ring_create(struct psp_context *psp,8787+ enum psp_ring_type ring_type)8888+{8989+ int ret = 0;9090+ unsigned int psp_ring_reg = 0;9191+ struct psp_ring *ring = &psp->km_ring;9292+ struct amdgpu_device *adev = psp->adev;9393+9494+ if (amdgpu_sriov_vf(adev)) {9595+ ret = psp_v11_0_8_ring_stop(psp, ring_type);9696+ if (ret) {9797+ DRM_ERROR("psp_v11_0_8_ring_stop_sriov failed!\n");9898+ return ret;9999+ }100100+101101+ /* Write low address of the ring to C2PMSG_102 */102102+ psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);103103+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg);104104+ /* Write high address of the ring to C2PMSG_103 */105105+ psp_ring_reg = upper_32_bits(ring->ring_mem_mc_addr);106106+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_103, psp_ring_reg);107107+108108+ /* Write the ring initialization command to C2PMSG_101 */109109+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101,110110+ GFX_CTRL_CMD_ID_INIT_GPCOM_RING);111111+112112+ /* there might be handshake issue with hardware which needs delay */113113+ mdelay(20);114114+115115+ /* Wait for response flag (bit 31) in C2PMSG_101 */116116+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_101),117117+ 0x80000000, 0x8000FFFF, false);118118+119119+ } else {120120+ /* Wait for sOS ready for ring creation */121121+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64),122122+ 0x80000000, 0x80000000, false);123123+ if (ret) {124124+ DRM_ERROR("Failed to wait for trust OS ready for ring creation\n");125125+ return ret;126126+ }127127+128128+ /* Write low address of the ring to C2PMSG_69 */129129+ psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);130130+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_69, psp_ring_reg);131131+ /* Write high address of the ring to C2PMSG_70 */132132+ psp_ring_reg = upper_32_bits(ring->ring_mem_mc_addr);133133+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_70, psp_ring_reg);134134+ /* Write size of ring to C2PMSG_71 */135135+ psp_ring_reg = ring->ring_size;136136+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_71, psp_ring_reg);137137+ /* Write the ring initialization command to C2PMSG_64 */138138+ psp_ring_reg = ring_type;139139+ psp_ring_reg = psp_ring_reg << 16;140140+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_64, psp_ring_reg);141141+142142+ /* there might be handshake issue with hardware which needs delay */143143+ mdelay(20);144144+145145+ /* Wait for response flag (bit 31) in C2PMSG_64 */146146+ ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64),147147+ 0x80000000, 0x8000FFFF, false);148148+ }149149+150150+ return ret;151151+}152152+153153+static int psp_v11_0_8_ring_destroy(struct psp_context *psp,154154+ enum psp_ring_type ring_type)155155+{156156+ int ret = 0;157157+ struct psp_ring *ring = &psp->km_ring;158158+ struct amdgpu_device *adev = psp->adev;159159+160160+ ret = psp_v11_0_8_ring_stop(psp, ring_type);161161+ if (ret)162162+ DRM_ERROR("Fail to stop psp ring\n");163163+164164+ amdgpu_bo_free_kernel(&adev->firmware.rbuf,165165+ &ring->ring_mem_mc_addr,166166+ (void **)&ring->ring_mem);167167+168168+ return ret;169169+}170170+171171+static uint32_t psp_v11_0_8_ring_get_wptr(struct psp_context *psp)172172+{173173+ uint32_t data;174174+ struct amdgpu_device *adev = psp->adev;175175+176176+ if (amdgpu_sriov_vf(adev))177177+ data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);178178+ else179179+ data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);180180+181181+ return data;182182+}183183+184184+static void psp_v11_0_8_ring_set_wptr(struct psp_context *psp, uint32_t value)185185+{186186+ struct amdgpu_device *adev = psp->adev;187187+188188+ if (amdgpu_sriov_vf(adev)) {189189+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, value);190190+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101,191191+ GFX_CTRL_CMD_ID_CONSUME_CMD);192192+ } else193193+ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67, value);194194+}195195+196196+static const struct psp_funcs psp_v11_0_8_funcs = {197197+ .ring_init = psp_v11_0_8_ring_init,198198+ .ring_create = psp_v11_0_8_ring_create,199199+ .ring_stop = psp_v11_0_8_ring_stop,200200+ .ring_destroy = psp_v11_0_8_ring_destroy,201201+ .ring_get_wptr = psp_v11_0_8_ring_get_wptr,202202+ .ring_set_wptr = psp_v11_0_8_ring_set_wptr,203203+};204204+205205+void psp_v11_0_8_set_psp_funcs(struct psp_context *psp)206206+{207207+ psp->funcs = &psp_v11_0_8_funcs;208208+}
+30
drivers/gpu/drm/amd/amdgpu/psp_v11_0_8.h
···11+/*22+ * Copyright 2021 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_V11_0_8_H__2424+#define __PSP_V11_0_8_H__2525+2626+#include "amdgpu_psp.h"2727+2828+void psp_v11_0_8_set_psp_funcs(struct psp_context *psp);2929+3030+#endif