18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2017 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * Authors: Xiangliang.Yu@amd.com 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "amdgpu.h" 268c2ecf20Sopenharmony_ci#include "vi.h" 278c2ecf20Sopenharmony_ci#include "bif/bif_5_0_d.h" 288c2ecf20Sopenharmony_ci#include "bif/bif_5_0_sh_mask.h" 298c2ecf20Sopenharmony_ci#include "vid.h" 308c2ecf20Sopenharmony_ci#include "gca/gfx_8_0_d.h" 318c2ecf20Sopenharmony_ci#include "gca/gfx_8_0_sh_mask.h" 328c2ecf20Sopenharmony_ci#include "gmc_v8_0.h" 338c2ecf20Sopenharmony_ci#include "gfx_v8_0.h" 348c2ecf20Sopenharmony_ci#include "sdma_v3_0.h" 358c2ecf20Sopenharmony_ci#include "tonga_ih.h" 368c2ecf20Sopenharmony_ci#include "gmc/gmc_8_2_d.h" 378c2ecf20Sopenharmony_ci#include "gmc/gmc_8_2_sh_mask.h" 388c2ecf20Sopenharmony_ci#include "oss/oss_3_0_d.h" 398c2ecf20Sopenharmony_ci#include "oss/oss_3_0_sh_mask.h" 408c2ecf20Sopenharmony_ci#include "dce/dce_10_0_d.h" 418c2ecf20Sopenharmony_ci#include "dce/dce_10_0_sh_mask.h" 428c2ecf20Sopenharmony_ci#include "smu/smu_7_1_3_d.h" 438c2ecf20Sopenharmony_ci#include "mxgpu_vi.h" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* VI golden setting */ 468c2ecf20Sopenharmony_cistatic const u32 xgpu_fiji_mgcg_cgcg_init[] = { 478c2ecf20Sopenharmony_ci mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff, 488c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 498c2ecf20Sopenharmony_ci mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 508c2ecf20Sopenharmony_ci mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100, 518c2ecf20Sopenharmony_ci mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100, 528c2ecf20Sopenharmony_ci mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100, 538c2ecf20Sopenharmony_ci mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100, 548c2ecf20Sopenharmony_ci mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100, 558c2ecf20Sopenharmony_ci mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100, 568c2ecf20Sopenharmony_ci mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100, 578c2ecf20Sopenharmony_ci mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100, 588c2ecf20Sopenharmony_ci mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100, 598c2ecf20Sopenharmony_ci mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100, 608c2ecf20Sopenharmony_ci mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100, 618c2ecf20Sopenharmony_ci mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100, 628c2ecf20Sopenharmony_ci mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100, 638c2ecf20Sopenharmony_ci mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100, 648c2ecf20Sopenharmony_ci mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100, 658c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100, 668c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100, 678c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100, 688c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100, 698c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100, 708c2ecf20Sopenharmony_ci mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100, 718c2ecf20Sopenharmony_ci mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100, 728c2ecf20Sopenharmony_ci mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100, 738c2ecf20Sopenharmony_ci mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100, 748c2ecf20Sopenharmony_ci mmTA_CGTT_CTRL, 0xffffffff, 0x00000100, 758c2ecf20Sopenharmony_ci mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 768c2ecf20Sopenharmony_ci mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 778c2ecf20Sopenharmony_ci mmTD_CGTT_CTRL, 0xffffffff, 0x00000100, 788c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 798c2ecf20Sopenharmony_ci mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200, 808c2ecf20Sopenharmony_ci mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100, 818c2ecf20Sopenharmony_ci mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c, 828c2ecf20Sopenharmony_ci mmPCIE_INDEX, 0xffffffff, 0x0140001c, 838c2ecf20Sopenharmony_ci mmPCIE_DATA, 0x000f0000, 0x00000000, 848c2ecf20Sopenharmony_ci mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C, 858c2ecf20Sopenharmony_ci mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100, 868c2ecf20Sopenharmony_ci mmXDMA_CLOCK_GATING_CNTL, 0xffffffff, 0x00000100, 878c2ecf20Sopenharmony_ci mmXDMA_MEM_POWER_CNTL, 0x00000101, 0x00000000, 888c2ecf20Sopenharmony_ci mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104, 898c2ecf20Sopenharmony_ci mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100, 908c2ecf20Sopenharmony_ci mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, 918c2ecf20Sopenharmony_ci mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001, 928c2ecf20Sopenharmony_ci mmSDMA0_CLK_CTRL, 0xff000ff0, 0x00000100, 938c2ecf20Sopenharmony_ci mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100, 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic const u32 xgpu_fiji_golden_settings_a10[] = { 978c2ecf20Sopenharmony_ci mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040, 988c2ecf20Sopenharmony_ci mmDB_DEBUG2, 0xf00fffff, 0x00000400, 998c2ecf20Sopenharmony_ci mmDCI_CLK_CNTL, 0x00000080, 0x00000000, 1008c2ecf20Sopenharmony_ci mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070, 1018c2ecf20Sopenharmony_ci mmFBC_MISC, 0x1f311fff, 0x12300000, 1028c2ecf20Sopenharmony_ci mmHDMI_CONTROL, 0x31000111, 0x00000011, 1038c2ecf20Sopenharmony_ci mmPA_SC_ENHANCE, 0xffffffff, 0x20000001, 1048c2ecf20Sopenharmony_ci mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000, 1058c2ecf20Sopenharmony_ci mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007, 1068c2ecf20Sopenharmony_ci mmSDMA0_GFX_IB_CNTL, 0x800f0111, 0x00000100, 1078c2ecf20Sopenharmony_ci mmSDMA0_RLC0_IB_CNTL, 0x800f0111, 0x00000100, 1088c2ecf20Sopenharmony_ci mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100, 1098c2ecf20Sopenharmony_ci mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007, 1108c2ecf20Sopenharmony_ci mmSDMA1_GFX_IB_CNTL, 0x800f0111, 0x00000100, 1118c2ecf20Sopenharmony_ci mmSDMA1_RLC0_IB_CNTL, 0x800f0111, 0x00000100, 1128c2ecf20Sopenharmony_ci mmSDMA1_RLC1_IB_CNTL, 0x800f0111, 0x00000100, 1138c2ecf20Sopenharmony_ci mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd, 1148c2ecf20Sopenharmony_ci mmTA_CNTL_AUX, 0x000f000f, 0x000b0000, 1158c2ecf20Sopenharmony_ci mmTCC_EXE_DISABLE, 0x00000002, 0x00000002, 1168c2ecf20Sopenharmony_ci mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff, 1178c2ecf20Sopenharmony_ci mmVGT_RESET_DEBUG, 0x00000004, 0x00000004, 1188c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE0_LOW_ADDR, 0x0fffffff, 0x0fffffff, 1198c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE1_LOW_ADDR, 0x0fffffff, 0x0fffffff, 1208c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE2_LOW_ADDR, 0x0fffffff, 0x0fffffff, 1218c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE3_LOW_ADDR, 0x0fffffff, 0x0fffffff, 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic const u32 xgpu_fiji_golden_common_all[] = { 1258c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 1268c2ecf20Sopenharmony_ci mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a, 1278c2ecf20Sopenharmony_ci mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e, 1288c2ecf20Sopenharmony_ci mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003, 1298c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800, 1308c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800, 1318c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF, 1328c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00007FAF, 1338c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 1348c2ecf20Sopenharmony_ci mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009, 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistatic const u32 xgpu_tonga_mgcg_cgcg_init[] = { 1388c2ecf20Sopenharmony_ci mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff, 1398c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 1408c2ecf20Sopenharmony_ci mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 1418c2ecf20Sopenharmony_ci mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100, 1428c2ecf20Sopenharmony_ci mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100, 1438c2ecf20Sopenharmony_ci mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100, 1448c2ecf20Sopenharmony_ci mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100, 1458c2ecf20Sopenharmony_ci mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100, 1468c2ecf20Sopenharmony_ci mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100, 1478c2ecf20Sopenharmony_ci mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100, 1488c2ecf20Sopenharmony_ci mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100, 1498c2ecf20Sopenharmony_ci mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100, 1508c2ecf20Sopenharmony_ci mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100, 1518c2ecf20Sopenharmony_ci mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100, 1528c2ecf20Sopenharmony_ci mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100, 1538c2ecf20Sopenharmony_ci mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100, 1548c2ecf20Sopenharmony_ci mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100, 1558c2ecf20Sopenharmony_ci mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100, 1568c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100, 1578c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100, 1588c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100, 1598c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100, 1608c2ecf20Sopenharmony_ci mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100, 1618c2ecf20Sopenharmony_ci mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100, 1628c2ecf20Sopenharmony_ci mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100, 1638c2ecf20Sopenharmony_ci mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100, 1648c2ecf20Sopenharmony_ci mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100, 1658c2ecf20Sopenharmony_ci mmTA_CGTT_CTRL, 0xffffffff, 0x00000100, 1668c2ecf20Sopenharmony_ci mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 1678c2ecf20Sopenharmony_ci mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100, 1688c2ecf20Sopenharmony_ci mmTD_CGTT_CTRL, 0xffffffff, 0x00000100, 1698c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 1708c2ecf20Sopenharmony_ci mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1718c2ecf20Sopenharmony_ci mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1728c2ecf20Sopenharmony_ci mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007, 1738c2ecf20Sopenharmony_ci mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1748c2ecf20Sopenharmony_ci mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 1758c2ecf20Sopenharmony_ci mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1768c2ecf20Sopenharmony_ci mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1778c2ecf20Sopenharmony_ci mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007, 1788c2ecf20Sopenharmony_ci mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1798c2ecf20Sopenharmony_ci mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 1808c2ecf20Sopenharmony_ci mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1818c2ecf20Sopenharmony_ci mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1828c2ecf20Sopenharmony_ci mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007, 1838c2ecf20Sopenharmony_ci mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1848c2ecf20Sopenharmony_ci mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 1858c2ecf20Sopenharmony_ci mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1868c2ecf20Sopenharmony_ci mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1878c2ecf20Sopenharmony_ci mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007, 1888c2ecf20Sopenharmony_ci mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1898c2ecf20Sopenharmony_ci mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 1908c2ecf20Sopenharmony_ci mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1918c2ecf20Sopenharmony_ci mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1928c2ecf20Sopenharmony_ci mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007, 1938c2ecf20Sopenharmony_ci mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1948c2ecf20Sopenharmony_ci mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 1958c2ecf20Sopenharmony_ci mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000, 1968c2ecf20Sopenharmony_ci mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 1978c2ecf20Sopenharmony_ci mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007, 1988c2ecf20Sopenharmony_ci mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005, 1998c2ecf20Sopenharmony_ci mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 2008c2ecf20Sopenharmony_ci mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000, 2018c2ecf20Sopenharmony_ci mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 2028c2ecf20Sopenharmony_ci mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007, 2038c2ecf20Sopenharmony_ci mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005, 2048c2ecf20Sopenharmony_ci mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 2058c2ecf20Sopenharmony_ci mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000, 2068c2ecf20Sopenharmony_ci mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002, 2078c2ecf20Sopenharmony_ci mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007, 2088c2ecf20Sopenharmony_ci mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005, 2098c2ecf20Sopenharmony_ci mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008, 2108c2ecf20Sopenharmony_ci mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200, 2118c2ecf20Sopenharmony_ci mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100, 2128c2ecf20Sopenharmony_ci mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c, 2138c2ecf20Sopenharmony_ci mmPCIE_INDEX, 0xffffffff, 0x0140001c, 2148c2ecf20Sopenharmony_ci mmPCIE_DATA, 0x000f0000, 0x00000000, 2158c2ecf20Sopenharmony_ci mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C, 2168c2ecf20Sopenharmony_ci mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100, 2178c2ecf20Sopenharmony_ci mmXDMA_CLOCK_GATING_CNTL, 0xffffffff, 0x00000100, 2188c2ecf20Sopenharmony_ci mmXDMA_MEM_POWER_CNTL, 0x00000101, 0x00000000, 2198c2ecf20Sopenharmony_ci mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104, 2208c2ecf20Sopenharmony_ci mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100, 2218c2ecf20Sopenharmony_ci mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, 2228c2ecf20Sopenharmony_ci mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001, 2238c2ecf20Sopenharmony_ci mmSDMA0_CLK_CTRL, 0xff000ff0, 0x00000100, 2248c2ecf20Sopenharmony_ci mmSDMA1_CLK_CTRL, 0xff000ff0, 0x00000100, 2258c2ecf20Sopenharmony_ci}; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic const u32 xgpu_tonga_golden_settings_a11[] = { 2288c2ecf20Sopenharmony_ci mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208, 2298c2ecf20Sopenharmony_ci mmCB_HW_CONTROL_3, 0x00000040, 0x00000040, 2308c2ecf20Sopenharmony_ci mmDB_DEBUG2, 0xf00fffff, 0x00000400, 2318c2ecf20Sopenharmony_ci mmDCI_CLK_CNTL, 0x00000080, 0x00000000, 2328c2ecf20Sopenharmony_ci mmFBC_DEBUG_COMP, 0x000000f0, 0x00000070, 2338c2ecf20Sopenharmony_ci mmFBC_MISC, 0x1f311fff, 0x12300000, 2348c2ecf20Sopenharmony_ci mmGB_GPU_ID, 0x0000000f, 0x00000000, 2358c2ecf20Sopenharmony_ci mmHDMI_CONTROL, 0x31000111, 0x00000011, 2368c2ecf20Sopenharmony_ci mmMC_ARB_WTM_GRPWT_RD, 0x00000003, 0x00000000, 2378c2ecf20Sopenharmony_ci mmMC_HUB_RDREQ_DMIF_LIMIT, 0x0000007f, 0x00000028, 2388c2ecf20Sopenharmony_ci mmMC_HUB_WDP_UMC, 0x00007fb6, 0x00000991, 2398c2ecf20Sopenharmony_ci mmPA_SC_ENHANCE, 0xffffffff, 0x20000001, 2408c2ecf20Sopenharmony_ci mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x000000fc, 2418c2ecf20Sopenharmony_ci mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000, 2428c2ecf20Sopenharmony_ci mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c, 2438c2ecf20Sopenharmony_ci mmSDMA0_CHICKEN_BITS, 0xfc910007, 0x00810007, 2448c2ecf20Sopenharmony_ci mmSDMA0_CLK_CTRL, 0xff000fff, 0x00000000, 2458c2ecf20Sopenharmony_ci mmSDMA0_GFX_IB_CNTL, 0x800f0111, 0x00000100, 2468c2ecf20Sopenharmony_ci mmSDMA0_RLC0_IB_CNTL, 0x800f0111, 0x00000100, 2478c2ecf20Sopenharmony_ci mmSDMA0_RLC1_IB_CNTL, 0x800f0111, 0x00000100, 2488c2ecf20Sopenharmony_ci mmSDMA1_CHICKEN_BITS, 0xfc910007, 0x00810007, 2498c2ecf20Sopenharmony_ci mmSDMA1_CLK_CTRL, 0xff000fff, 0x00000000, 2508c2ecf20Sopenharmony_ci mmSDMA1_GFX_IB_CNTL, 0x800f0111, 0x00000100, 2518c2ecf20Sopenharmony_ci mmSDMA1_RLC0_IB_CNTL, 0x800f0111, 0x00000100, 2528c2ecf20Sopenharmony_ci mmSDMA1_RLC1_IB_CNTL, 0x800f0111, 0x00000100, 2538c2ecf20Sopenharmony_ci mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd, 2548c2ecf20Sopenharmony_ci mmTA_CNTL_AUX, 0x000f000f, 0x000b0000, 2558c2ecf20Sopenharmony_ci mmTCC_CTRL, 0x00100000, 0xf31fff7f, 2568c2ecf20Sopenharmony_ci mmTCC_EXE_DISABLE, 0x00000002, 0x00000002, 2578c2ecf20Sopenharmony_ci mmTCP_ADDR_CONFIG, 0x000003ff, 0x000002fb, 2588c2ecf20Sopenharmony_ci mmTCP_CHAN_STEER_HI, 0xffffffff, 0x0000543b, 2598c2ecf20Sopenharmony_ci mmTCP_CHAN_STEER_LO, 0xffffffff, 0xa9210876, 2608c2ecf20Sopenharmony_ci mmVGT_RESET_DEBUG, 0x00000004, 0x00000004, 2618c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE0_LOW_ADDR, 0x0fffffff, 0x0fffffff, 2628c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE1_LOW_ADDR, 0x0fffffff, 0x0fffffff, 2638c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE2_LOW_ADDR, 0x0fffffff, 0x0fffffff, 2648c2ecf20Sopenharmony_ci mmVM_PRT_APERTURE3_LOW_ADDR, 0x0fffffff, 0x0fffffff, 2658c2ecf20Sopenharmony_ci}; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_cistatic const u32 xgpu_tonga_golden_common_all[] = { 2688c2ecf20Sopenharmony_ci mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000, 2698c2ecf20Sopenharmony_ci mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012, 2708c2ecf20Sopenharmony_ci mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A, 2718c2ecf20Sopenharmony_ci mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002, 2728c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800, 2738c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800, 2748c2ecf20Sopenharmony_ci mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00007FBF, 2758c2ecf20Sopenharmony_ci}; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_civoid xgpu_vi_init_golden_registers(struct amdgpu_device *adev) 2788c2ecf20Sopenharmony_ci{ 2798c2ecf20Sopenharmony_ci switch (adev->asic_type) { 2808c2ecf20Sopenharmony_ci case CHIP_FIJI: 2818c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 2828c2ecf20Sopenharmony_ci xgpu_fiji_mgcg_cgcg_init, 2838c2ecf20Sopenharmony_ci ARRAY_SIZE( 2848c2ecf20Sopenharmony_ci xgpu_fiji_mgcg_cgcg_init)); 2858c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 2868c2ecf20Sopenharmony_ci xgpu_fiji_golden_settings_a10, 2878c2ecf20Sopenharmony_ci ARRAY_SIZE( 2888c2ecf20Sopenharmony_ci xgpu_fiji_golden_settings_a10)); 2898c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 2908c2ecf20Sopenharmony_ci xgpu_fiji_golden_common_all, 2918c2ecf20Sopenharmony_ci ARRAY_SIZE( 2928c2ecf20Sopenharmony_ci xgpu_fiji_golden_common_all)); 2938c2ecf20Sopenharmony_ci break; 2948c2ecf20Sopenharmony_ci case CHIP_TONGA: 2958c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 2968c2ecf20Sopenharmony_ci xgpu_tonga_mgcg_cgcg_init, 2978c2ecf20Sopenharmony_ci ARRAY_SIZE( 2988c2ecf20Sopenharmony_ci xgpu_tonga_mgcg_cgcg_init)); 2998c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 3008c2ecf20Sopenharmony_ci xgpu_tonga_golden_settings_a11, 3018c2ecf20Sopenharmony_ci ARRAY_SIZE( 3028c2ecf20Sopenharmony_ci xgpu_tonga_golden_settings_a11)); 3038c2ecf20Sopenharmony_ci amdgpu_device_program_register_sequence(adev, 3048c2ecf20Sopenharmony_ci xgpu_tonga_golden_common_all, 3058c2ecf20Sopenharmony_ci ARRAY_SIZE( 3068c2ecf20Sopenharmony_ci xgpu_tonga_golden_common_all)); 3078c2ecf20Sopenharmony_ci break; 3088c2ecf20Sopenharmony_ci default: 3098c2ecf20Sopenharmony_ci BUG_ON("Doesn't support chip type.\n"); 3108c2ecf20Sopenharmony_ci break; 3118c2ecf20Sopenharmony_ci } 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci/* 3158c2ecf20Sopenharmony_ci * Mailbox communication between GPU hypervisor and VFs 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_cistatic void xgpu_vi_mailbox_send_ack(struct amdgpu_device *adev) 3188c2ecf20Sopenharmony_ci{ 3198c2ecf20Sopenharmony_ci u32 reg; 3208c2ecf20Sopenharmony_ci int timeout = VI_MAILBOX_TIMEDOUT; 3218c2ecf20Sopenharmony_ci u32 mask = REG_FIELD_MASK(MAILBOX_CONTROL, RCV_MSG_VALID); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3248c2ecf20Sopenharmony_ci reg = REG_SET_FIELD(reg, MAILBOX_CONTROL, RCV_MSG_ACK, 1); 3258c2ecf20Sopenharmony_ci WREG32_NO_KIQ(mmMAILBOX_CONTROL, reg); 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci /*Wait for RCV_MSG_VALID to be 0*/ 3288c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3298c2ecf20Sopenharmony_ci while (reg & mask) { 3308c2ecf20Sopenharmony_ci if (timeout <= 0) { 3318c2ecf20Sopenharmony_ci pr_err("RCV_MSG_VALID is not cleared\n"); 3328c2ecf20Sopenharmony_ci break; 3338c2ecf20Sopenharmony_ci } 3348c2ecf20Sopenharmony_ci mdelay(1); 3358c2ecf20Sopenharmony_ci timeout -=1; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3388c2ecf20Sopenharmony_ci } 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cistatic void xgpu_vi_mailbox_set_valid(struct amdgpu_device *adev, bool val) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci u32 reg; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3468c2ecf20Sopenharmony_ci reg = REG_SET_FIELD(reg, MAILBOX_CONTROL, 3478c2ecf20Sopenharmony_ci TRN_MSG_VALID, val ? 1 : 0); 3488c2ecf20Sopenharmony_ci WREG32_NO_KIQ(mmMAILBOX_CONTROL, reg); 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic void xgpu_vi_mailbox_trans_msg(struct amdgpu_device *adev, 3528c2ecf20Sopenharmony_ci enum idh_request req) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci u32 reg; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_MSGBUF_TRN_DW0); 3578c2ecf20Sopenharmony_ci reg = REG_SET_FIELD(reg, MAILBOX_MSGBUF_TRN_DW0, 3588c2ecf20Sopenharmony_ci MSGBUF_DATA, req); 3598c2ecf20Sopenharmony_ci WREG32_NO_KIQ(mmMAILBOX_MSGBUF_TRN_DW0, reg); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci xgpu_vi_mailbox_set_valid(adev, true); 3628c2ecf20Sopenharmony_ci} 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cistatic int xgpu_vi_mailbox_rcv_msg(struct amdgpu_device *adev, 3658c2ecf20Sopenharmony_ci enum idh_event event) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci u32 reg; 3688c2ecf20Sopenharmony_ci u32 mask = REG_FIELD_MASK(MAILBOX_CONTROL, RCV_MSG_VALID); 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci /* workaround: host driver doesn't set VALID for CMPL now */ 3718c2ecf20Sopenharmony_ci if (event != IDH_FLR_NOTIFICATION_CMPL) { 3728c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3738c2ecf20Sopenharmony_ci if (!(reg & mask)) 3748c2ecf20Sopenharmony_ci return -ENOENT; 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_MSGBUF_RCV_DW0); 3788c2ecf20Sopenharmony_ci if (reg != event) 3798c2ecf20Sopenharmony_ci return -ENOENT; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci /* send ack to PF */ 3828c2ecf20Sopenharmony_ci xgpu_vi_mailbox_send_ack(adev); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci return 0; 3858c2ecf20Sopenharmony_ci} 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_cistatic int xgpu_vi_poll_ack(struct amdgpu_device *adev) 3888c2ecf20Sopenharmony_ci{ 3898c2ecf20Sopenharmony_ci int r = 0, timeout = VI_MAILBOX_TIMEDOUT; 3908c2ecf20Sopenharmony_ci u32 mask = REG_FIELD_MASK(MAILBOX_CONTROL, TRN_MSG_ACK); 3918c2ecf20Sopenharmony_ci u32 reg; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 3948c2ecf20Sopenharmony_ci while (!(reg & mask)) { 3958c2ecf20Sopenharmony_ci if (timeout <= 0) { 3968c2ecf20Sopenharmony_ci pr_err("Doesn't get ack from pf.\n"); 3978c2ecf20Sopenharmony_ci r = -ETIME; 3988c2ecf20Sopenharmony_ci break; 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci mdelay(5); 4018c2ecf20Sopenharmony_ci timeout -= 5; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci reg = RREG32_NO_KIQ(mmMAILBOX_CONTROL); 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci return r; 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic int xgpu_vi_poll_msg(struct amdgpu_device *adev, enum idh_event event) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci int r = 0, timeout = VI_MAILBOX_TIMEDOUT; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci r = xgpu_vi_mailbox_rcv_msg(adev, event); 4148c2ecf20Sopenharmony_ci while (r) { 4158c2ecf20Sopenharmony_ci if (timeout <= 0) { 4168c2ecf20Sopenharmony_ci pr_err("Doesn't get ack from pf.\n"); 4178c2ecf20Sopenharmony_ci r = -ETIME; 4188c2ecf20Sopenharmony_ci break; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci mdelay(5); 4218c2ecf20Sopenharmony_ci timeout -= 5; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci r = xgpu_vi_mailbox_rcv_msg(adev, event); 4248c2ecf20Sopenharmony_ci } 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci return r; 4278c2ecf20Sopenharmony_ci} 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic int xgpu_vi_send_access_requests(struct amdgpu_device *adev, 4308c2ecf20Sopenharmony_ci enum idh_request request) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci int r; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci xgpu_vi_mailbox_trans_msg(adev, request); 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci /* start to poll ack */ 4378c2ecf20Sopenharmony_ci r = xgpu_vi_poll_ack(adev); 4388c2ecf20Sopenharmony_ci if (r) 4398c2ecf20Sopenharmony_ci return r; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci xgpu_vi_mailbox_set_valid(adev, false); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci /* start to check msg if request is idh_req_gpu_init_access */ 4448c2ecf20Sopenharmony_ci if (request == IDH_REQ_GPU_INIT_ACCESS || 4458c2ecf20Sopenharmony_ci request == IDH_REQ_GPU_FINI_ACCESS || 4468c2ecf20Sopenharmony_ci request == IDH_REQ_GPU_RESET_ACCESS) { 4478c2ecf20Sopenharmony_ci r = xgpu_vi_poll_msg(adev, IDH_READY_TO_ACCESS_GPU); 4488c2ecf20Sopenharmony_ci if (r) { 4498c2ecf20Sopenharmony_ci pr_err("Doesn't get ack from pf, give up\n"); 4508c2ecf20Sopenharmony_ci return r; 4518c2ecf20Sopenharmony_ci } 4528c2ecf20Sopenharmony_ci } 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci return 0; 4558c2ecf20Sopenharmony_ci} 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_cistatic int xgpu_vi_request_reset(struct amdgpu_device *adev) 4588c2ecf20Sopenharmony_ci{ 4598c2ecf20Sopenharmony_ci return xgpu_vi_send_access_requests(adev, IDH_REQ_GPU_RESET_ACCESS); 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic int xgpu_vi_wait_reset_cmpl(struct amdgpu_device *adev) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci return xgpu_vi_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL); 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_cistatic int xgpu_vi_request_full_gpu_access(struct amdgpu_device *adev, 4688c2ecf20Sopenharmony_ci bool init) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci enum idh_request req; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci req = init ? IDH_REQ_GPU_INIT_ACCESS : IDH_REQ_GPU_FINI_ACCESS; 4738c2ecf20Sopenharmony_ci return xgpu_vi_send_access_requests(adev, req); 4748c2ecf20Sopenharmony_ci} 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_cistatic int xgpu_vi_release_full_gpu_access(struct amdgpu_device *adev, 4778c2ecf20Sopenharmony_ci bool init) 4788c2ecf20Sopenharmony_ci{ 4798c2ecf20Sopenharmony_ci enum idh_request req; 4808c2ecf20Sopenharmony_ci int r = 0; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci req = init ? IDH_REL_GPU_INIT_ACCESS : IDH_REL_GPU_FINI_ACCESS; 4838c2ecf20Sopenharmony_ci r = xgpu_vi_send_access_requests(adev, req); 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci return r; 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci/* add support mailbox interrupts */ 4898c2ecf20Sopenharmony_cistatic int xgpu_vi_mailbox_ack_irq(struct amdgpu_device *adev, 4908c2ecf20Sopenharmony_ci struct amdgpu_irq_src *source, 4918c2ecf20Sopenharmony_ci struct amdgpu_iv_entry *entry) 4928c2ecf20Sopenharmony_ci{ 4938c2ecf20Sopenharmony_ci DRM_DEBUG("get ack intr and do nothing.\n"); 4948c2ecf20Sopenharmony_ci return 0; 4958c2ecf20Sopenharmony_ci} 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_cistatic int xgpu_vi_set_mailbox_ack_irq(struct amdgpu_device *adev, 4988c2ecf20Sopenharmony_ci struct amdgpu_irq_src *src, 4998c2ecf20Sopenharmony_ci unsigned type, 5008c2ecf20Sopenharmony_ci enum amdgpu_interrupt_state state) 5018c2ecf20Sopenharmony_ci{ 5028c2ecf20Sopenharmony_ci u32 tmp = RREG32_NO_KIQ(mmMAILBOX_INT_CNTL); 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci tmp = REG_SET_FIELD(tmp, MAILBOX_INT_CNTL, ACK_INT_EN, 5058c2ecf20Sopenharmony_ci (state == AMDGPU_IRQ_STATE_ENABLE) ? 1 : 0); 5068c2ecf20Sopenharmony_ci WREG32_NO_KIQ(mmMAILBOX_INT_CNTL, tmp); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci return 0; 5098c2ecf20Sopenharmony_ci} 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_cistatic void xgpu_vi_mailbox_flr_work(struct work_struct *work) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work); 5148c2ecf20Sopenharmony_ci struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci /* wait until RCV_MSG become 3 */ 5178c2ecf20Sopenharmony_ci if (xgpu_vi_poll_msg(adev, IDH_FLR_NOTIFICATION_CMPL)) { 5188c2ecf20Sopenharmony_ci pr_err("failed to receive FLR_CMPL\n"); 5198c2ecf20Sopenharmony_ci return; 5208c2ecf20Sopenharmony_ci } 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci /* Trigger recovery due to world switch failure */ 5238c2ecf20Sopenharmony_ci if (amdgpu_device_should_recover_gpu(adev)) 5248c2ecf20Sopenharmony_ci amdgpu_device_gpu_recover(adev, NULL); 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic int xgpu_vi_set_mailbox_rcv_irq(struct amdgpu_device *adev, 5288c2ecf20Sopenharmony_ci struct amdgpu_irq_src *src, 5298c2ecf20Sopenharmony_ci unsigned type, 5308c2ecf20Sopenharmony_ci enum amdgpu_interrupt_state state) 5318c2ecf20Sopenharmony_ci{ 5328c2ecf20Sopenharmony_ci u32 tmp = RREG32_NO_KIQ(mmMAILBOX_INT_CNTL); 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci tmp = REG_SET_FIELD(tmp, MAILBOX_INT_CNTL, VALID_INT_EN, 5358c2ecf20Sopenharmony_ci (state == AMDGPU_IRQ_STATE_ENABLE) ? 1 : 0); 5368c2ecf20Sopenharmony_ci WREG32_NO_KIQ(mmMAILBOX_INT_CNTL, tmp); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci return 0; 5398c2ecf20Sopenharmony_ci} 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_cistatic int xgpu_vi_mailbox_rcv_irq(struct amdgpu_device *adev, 5428c2ecf20Sopenharmony_ci struct amdgpu_irq_src *source, 5438c2ecf20Sopenharmony_ci struct amdgpu_iv_entry *entry) 5448c2ecf20Sopenharmony_ci{ 5458c2ecf20Sopenharmony_ci int r; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci /* trigger gpu-reset by hypervisor only if TDR disbaled */ 5488c2ecf20Sopenharmony_ci if (!amdgpu_gpu_recovery) { 5498c2ecf20Sopenharmony_ci /* see what event we get */ 5508c2ecf20Sopenharmony_ci r = xgpu_vi_mailbox_rcv_msg(adev, IDH_FLR_NOTIFICATION); 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci /* only handle FLR_NOTIFY now */ 5538c2ecf20Sopenharmony_ci if (!r) 5548c2ecf20Sopenharmony_ci schedule_work(&adev->virt.flr_work); 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci return 0; 5588c2ecf20Sopenharmony_ci} 5598c2ecf20Sopenharmony_ci 5608c2ecf20Sopenharmony_cistatic const struct amdgpu_irq_src_funcs xgpu_vi_mailbox_ack_irq_funcs = { 5618c2ecf20Sopenharmony_ci .set = xgpu_vi_set_mailbox_ack_irq, 5628c2ecf20Sopenharmony_ci .process = xgpu_vi_mailbox_ack_irq, 5638c2ecf20Sopenharmony_ci}; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_cistatic const struct amdgpu_irq_src_funcs xgpu_vi_mailbox_rcv_irq_funcs = { 5668c2ecf20Sopenharmony_ci .set = xgpu_vi_set_mailbox_rcv_irq, 5678c2ecf20Sopenharmony_ci .process = xgpu_vi_mailbox_rcv_irq, 5688c2ecf20Sopenharmony_ci}; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_civoid xgpu_vi_mailbox_set_irq_funcs(struct amdgpu_device *adev) 5718c2ecf20Sopenharmony_ci{ 5728c2ecf20Sopenharmony_ci adev->virt.ack_irq.num_types = 1; 5738c2ecf20Sopenharmony_ci adev->virt.ack_irq.funcs = &xgpu_vi_mailbox_ack_irq_funcs; 5748c2ecf20Sopenharmony_ci adev->virt.rcv_irq.num_types = 1; 5758c2ecf20Sopenharmony_ci adev->virt.rcv_irq.funcs = &xgpu_vi_mailbox_rcv_irq_funcs; 5768c2ecf20Sopenharmony_ci} 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ciint xgpu_vi_mailbox_add_irq_id(struct amdgpu_device *adev) 5798c2ecf20Sopenharmony_ci{ 5808c2ecf20Sopenharmony_ci int r; 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 135, &adev->virt.rcv_irq); 5838c2ecf20Sopenharmony_ci if (r) 5848c2ecf20Sopenharmony_ci return r; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, 138, &adev->virt.ack_irq); 5878c2ecf20Sopenharmony_ci if (r) { 5888c2ecf20Sopenharmony_ci amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0); 5898c2ecf20Sopenharmony_ci return r; 5908c2ecf20Sopenharmony_ci } 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci return 0; 5938c2ecf20Sopenharmony_ci} 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ciint xgpu_vi_mailbox_get_irq(struct amdgpu_device *adev) 5968c2ecf20Sopenharmony_ci{ 5978c2ecf20Sopenharmony_ci int r; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci r = amdgpu_irq_get(adev, &adev->virt.rcv_irq, 0); 6008c2ecf20Sopenharmony_ci if (r) 6018c2ecf20Sopenharmony_ci return r; 6028c2ecf20Sopenharmony_ci r = amdgpu_irq_get(adev, &adev->virt.ack_irq, 0); 6038c2ecf20Sopenharmony_ci if (r) { 6048c2ecf20Sopenharmony_ci amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0); 6058c2ecf20Sopenharmony_ci return r; 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci INIT_WORK(&adev->virt.flr_work, xgpu_vi_mailbox_flr_work); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci return 0; 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_civoid xgpu_vi_mailbox_put_irq(struct amdgpu_device *adev) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci amdgpu_irq_put(adev, &adev->virt.ack_irq, 0); 6168c2ecf20Sopenharmony_ci amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0); 6178c2ecf20Sopenharmony_ci} 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ciconst struct amdgpu_virt_ops xgpu_vi_virt_ops = { 6208c2ecf20Sopenharmony_ci .req_full_gpu = xgpu_vi_request_full_gpu_access, 6218c2ecf20Sopenharmony_ci .rel_full_gpu = xgpu_vi_release_full_gpu_access, 6228c2ecf20Sopenharmony_ci .reset_gpu = xgpu_vi_request_reset, 6238c2ecf20Sopenharmony_ci .wait_reset = xgpu_vi_wait_reset_cmpl, 6248c2ecf20Sopenharmony_ci .trans_msg = NULL, /* Does not need to trans VF errors to host. */ 6258c2ecf20Sopenharmony_ci}; 626