xref: /linux/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1aaa36a97SAlex Deucher /*
2aaa36a97SAlex Deucher  * Copyright 2014 Advanced Micro Devices, Inc.
3aaa36a97SAlex Deucher  *
4aaa36a97SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
5aaa36a97SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
6aaa36a97SAlex Deucher  * to deal in the Software without restriction, including without limitation
7aaa36a97SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8aaa36a97SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
9aaa36a97SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
10aaa36a97SAlex Deucher  *
11aaa36a97SAlex Deucher  * The above copyright notice and this permission notice shall be included in
12aaa36a97SAlex Deucher  * all copies or substantial portions of the Software.
13aaa36a97SAlex Deucher  *
14aaa36a97SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15aaa36a97SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16aaa36a97SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17aaa36a97SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18aaa36a97SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19aaa36a97SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20aaa36a97SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
21aaa36a97SAlex Deucher  *
22aaa36a97SAlex Deucher  */
23c366be54SSam Ravnborg 
24c366be54SSam Ravnborg #include <linux/delay.h>
25c1b24a14SJérémy Lefaure #include <linux/kernel.h>
26aaa36a97SAlex Deucher #include <linux/firmware.h>
2747b757fbSSam Ravnborg #include <linux/module.h>
2847b757fbSSam Ravnborg #include <linux/pci.h>
29c366be54SSam Ravnborg 
30aaa36a97SAlex Deucher #include "amdgpu.h"
31aaa36a97SAlex Deucher #include "amdgpu_gfx.h"
320a52a6caSNirmoy Das #include "amdgpu_ring.h"
33aaa36a97SAlex Deucher #include "vi.h"
34aeab2032SXiangliang Yu #include "vi_structs.h"
35aaa36a97SAlex Deucher #include "vid.h"
36aaa36a97SAlex Deucher #include "amdgpu_ucode.h"
3768182d90SFlora Cui #include "amdgpu_atombios.h"
38eeade25aSKen Wang #include "atombios_i2c.h"
39aaa36a97SAlex Deucher #include "clearstate_vi.h"
40aaa36a97SAlex Deucher 
41aaa36a97SAlex Deucher #include "gmc/gmc_8_2_d.h"
42aaa36a97SAlex Deucher #include "gmc/gmc_8_2_sh_mask.h"
43aaa36a97SAlex Deucher 
44aaa36a97SAlex Deucher #include "oss/oss_3_0_d.h"
45aaa36a97SAlex Deucher #include "oss/oss_3_0_sh_mask.h"
46aaa36a97SAlex Deucher 
47aaa36a97SAlex Deucher #include "bif/bif_5_0_d.h"
48aaa36a97SAlex Deucher #include "bif/bif_5_0_sh_mask.h"
49aaa36a97SAlex Deucher #include "gca/gfx_8_0_d.h"
50aaa36a97SAlex Deucher #include "gca/gfx_8_0_enum.h"
51aaa36a97SAlex Deucher #include "gca/gfx_8_0_sh_mask.h"
52aaa36a97SAlex Deucher 
53aaa36a97SAlex Deucher #include "dce/dce_10_0_d.h"
54aaa36a97SAlex Deucher #include "dce/dce_10_0_sh_mask.h"
55aaa36a97SAlex Deucher 
56d9d533c1SKen Wang #include "smu/smu_7_1_3_d.h"
57d9d533c1SKen Wang 
58091aec0bSAndrey Grodzovsky #include "ivsrcid/ivsrcid_vislands30.h"
59091aec0bSAndrey Grodzovsky 
60aaa36a97SAlex Deucher #define GFX8_NUM_GFX_RINGS     1
6117e4bd6cSMarek Olšák #define GFX8_MEC_HPD_SIZE 4096
62aaa36a97SAlex Deucher 
63aaa36a97SAlex Deucher #define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001
64aaa36a97SAlex Deucher #define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001
652cc0c0b5SFlora Cui #define POLARIS11_GB_ADDR_CONFIG_GOLDEN 0x22011002
66aaa36a97SAlex Deucher #define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003
67aaa36a97SAlex Deucher 
68aaa36a97SAlex Deucher #define ARRAY_MODE(x)					((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT)
69aaa36a97SAlex Deucher #define PIPE_CONFIG(x)					((x) << GB_TILE_MODE0__PIPE_CONFIG__SHIFT)
70aaa36a97SAlex Deucher #define TILE_SPLIT(x)					((x) << GB_TILE_MODE0__TILE_SPLIT__SHIFT)
71aaa36a97SAlex Deucher #define MICRO_TILE_MODE_NEW(x)				((x) << GB_TILE_MODE0__MICRO_TILE_MODE_NEW__SHIFT)
72aaa36a97SAlex Deucher #define SAMPLE_SPLIT(x)					((x) << GB_TILE_MODE0__SAMPLE_SPLIT__SHIFT)
73aaa36a97SAlex Deucher #define BANK_WIDTH(x)					((x) << GB_MACROTILE_MODE0__BANK_WIDTH__SHIFT)
74aaa36a97SAlex Deucher #define BANK_HEIGHT(x)					((x) << GB_MACROTILE_MODE0__BANK_HEIGHT__SHIFT)
75aaa36a97SAlex Deucher #define MACRO_TILE_ASPECT(x)				((x) << GB_MACROTILE_MODE0__MACRO_TILE_ASPECT__SHIFT)
76aaa36a97SAlex Deucher #define NUM_BANKS(x)					((x) << GB_MACROTILE_MODE0__NUM_BANKS__SHIFT)
77aaa36a97SAlex Deucher 
786e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__CPF_MASK            0x00000001L
796e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__RLC_MASK            0x00000002L
806e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK           0x00000004L
816e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK           0x00000008L
826e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK           0x00000010L
836e378858SEric Huang #define RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK           0x00000020L
846e378858SEric Huang 
856e378858SEric Huang /* BPM SERDES CMD */
866e378858SEric Huang #define SET_BPM_SERDES_CMD    1
876e378858SEric Huang #define CLE_BPM_SERDES_CMD    0
886e378858SEric Huang 
896e378858SEric Huang /* BPM Register Address*/
906e378858SEric Huang enum {
916e378858SEric Huang 	BPM_REG_CGLS_EN = 0,        /* Enable/Disable CGLS */
926e378858SEric Huang 	BPM_REG_CGLS_ON,            /* ON/OFF CGLS: shall be controlled by RLC FW */
936e378858SEric Huang 	BPM_REG_CGCG_OVERRIDE,      /* Set/Clear CGCG Override */
946e378858SEric Huang 	BPM_REG_MGCG_OVERRIDE,      /* Set/Clear MGCG Override */
956e378858SEric Huang 	BPM_REG_FGCG_OVERRIDE,      /* Set/Clear FGCG Override */
966e378858SEric Huang 	BPM_REG_FGCG_MAX
976e378858SEric Huang };
986e378858SEric Huang 
992b6cd977SEric Huang #define RLC_FormatDirectRegListLength        14
1002b6cd977SEric Huang 
101c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_ce.bin");
102c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin");
103c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_me.bin");
104c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_mec.bin");
105c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_mec2.bin");
106c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/carrizo_rlc.bin");
107aaa36a97SAlex Deucher 
108e3c7656cSSamuel Li MODULE_FIRMWARE("amdgpu/stoney_ce.bin");
109e3c7656cSSamuel Li MODULE_FIRMWARE("amdgpu/stoney_pfp.bin");
110e3c7656cSSamuel Li MODULE_FIRMWARE("amdgpu/stoney_me.bin");
111e3c7656cSSamuel Li MODULE_FIRMWARE("amdgpu/stoney_mec.bin");
112e3c7656cSSamuel Li MODULE_FIRMWARE("amdgpu/stoney_rlc.bin");
113e3c7656cSSamuel Li 
114c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_ce.bin");
115c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_pfp.bin");
116c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_me.bin");
117c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_mec.bin");
118c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_mec2.bin");
119c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/tonga_rlc.bin");
120aaa36a97SAlex Deucher 
121c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/topaz_ce.bin");
122c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/topaz_pfp.bin");
123c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/topaz_me.bin");
124c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/topaz_mec.bin");
125c65444feSJammy Zhou MODULE_FIRMWARE("amdgpu/topaz_rlc.bin");
126aaa36a97SAlex Deucher 
127af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_ce.bin");
128af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_pfp.bin");
129af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_me.bin");
130af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_mec.bin");
131af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_mec2.bin");
132af15a2d5SDavid Zhang MODULE_FIRMWARE("amdgpu/fiji_rlc.bin");
133af15a2d5SDavid Zhang 
1342cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_ce.bin");
135f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris10_ce_2.bin");
1362cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_pfp.bin");
137f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris10_pfp_2.bin");
1382cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_me.bin");
139f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris10_me_2.bin");
1402cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_mec.bin");
141f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris10_mec_2.bin");
1422cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
143f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris10_mec2_2.bin");
1442cc0c0b5SFlora Cui MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");
14568182d90SFlora Cui 
14662aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_ce.bin");
14762aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_ce_2.bin");
14862aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_pfp.bin");
14962aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_pfp_2.bin");
15062aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_me.bin");
15162aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_me_2.bin");
15262aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_mec.bin");
15362aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_mec_2.bin");
15462aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_mec2.bin");
15562aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_mec2_2.bin");
15662aac201SLeo Liu MODULE_FIRMWARE("amdgpu/polaris11_rlc.bin");
15762aac201SLeo Liu 
158c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_ce.bin");
159f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris12_ce_2.bin");
160c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_pfp.bin");
161f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris12_pfp_2.bin");
162c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_me.bin");
163f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris12_me_2.bin");
164c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_mec.bin");
165f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris12_mec_2.bin");
166c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_mec2.bin");
167f5830465SEvan Quan MODULE_FIRMWARE("amdgpu/polaris12_mec2_2.bin");
168c4642a47SJunwei Zhang MODULE_FIRMWARE("amdgpu/polaris12_rlc.bin");
169c4642a47SJunwei Zhang 
17062aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_ce.bin");
17162aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_pfp.bin");
17262aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_me.bin");
17362aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_mec.bin");
17462aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_mec2.bin");
17562aac201SLeo Liu MODULE_FIRMWARE("amdgpu/vegam_rlc.bin");
17662aac201SLeo Liu 
177aaa36a97SAlex Deucher static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
178aaa36a97SAlex Deucher {
179aaa36a97SAlex Deucher 	{mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
180aaa36a97SAlex Deucher 	{mmGDS_VMID1_BASE, mmGDS_VMID1_SIZE, mmGDS_GWS_VMID1, mmGDS_OA_VMID1},
181aaa36a97SAlex Deucher 	{mmGDS_VMID2_BASE, mmGDS_VMID2_SIZE, mmGDS_GWS_VMID2, mmGDS_OA_VMID2},
182aaa36a97SAlex Deucher 	{mmGDS_VMID3_BASE, mmGDS_VMID3_SIZE, mmGDS_GWS_VMID3, mmGDS_OA_VMID3},
183aaa36a97SAlex Deucher 	{mmGDS_VMID4_BASE, mmGDS_VMID4_SIZE, mmGDS_GWS_VMID4, mmGDS_OA_VMID4},
184aaa36a97SAlex Deucher 	{mmGDS_VMID5_BASE, mmGDS_VMID5_SIZE, mmGDS_GWS_VMID5, mmGDS_OA_VMID5},
185aaa36a97SAlex Deucher 	{mmGDS_VMID6_BASE, mmGDS_VMID6_SIZE, mmGDS_GWS_VMID6, mmGDS_OA_VMID6},
186aaa36a97SAlex Deucher 	{mmGDS_VMID7_BASE, mmGDS_VMID7_SIZE, mmGDS_GWS_VMID7, mmGDS_OA_VMID7},
187aaa36a97SAlex Deucher 	{mmGDS_VMID8_BASE, mmGDS_VMID8_SIZE, mmGDS_GWS_VMID8, mmGDS_OA_VMID8},
188aaa36a97SAlex Deucher 	{mmGDS_VMID9_BASE, mmGDS_VMID9_SIZE, mmGDS_GWS_VMID9, mmGDS_OA_VMID9},
189aaa36a97SAlex Deucher 	{mmGDS_VMID10_BASE, mmGDS_VMID10_SIZE, mmGDS_GWS_VMID10, mmGDS_OA_VMID10},
190aaa36a97SAlex Deucher 	{mmGDS_VMID11_BASE, mmGDS_VMID11_SIZE, mmGDS_GWS_VMID11, mmGDS_OA_VMID11},
191aaa36a97SAlex Deucher 	{mmGDS_VMID12_BASE, mmGDS_VMID12_SIZE, mmGDS_GWS_VMID12, mmGDS_OA_VMID12},
192aaa36a97SAlex Deucher 	{mmGDS_VMID13_BASE, mmGDS_VMID13_SIZE, mmGDS_GWS_VMID13, mmGDS_OA_VMID13},
193aaa36a97SAlex Deucher 	{mmGDS_VMID14_BASE, mmGDS_VMID14_SIZE, mmGDS_GWS_VMID14, mmGDS_OA_VMID14},
194aaa36a97SAlex Deucher 	{mmGDS_VMID15_BASE, mmGDS_VMID15_SIZE, mmGDS_GWS_VMID15, mmGDS_OA_VMID15}
195aaa36a97SAlex Deucher };
196aaa36a97SAlex Deucher 
197aaa36a97SAlex Deucher static const u32 golden_settings_tonga_a11[] =
198aaa36a97SAlex Deucher {
199aaa36a97SAlex Deucher 	mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208,
200aaa36a97SAlex Deucher 	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
201aaa36a97SAlex Deucher 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
202aaa36a97SAlex Deucher 	mmGB_GPU_ID, 0x0000000f, 0x00000000,
203aaa36a97SAlex Deucher 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
204aaa36a97SAlex Deucher 	mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x000000fc,
205aaa36a97SAlex Deucher 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
206ff9d6460SHuang Rui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
2076a00a09eSAlex Deucher 	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
208aaa36a97SAlex Deucher 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
209aaa36a97SAlex Deucher 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
2106a00a09eSAlex Deucher 	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
211aaa36a97SAlex Deucher 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000002fb,
212aaa36a97SAlex Deucher 	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x0000543b,
213aaa36a97SAlex Deucher 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0xa9210876,
2146a00a09eSAlex Deucher 	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
215aaa36a97SAlex Deucher };
216aaa36a97SAlex Deucher 
217aaa36a97SAlex Deucher static const u32 tonga_golden_common_all[] =
218aaa36a97SAlex Deucher {
219aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
220aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
221aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
222aaa36a97SAlex Deucher 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
223aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
224aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
22598b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
22698b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
227aaa36a97SAlex Deucher };
228aaa36a97SAlex Deucher 
229aaa36a97SAlex Deucher static const u32 tonga_mgcg_cgcg_init[] =
230aaa36a97SAlex Deucher {
231aaa36a97SAlex Deucher 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
232aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
233aaa36a97SAlex Deucher 	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
234aaa36a97SAlex Deucher 	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
235aaa36a97SAlex Deucher 	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
236aaa36a97SAlex Deucher 	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
237aaa36a97SAlex Deucher 	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
238aaa36a97SAlex Deucher 	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
239aaa36a97SAlex Deucher 	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
240aaa36a97SAlex Deucher 	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
241aaa36a97SAlex Deucher 	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
242aaa36a97SAlex Deucher 	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
243aaa36a97SAlex Deucher 	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
244aaa36a97SAlex Deucher 	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
245aaa36a97SAlex Deucher 	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
246aaa36a97SAlex Deucher 	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
247aaa36a97SAlex Deucher 	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
248aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
249aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
250aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
251aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
252aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
253aaa36a97SAlex Deucher 	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
254aaa36a97SAlex Deucher 	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
255aaa36a97SAlex Deucher 	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
256aaa36a97SAlex Deucher 	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
257aaa36a97SAlex Deucher 	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
258aaa36a97SAlex Deucher 	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
259aaa36a97SAlex Deucher 	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
260aaa36a97SAlex Deucher 	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
261aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
262aaa36a97SAlex Deucher 	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
263aaa36a97SAlex Deucher 	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
264aaa36a97SAlex Deucher 	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
265aaa36a97SAlex Deucher 	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
266aaa36a97SAlex Deucher 	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
267aaa36a97SAlex Deucher 	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
268aaa36a97SAlex Deucher 	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
269aaa36a97SAlex Deucher 	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
270aaa36a97SAlex Deucher 	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
271aaa36a97SAlex Deucher 	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
272aaa36a97SAlex Deucher 	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
273aaa36a97SAlex Deucher 	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
274aaa36a97SAlex Deucher 	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
275aaa36a97SAlex Deucher 	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
276aaa36a97SAlex Deucher 	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
277aaa36a97SAlex Deucher 	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
278aaa36a97SAlex Deucher 	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
279aaa36a97SAlex Deucher 	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
280aaa36a97SAlex Deucher 	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
281aaa36a97SAlex Deucher 	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
282aaa36a97SAlex Deucher 	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
283aaa36a97SAlex Deucher 	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
284aaa36a97SAlex Deucher 	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
285aaa36a97SAlex Deucher 	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
286aaa36a97SAlex Deucher 	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
287aaa36a97SAlex Deucher 	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
288aaa36a97SAlex Deucher 	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
289aaa36a97SAlex Deucher 	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
290aaa36a97SAlex Deucher 	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
291aaa36a97SAlex Deucher 	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
292aaa36a97SAlex Deucher 	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
293aaa36a97SAlex Deucher 	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
294aaa36a97SAlex Deucher 	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
295aaa36a97SAlex Deucher 	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
296aaa36a97SAlex Deucher 	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
297aaa36a97SAlex Deucher 	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
298aaa36a97SAlex Deucher 	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
299aaa36a97SAlex Deucher 	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
300aaa36a97SAlex Deucher 	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
301aaa36a97SAlex Deucher 	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
302aaa36a97SAlex Deucher 	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
303aaa36a97SAlex Deucher 	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
304aaa36a97SAlex Deucher 	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
305aaa36a97SAlex Deucher 	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
306aaa36a97SAlex Deucher };
307aaa36a97SAlex Deucher 
308aefbbd6cSLeo Liu static const u32 golden_settings_vegam_a11[] =
309aefbbd6cSLeo Liu {
310aefbbd6cSLeo Liu 	mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
311aefbbd6cSLeo Liu 	mmCB_HW_CONTROL_2, 0x0f000000, 0x0d000000,
312aefbbd6cSLeo Liu 	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
313aefbbd6cSLeo Liu 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
314aefbbd6cSLeo Liu 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
315aefbbd6cSLeo Liu 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
316aefbbd6cSLeo Liu 	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x3a00161a,
317aefbbd6cSLeo Liu 	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002e,
318aefbbd6cSLeo Liu 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
319aefbbd6cSLeo Liu 	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
320aefbbd6cSLeo Liu 	mmSQ_CONFIG, 0x07f80000, 0x01180000,
321aefbbd6cSLeo Liu 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
322aefbbd6cSLeo Liu 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
323aefbbd6cSLeo Liu 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
324aefbbd6cSLeo Liu 	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
325aefbbd6cSLeo Liu 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x32761054,
326aefbbd6cSLeo Liu 	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
327aefbbd6cSLeo Liu };
328aefbbd6cSLeo Liu 
329aefbbd6cSLeo Liu static const u32 vegam_golden_common_all[] =
330aefbbd6cSLeo Liu {
331aefbbd6cSLeo Liu 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
332aefbbd6cSLeo Liu 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
333aefbbd6cSLeo Liu 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
334aefbbd6cSLeo Liu 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
335aefbbd6cSLeo Liu 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
336aefbbd6cSLeo Liu 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
337aefbbd6cSLeo Liu };
338aefbbd6cSLeo Liu 
3392cc0c0b5SFlora Cui static const u32 golden_settings_polaris11_a11[] =
34068182d90SFlora Cui {
3419761bc53SHuang Rui 	mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
3429761bc53SHuang Rui 	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
34368182d90SFlora Cui 	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
34468182d90SFlora Cui 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
34568182d90SFlora Cui 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
34668182d90SFlora Cui 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
347b9934878SFlora Cui 	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
348b9934878SFlora Cui 	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
34968182d90SFlora Cui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
35068182d90SFlora Cui 	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
3519761bc53SHuang Rui 	mmSQ_CONFIG, 0x07f80000, 0x01180000,
35268182d90SFlora Cui 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
35368182d90SFlora Cui 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
35468182d90SFlora Cui 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
35568182d90SFlora Cui 	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
35668182d90SFlora Cui 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00003210,
357795c2109SKen Wang 	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
35868182d90SFlora Cui };
35968182d90SFlora Cui 
3602cc0c0b5SFlora Cui static const u32 polaris11_golden_common_all[] =
36168182d90SFlora Cui {
36268182d90SFlora Cui 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
36368182d90SFlora Cui 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002,
36468182d90SFlora Cui 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
36568182d90SFlora Cui 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
36698b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
36798b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
36868182d90SFlora Cui };
36968182d90SFlora Cui 
3702cc0c0b5SFlora Cui static const u32 golden_settings_polaris10_a11[] =
37168182d90SFlora Cui {
37268182d90SFlora Cui 	mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
373a5a5e308SHuang Rui 	mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
374a5a5e308SHuang Rui 	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
37568182d90SFlora Cui 	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
37668182d90SFlora Cui 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
37768182d90SFlora Cui 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
37868182d90SFlora Cui 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
37968182d90SFlora Cui 	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
38068182d90SFlora Cui 	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002a,
38168182d90SFlora Cui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
38268182d90SFlora Cui 	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
38368182d90SFlora Cui 	mmSQ_CONFIG, 0x07f80000, 0x07180000,
38468182d90SFlora Cui 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
38568182d90SFlora Cui 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
38668182d90SFlora Cui 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
38768182d90SFlora Cui 	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
388795c2109SKen Wang 	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
38968182d90SFlora Cui };
39068182d90SFlora Cui 
3912cc0c0b5SFlora Cui static const u32 polaris10_golden_common_all[] =
39268182d90SFlora Cui {
39368182d90SFlora Cui 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
39468182d90SFlora Cui 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
39568182d90SFlora Cui 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
39668182d90SFlora Cui 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
39768182d90SFlora Cui 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
39868182d90SFlora Cui 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
39998b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
40098b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
40168182d90SFlora Cui };
40268182d90SFlora Cui 
403af15a2d5SDavid Zhang static const u32 fiji_golden_common_all[] =
404af15a2d5SDavid Zhang {
405af15a2d5SDavid Zhang 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
406af15a2d5SDavid Zhang 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a,
407af15a2d5SDavid Zhang 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e,
408a7ca8ef9SFlora Cui 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
409af15a2d5SDavid Zhang 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
410af15a2d5SDavid Zhang 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
41198b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
41298b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
413a7ca8ef9SFlora Cui 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
414a7ca8ef9SFlora Cui 	mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009,
415af15a2d5SDavid Zhang };
416af15a2d5SDavid Zhang 
417af15a2d5SDavid Zhang static const u32 golden_settings_fiji_a10[] =
418af15a2d5SDavid Zhang {
419af15a2d5SDavid Zhang 	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
420af15a2d5SDavid Zhang 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
421af15a2d5SDavid Zhang 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
422af15a2d5SDavid Zhang 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
423a7ca8ef9SFlora Cui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
424a7ca8ef9SFlora Cui 	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
425af15a2d5SDavid Zhang 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
426a7ca8ef9SFlora Cui 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
427a7ca8ef9SFlora Cui 	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
428af15a2d5SDavid Zhang 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff,
429a7ca8ef9SFlora Cui 	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
430af15a2d5SDavid Zhang };
431af15a2d5SDavid Zhang 
432af15a2d5SDavid Zhang static const u32 fiji_mgcg_cgcg_init[] =
433af15a2d5SDavid Zhang {
434a7ca8ef9SFlora Cui 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
435af15a2d5SDavid Zhang 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
436af15a2d5SDavid Zhang 	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
437af15a2d5SDavid Zhang 	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
438af15a2d5SDavid Zhang 	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
439af15a2d5SDavid Zhang 	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
440af15a2d5SDavid Zhang 	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
441af15a2d5SDavid Zhang 	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
442af15a2d5SDavid Zhang 	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
443af15a2d5SDavid Zhang 	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
444af15a2d5SDavid Zhang 	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
445af15a2d5SDavid Zhang 	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
446af15a2d5SDavid Zhang 	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
447af15a2d5SDavid Zhang 	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
448af15a2d5SDavid Zhang 	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
449af15a2d5SDavid Zhang 	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
450af15a2d5SDavid Zhang 	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
451af15a2d5SDavid Zhang 	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
452af15a2d5SDavid Zhang 	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
453af15a2d5SDavid Zhang 	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
454af15a2d5SDavid Zhang 	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
455af15a2d5SDavid Zhang 	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
456af15a2d5SDavid Zhang 	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
457af15a2d5SDavid Zhang 	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
458af15a2d5SDavid Zhang 	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
459af15a2d5SDavid Zhang 	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
460af15a2d5SDavid Zhang 	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
461af15a2d5SDavid Zhang 	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
462af15a2d5SDavid Zhang 	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
463af15a2d5SDavid Zhang 	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
464af15a2d5SDavid Zhang 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
465af15a2d5SDavid Zhang 	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
466af15a2d5SDavid Zhang 	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
467af15a2d5SDavid Zhang 	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
468af15a2d5SDavid Zhang 	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
469af15a2d5SDavid Zhang };
470af15a2d5SDavid Zhang 
471aaa36a97SAlex Deucher static const u32 golden_settings_iceland_a11[] =
472aaa36a97SAlex Deucher {
473aaa36a97SAlex Deucher 	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
474aaa36a97SAlex Deucher 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
475aaa36a97SAlex Deucher 	mmDB_DEBUG3, 0xc0000000, 0xc0000000,
476aaa36a97SAlex Deucher 	mmGB_GPU_ID, 0x0000000f, 0x00000000,
477aaa36a97SAlex Deucher 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
478aaa36a97SAlex Deucher 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
479aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
480aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
481fe85f07fSHuang Rui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
4826a00a09eSAlex Deucher 	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
483aaa36a97SAlex Deucher 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
484aaa36a97SAlex Deucher 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
4856a00a09eSAlex Deucher 	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
486aaa36a97SAlex Deucher 	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f1,
487aaa36a97SAlex Deucher 	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
488aaa36a97SAlex Deucher 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00000010,
489aaa36a97SAlex Deucher };
490aaa36a97SAlex Deucher 
491aaa36a97SAlex Deucher static const u32 iceland_golden_common_all[] =
492aaa36a97SAlex Deucher {
493aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
494aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
495aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
496aaa36a97SAlex Deucher 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
497aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
498aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
49998b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
50098b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
501aaa36a97SAlex Deucher };
502aaa36a97SAlex Deucher 
503aaa36a97SAlex Deucher static const u32 iceland_mgcg_cgcg_init[] =
504aaa36a97SAlex Deucher {
505aaa36a97SAlex Deucher 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
506aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
507aaa36a97SAlex Deucher 	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
508aaa36a97SAlex Deucher 	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
509aaa36a97SAlex Deucher 	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0xc0000100,
510aaa36a97SAlex Deucher 	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0xc0000100,
511aaa36a97SAlex Deucher 	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0xc0000100,
512aaa36a97SAlex Deucher 	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
513aaa36a97SAlex Deucher 	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
514aaa36a97SAlex Deucher 	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
515aaa36a97SAlex Deucher 	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
516aaa36a97SAlex Deucher 	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
517aaa36a97SAlex Deucher 	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
518aaa36a97SAlex Deucher 	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
519aaa36a97SAlex Deucher 	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
520aaa36a97SAlex Deucher 	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
521aaa36a97SAlex Deucher 	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
522aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
523aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
524aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
525aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
526aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
527aaa36a97SAlex Deucher 	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0xff000100,
528aaa36a97SAlex Deucher 	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
529aaa36a97SAlex Deucher 	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
530aaa36a97SAlex Deucher 	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
531aaa36a97SAlex Deucher 	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
532aaa36a97SAlex Deucher 	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
533aaa36a97SAlex Deucher 	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
534aaa36a97SAlex Deucher 	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
535aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
536aaa36a97SAlex Deucher 	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
537aaa36a97SAlex Deucher 	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
538aaa36a97SAlex Deucher 	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
539aaa36a97SAlex Deucher 	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
540aaa36a97SAlex Deucher 	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
541aaa36a97SAlex Deucher 	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
542aaa36a97SAlex Deucher 	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
543aaa36a97SAlex Deucher 	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
544aaa36a97SAlex Deucher 	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
545aaa36a97SAlex Deucher 	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
546aaa36a97SAlex Deucher 	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
547aaa36a97SAlex Deucher 	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
548aaa36a97SAlex Deucher 	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
549aaa36a97SAlex Deucher 	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
550aaa36a97SAlex Deucher 	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
551aaa36a97SAlex Deucher 	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
552aaa36a97SAlex Deucher 	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
553aaa36a97SAlex Deucher 	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
554aaa36a97SAlex Deucher 	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
555aaa36a97SAlex Deucher 	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
556aaa36a97SAlex Deucher 	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
557aaa36a97SAlex Deucher 	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
558aaa36a97SAlex Deucher 	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
559aaa36a97SAlex Deucher 	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
560aaa36a97SAlex Deucher 	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
561aaa36a97SAlex Deucher 	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
562aaa36a97SAlex Deucher 	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
563aaa36a97SAlex Deucher 	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
564aaa36a97SAlex Deucher 	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
565aaa36a97SAlex Deucher 	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
566aaa36a97SAlex Deucher 	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
567aaa36a97SAlex Deucher 	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
568aaa36a97SAlex Deucher 	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
569aaa36a97SAlex Deucher };
570aaa36a97SAlex Deucher 
571aaa36a97SAlex Deucher static const u32 cz_golden_settings_a11[] =
572aaa36a97SAlex Deucher {
573aaa36a97SAlex Deucher 	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
574aaa36a97SAlex Deucher 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
575aaa36a97SAlex Deucher 	mmGB_GPU_ID, 0x0000000f, 0x00000000,
576aaa36a97SAlex Deucher 	mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
577aaa36a97SAlex Deucher 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
5783a494b58SHuang Rui 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
5796a00a09eSAlex Deucher 	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
580aaa36a97SAlex Deucher 	mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
5813a494b58SHuang Rui 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
5826a00a09eSAlex Deucher 	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
583aaa36a97SAlex Deucher 	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
584aaa36a97SAlex Deucher 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
585aaa36a97SAlex Deucher };
586aaa36a97SAlex Deucher 
587aaa36a97SAlex Deucher static const u32 cz_golden_common_all[] =
588aaa36a97SAlex Deucher {
589aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
590aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
591aaa36a97SAlex Deucher 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
592aaa36a97SAlex Deucher 	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
593aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
594aaa36a97SAlex Deucher 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
59598b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
59698b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
597aaa36a97SAlex Deucher };
598aaa36a97SAlex Deucher 
599aaa36a97SAlex Deucher static const u32 cz_mgcg_cgcg_init[] =
600aaa36a97SAlex Deucher {
601aaa36a97SAlex Deucher 	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
602aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
603aaa36a97SAlex Deucher 	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
604aaa36a97SAlex Deucher 	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
605aaa36a97SAlex Deucher 	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
606aaa36a97SAlex Deucher 	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
607aaa36a97SAlex Deucher 	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x00000100,
608aaa36a97SAlex Deucher 	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
609aaa36a97SAlex Deucher 	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
610aaa36a97SAlex Deucher 	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
611aaa36a97SAlex Deucher 	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
612aaa36a97SAlex Deucher 	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
613aaa36a97SAlex Deucher 	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
614aaa36a97SAlex Deucher 	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
615aaa36a97SAlex Deucher 	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
616aaa36a97SAlex Deucher 	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
617aaa36a97SAlex Deucher 	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
618aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
619aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
620aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
621aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
622aaa36a97SAlex Deucher 	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
623aaa36a97SAlex Deucher 	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
624aaa36a97SAlex Deucher 	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
625aaa36a97SAlex Deucher 	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
626aaa36a97SAlex Deucher 	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
627aaa36a97SAlex Deucher 	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
628aaa36a97SAlex Deucher 	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
629aaa36a97SAlex Deucher 	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
630aaa36a97SAlex Deucher 	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
631aaa36a97SAlex Deucher 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
632aaa36a97SAlex Deucher 	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
633aaa36a97SAlex Deucher 	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
634aaa36a97SAlex Deucher 	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
635aaa36a97SAlex Deucher 	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
636aaa36a97SAlex Deucher 	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
637aaa36a97SAlex Deucher 	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
638aaa36a97SAlex Deucher 	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
639aaa36a97SAlex Deucher 	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
640aaa36a97SAlex Deucher 	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
641aaa36a97SAlex Deucher 	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
642aaa36a97SAlex Deucher 	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
643aaa36a97SAlex Deucher 	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
644aaa36a97SAlex Deucher 	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
645aaa36a97SAlex Deucher 	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
646aaa36a97SAlex Deucher 	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
647aaa36a97SAlex Deucher 	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
648aaa36a97SAlex Deucher 	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
649aaa36a97SAlex Deucher 	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
650aaa36a97SAlex Deucher 	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
651aaa36a97SAlex Deucher 	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
652aaa36a97SAlex Deucher 	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
653aaa36a97SAlex Deucher 	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
654aaa36a97SAlex Deucher 	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
655aaa36a97SAlex Deucher 	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
656aaa36a97SAlex Deucher 	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
657aaa36a97SAlex Deucher 	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
658aaa36a97SAlex Deucher 	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
659aaa36a97SAlex Deucher 	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
660aaa36a97SAlex Deucher 	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
661aaa36a97SAlex Deucher 	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
662aaa36a97SAlex Deucher 	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
663aaa36a97SAlex Deucher 	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
664aaa36a97SAlex Deucher 	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
665aaa36a97SAlex Deucher 	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
666aaa36a97SAlex Deucher 	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
667aaa36a97SAlex Deucher 	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
668aaa36a97SAlex Deucher 	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
669aaa36a97SAlex Deucher 	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
670aaa36a97SAlex Deucher 	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
671aaa36a97SAlex Deucher 	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
672aaa36a97SAlex Deucher 	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
673aaa36a97SAlex Deucher 	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
674aaa36a97SAlex Deucher 	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
675aaa36a97SAlex Deucher 	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
676aaa36a97SAlex Deucher };
677aaa36a97SAlex Deucher 
678e3c7656cSSamuel Li static const u32 stoney_golden_settings_a11[] =
679e3c7656cSSamuel Li {
680e3c7656cSSamuel Li 	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
681e3c7656cSSamuel Li 	mmGB_GPU_ID, 0x0000000f, 0x00000000,
682e3c7656cSSamuel Li 	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
683e3c7656cSSamuel Li 	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
684e3c7656cSSamuel Li 	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
685e3c7656cSSamuel Li 	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
686e3c7656cSSamuel Li 	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
687e3c7656cSSamuel Li 	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
688e3c7656cSSamuel Li 	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f1,
689e3c7656cSSamuel Li 	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x10101010,
690e3c7656cSSamuel Li };
691e3c7656cSSamuel Li 
692e3c7656cSSamuel Li static const u32 stoney_golden_common_all[] =
693e3c7656cSSamuel Li {
694e3c7656cSSamuel Li 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
695e3c7656cSSamuel Li 	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000000,
696e3c7656cSSamuel Li 	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
697e3c7656cSSamuel Li 	mmGB_ADDR_CONFIG, 0xffffffff, 0x12010001,
698e3c7656cSSamuel Li 	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
699e3c7656cSSamuel Li 	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
70098b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
70198b09f52Sozeng 	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
702e3c7656cSSamuel Li };
703e3c7656cSSamuel Li 
704e3c7656cSSamuel Li static const u32 stoney_mgcg_cgcg_init[] =
705e3c7656cSSamuel Li {
706e3c7656cSSamuel Li 	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
707e3c7656cSSamuel Li 	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
708e3c7656cSSamuel Li 	mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
709e3c7656cSSamuel Li 	mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
710e3c7656cSSamuel Li 	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200,
711e3c7656cSSamuel Li };
712e3c7656cSSamuel Li 
7139bdc2092SAndrey Grodzovsky 
7149bdc2092SAndrey Grodzovsky static const char * const sq_edc_source_names[] = {
7159bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_INVALID: No EDC error has occurred",
7169bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_INST: EDC source is Instruction Fetch",
7179bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_SGPR: EDC source is SGPR or SQC data return",
7189bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_VGPR: EDC source is VGPR",
7199bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_LDS: EDC source is LDS",
7209bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_GDS: EDC source is GDS",
7219bdc2092SAndrey Grodzovsky 	"SQ_EDC_INFO_SOURCE_TA: EDC source is TA",
7229bdc2092SAndrey Grodzovsky };
7239bdc2092SAndrey Grodzovsky 
724aaa36a97SAlex Deucher static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
725aaa36a97SAlex Deucher static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev);
726aaa36a97SAlex Deucher static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev);
727dbff57bcSAlex Deucher static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
7282b6cd977SEric Huang static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
7297dae69a2SAlex Deucher static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
73095243543SMonk Liu static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
73195243543SMonk Liu static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
732aaa36a97SAlex Deucher 
73392995254SEvan Quan #define CG_ACLK_CNTL__ACLK_DIVIDER_MASK                    0x0000007fL
73492995254SEvan Quan #define CG_ACLK_CNTL__ACLK_DIVIDER__SHIFT                  0x00000000L
73592995254SEvan Quan 
gfx_v8_0_init_golden_registers(struct amdgpu_device * adev)736aaa36a97SAlex Deucher static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
737aaa36a97SAlex Deucher {
73892995254SEvan Quan 	uint32_t data;
73992995254SEvan Quan 
740aaa36a97SAlex Deucher 	switch (adev->asic_type) {
741aaa36a97SAlex Deucher 	case CHIP_TOPAZ:
7429c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
743aaa36a97SAlex Deucher 							iceland_mgcg_cgcg_init,
744c47b41a7SChristian König 							ARRAY_SIZE(iceland_mgcg_cgcg_init));
7459c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
746aaa36a97SAlex Deucher 							golden_settings_iceland_a11,
747c47b41a7SChristian König 							ARRAY_SIZE(golden_settings_iceland_a11));
7489c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
749aaa36a97SAlex Deucher 							iceland_golden_common_all,
750c47b41a7SChristian König 							ARRAY_SIZE(iceland_golden_common_all));
751aaa36a97SAlex Deucher 		break;
752af15a2d5SDavid Zhang 	case CHIP_FIJI:
7539c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
754af15a2d5SDavid Zhang 							fiji_mgcg_cgcg_init,
755c47b41a7SChristian König 							ARRAY_SIZE(fiji_mgcg_cgcg_init));
7569c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
757af15a2d5SDavid Zhang 							golden_settings_fiji_a10,
758c47b41a7SChristian König 							ARRAY_SIZE(golden_settings_fiji_a10));
7599c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
760af15a2d5SDavid Zhang 							fiji_golden_common_all,
761c47b41a7SChristian König 							ARRAY_SIZE(fiji_golden_common_all));
762af15a2d5SDavid Zhang 		break;
763af15a2d5SDavid Zhang 
764aaa36a97SAlex Deucher 	case CHIP_TONGA:
7659c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
766aaa36a97SAlex Deucher 							tonga_mgcg_cgcg_init,
767c47b41a7SChristian König 							ARRAY_SIZE(tonga_mgcg_cgcg_init));
7689c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
769aaa36a97SAlex Deucher 							golden_settings_tonga_a11,
770c47b41a7SChristian König 							ARRAY_SIZE(golden_settings_tonga_a11));
7719c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
772aaa36a97SAlex Deucher 							tonga_golden_common_all,
773c47b41a7SChristian König 							ARRAY_SIZE(tonga_golden_common_all));
774aaa36a97SAlex Deucher 		break;
775aefbbd6cSLeo Liu 	case CHIP_VEGAM:
776aefbbd6cSLeo Liu 		amdgpu_device_program_register_sequence(adev,
777aefbbd6cSLeo Liu 							golden_settings_vegam_a11,
778aefbbd6cSLeo Liu 							ARRAY_SIZE(golden_settings_vegam_a11));
779aefbbd6cSLeo Liu 		amdgpu_device_program_register_sequence(adev,
780aefbbd6cSLeo Liu 							vegam_golden_common_all,
781aefbbd6cSLeo Liu 							ARRAY_SIZE(vegam_golden_common_all));
782aefbbd6cSLeo Liu 		break;
7832cc0c0b5SFlora Cui 	case CHIP_POLARIS11:
784c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
7859c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
7862cc0c0b5SFlora Cui 							golden_settings_polaris11_a11,
787c47b41a7SChristian König 							ARRAY_SIZE(golden_settings_polaris11_a11));
7889c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
7892cc0c0b5SFlora Cui 							polaris11_golden_common_all,
790c47b41a7SChristian König 							ARRAY_SIZE(polaris11_golden_common_all));
79168182d90SFlora Cui 		break;
7922cc0c0b5SFlora Cui 	case CHIP_POLARIS10:
7939c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
7942cc0c0b5SFlora Cui 							golden_settings_polaris10_a11,
795c47b41a7SChristian König 							ARRAY_SIZE(golden_settings_polaris10_a11));
7969c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
7972cc0c0b5SFlora Cui 							polaris10_golden_common_all,
798c47b41a7SChristian König 							ARRAY_SIZE(polaris10_golden_common_all));
79992995254SEvan Quan 		data = RREG32_SMC(ixCG_ACLK_CNTL);
80092995254SEvan Quan 		data &= ~CG_ACLK_CNTL__ACLK_DIVIDER_MASK;
80192995254SEvan Quan 		data |= 0x18 << CG_ACLK_CNTL__ACLK_DIVIDER__SHIFT;
80292995254SEvan Quan 		WREG32_SMC(ixCG_ACLK_CNTL, data);
80392995254SEvan Quan 		if ((adev->pdev->device == 0x67DF) && (adev->pdev->revision == 0xc7) &&
8045765a36dSRex Zhu 		    ((adev->pdev->subsystem_device == 0xb37 && adev->pdev->subsystem_vendor == 0x1002) ||
8055765a36dSRex Zhu 		     (adev->pdev->subsystem_device == 0x4a8 && adev->pdev->subsystem_vendor == 0x1043) ||
80692995254SEvan Quan 		     (adev->pdev->subsystem_device == 0x9480 && adev->pdev->subsystem_vendor == 0x1680))) {
807eeade25aSKen Wang 			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1E, 0xDD);
808eeade25aSKen Wang 			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1F, 0xD0);
809eeade25aSKen Wang 		}
81068182d90SFlora Cui 		break;
811aaa36a97SAlex Deucher 	case CHIP_CARRIZO:
8129c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
813aaa36a97SAlex Deucher 							cz_mgcg_cgcg_init,
814c47b41a7SChristian König 							ARRAY_SIZE(cz_mgcg_cgcg_init));
8159c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
816aaa36a97SAlex Deucher 							cz_golden_settings_a11,
817c47b41a7SChristian König 							ARRAY_SIZE(cz_golden_settings_a11));
8189c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
819aaa36a97SAlex Deucher 							cz_golden_common_all,
820c47b41a7SChristian König 							ARRAY_SIZE(cz_golden_common_all));
821aaa36a97SAlex Deucher 		break;
822e3c7656cSSamuel Li 	case CHIP_STONEY:
8239c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
824e3c7656cSSamuel Li 							stoney_mgcg_cgcg_init,
825c47b41a7SChristian König 							ARRAY_SIZE(stoney_mgcg_cgcg_init));
8269c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
827e3c7656cSSamuel Li 							stoney_golden_settings_a11,
828c47b41a7SChristian König 							ARRAY_SIZE(stoney_golden_settings_a11));
8299c3f2b54SAlex Deucher 		amdgpu_device_program_register_sequence(adev,
830e3c7656cSSamuel Li 							stoney_golden_common_all,
831c47b41a7SChristian König 							ARRAY_SIZE(stoney_golden_common_all));
832e3c7656cSSamuel Li 		break;
833aaa36a97SAlex Deucher 	default:
834aaa36a97SAlex Deucher 		break;
835aaa36a97SAlex Deucher 	}
836aaa36a97SAlex Deucher }
837aaa36a97SAlex Deucher 
gfx_v8_0_ring_test_ring(struct amdgpu_ring * ring)838aaa36a97SAlex Deucher static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
839aaa36a97SAlex Deucher {
840aaa36a97SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
841aaa36a97SAlex Deucher 	uint32_t tmp = 0;
842aaa36a97SAlex Deucher 	unsigned i;
843aaa36a97SAlex Deucher 	int r;
844aaa36a97SAlex Deucher 
845d54762ccSChristian König 	WREG32(mmSCRATCH_REG0, 0xCAFEDEAD);
846d54762ccSChristian König 	r = amdgpu_ring_alloc(ring, 3);
847dc9eeff8SChristian König 	if (r)
848aaa36a97SAlex Deucher 		return r;
849dc9eeff8SChristian König 
850aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
851d54762ccSChristian König 	amdgpu_ring_write(ring, mmSCRATCH_REG0 - PACKET3_SET_UCONFIG_REG_START);
852aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0xDEADBEEF);
853a27de35cSChristian König 	amdgpu_ring_commit(ring);
854aaa36a97SAlex Deucher 
855aaa36a97SAlex Deucher 	for (i = 0; i < adev->usec_timeout; i++) {
856d54762ccSChristian König 		tmp = RREG32(mmSCRATCH_REG0);
857aaa36a97SAlex Deucher 		if (tmp == 0xDEADBEEF)
858aaa36a97SAlex Deucher 			break;
859c366be54SSam Ravnborg 		udelay(1);
860aaa36a97SAlex Deucher 	}
861dc9eeff8SChristian König 
862dc9eeff8SChristian König 	if (i >= adev->usec_timeout)
863dc9eeff8SChristian König 		r = -ETIMEDOUT;
864dc9eeff8SChristian König 
865aaa36a97SAlex Deucher 	return r;
866aaa36a97SAlex Deucher }
867aaa36a97SAlex Deucher 
gfx_v8_0_ring_test_ib(struct amdgpu_ring * ring,long timeout)868bbec97aaSChristian König static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
869aaa36a97SAlex Deucher {
870aaa36a97SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
871aaa36a97SAlex Deucher 	struct amdgpu_ib ib;
872f54d1867SChris Wilson 	struct dma_fence *f = NULL;
8738f4039feSShirish S 
8748f4039feSShirish S 	unsigned int index;
8758f4039feSShirish S 	uint64_t gpu_addr;
8768f4039feSShirish S 	uint32_t tmp;
877bbec97aaSChristian König 	long r;
878aaa36a97SAlex Deucher 
8798f4039feSShirish S 	r = amdgpu_device_wb_get(adev, &index);
88098079389SChristian König 	if (r)
881aaa36a97SAlex Deucher 		return r;
8828f4039feSShirish S 
8838f4039feSShirish S 	gpu_addr = adev->wb.gpu_addr + (index * 4);
8848f4039feSShirish S 	adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
885b203dd95SChristian König 	memset(&ib, 0, sizeof(ib));
88688f4b10aSTim Huang 
88788f4b10aSTim Huang 	r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
88898079389SChristian König 	if (r)
88942d13693SChunming Zhou 		goto err1;
89098079389SChristian König 
8918f4039feSShirish S 	ib.ptr[0] = PACKET3(PACKET3_WRITE_DATA, 3);
8928f4039feSShirish S 	ib.ptr[1] = WRITE_DATA_DST_SEL(5) | WR_CONFIRM;
8938f4039feSShirish S 	ib.ptr[2] = lower_32_bits(gpu_addr);
8948f4039feSShirish S 	ib.ptr[3] = upper_32_bits(gpu_addr);
8958f4039feSShirish S 	ib.ptr[4] = 0xDEADBEEF;
8968f4039feSShirish S 	ib.length_dw = 5;
89742d13693SChunming Zhou 
89850ddc75eSJunwei Zhang 	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
89942d13693SChunming Zhou 	if (r)
90042d13693SChunming Zhou 		goto err2;
90142d13693SChunming Zhou 
902f54d1867SChris Wilson 	r = dma_fence_wait_timeout(f, false, timeout);
903bbec97aaSChristian König 	if (r == 0) {
904bbec97aaSChristian König 		r = -ETIMEDOUT;
905bbec97aaSChristian König 		goto err2;
906bbec97aaSChristian König 	} else if (r < 0) {
90742d13693SChunming Zhou 		goto err2;
908aaa36a97SAlex Deucher 	}
9098f4039feSShirish S 
9108f4039feSShirish S 	tmp = adev->wb.wb[index];
91198079389SChristian König 	if (tmp == 0xDEADBEEF)
912bbec97aaSChristian König 		r = 0;
91398079389SChristian König 	else
914aaa36a97SAlex Deucher 		r = -EINVAL;
9158f4039feSShirish S 
91642d13693SChunming Zhou err2:
917cc55c45dSMonk Liu 	amdgpu_ib_free(adev, &ib, NULL);
918f54d1867SChris Wilson 	dma_fence_put(f);
91942d13693SChunming Zhou err1:
9208f4039feSShirish S 	amdgpu_device_wb_free(adev, index);
921aaa36a97SAlex Deucher 	return r;
922aaa36a97SAlex Deucher }
923aaa36a97SAlex Deucher 
92413331ac3SMonk Liu 
gfx_v8_0_free_microcode(struct amdgpu_device * adev)925d6b20c87SAlex Deucher static void gfx_v8_0_free_microcode(struct amdgpu_device *adev)
926d6b20c87SAlex Deucher {
9270aaafb73SMario Limonciello 	amdgpu_ucode_release(&adev->gfx.pfp_fw);
9280aaafb73SMario Limonciello 	amdgpu_ucode_release(&adev->gfx.me_fw);
9290aaafb73SMario Limonciello 	amdgpu_ucode_release(&adev->gfx.ce_fw);
9300aaafb73SMario Limonciello 	amdgpu_ucode_release(&adev->gfx.rlc_fw);
9310aaafb73SMario Limonciello 	amdgpu_ucode_release(&adev->gfx.mec_fw);
93213331ac3SMonk Liu 	if ((adev->asic_type != CHIP_STONEY) &&
93313331ac3SMonk Liu 	    (adev->asic_type != CHIP_TOPAZ))
9340aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.mec2_fw);
93513331ac3SMonk Liu 
93613331ac3SMonk Liu 	kfree(adev->gfx.rlc.register_list_format);
93713331ac3SMonk Liu }
93813331ac3SMonk Liu 
gfx_v8_0_init_microcode(struct amdgpu_device * adev)939aaa36a97SAlex Deucher static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
940aaa36a97SAlex Deucher {
941aaa36a97SAlex Deucher 	const char *chip_name;
942aaa36a97SAlex Deucher 	int err;
943aaa36a97SAlex Deucher 	struct amdgpu_firmware_info *info = NULL;
944aaa36a97SAlex Deucher 	const struct common_firmware_header *header = NULL;
945595fd013SJammy Zhou 	const struct gfx_firmware_header_v1_0 *cp_hdr;
9462b6cd977SEric Huang 	const struct rlc_firmware_header_v2_0 *rlc_hdr;
9472b6cd977SEric Huang 	unsigned int *tmp = NULL, i;
948aaa36a97SAlex Deucher 
949aaa36a97SAlex Deucher 	DRM_DEBUG("\n");
950aaa36a97SAlex Deucher 
951aaa36a97SAlex Deucher 	switch (adev->asic_type) {
952aaa36a97SAlex Deucher 	case CHIP_TOPAZ:
953aaa36a97SAlex Deucher 		chip_name = "topaz";
954aaa36a97SAlex Deucher 		break;
955aaa36a97SAlex Deucher 	case CHIP_TONGA:
956aaa36a97SAlex Deucher 		chip_name = "tonga";
957aaa36a97SAlex Deucher 		break;
958aaa36a97SAlex Deucher 	case CHIP_CARRIZO:
959aaa36a97SAlex Deucher 		chip_name = "carrizo";
960aaa36a97SAlex Deucher 		break;
961af15a2d5SDavid Zhang 	case CHIP_FIJI:
962af15a2d5SDavid Zhang 		chip_name = "fiji";
963af15a2d5SDavid Zhang 		break;
96462aac201SLeo Liu 	case CHIP_STONEY:
96562aac201SLeo Liu 		chip_name = "stoney";
96668182d90SFlora Cui 		break;
9672cc0c0b5SFlora Cui 	case CHIP_POLARIS10:
9682cc0c0b5SFlora Cui 		chip_name = "polaris10";
96968182d90SFlora Cui 		break;
97062aac201SLeo Liu 	case CHIP_POLARIS11:
97162aac201SLeo Liu 		chip_name = "polaris11";
97262aac201SLeo Liu 		break;
973c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
974c4642a47SJunwei Zhang 		chip_name = "polaris12";
975c4642a47SJunwei Zhang 		break;
97662aac201SLeo Liu 	case CHIP_VEGAM:
97762aac201SLeo Liu 		chip_name = "vegam";
978e3c7656cSSamuel Li 		break;
979aaa36a97SAlex Deucher 	default:
980aaa36a97SAlex Deucher 		BUG();
981aaa36a97SAlex Deucher 	}
982aaa36a97SAlex Deucher 
983727030b0SEvan Quan 	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
9843a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
9853a3be8bbSYang Wang 					   "amdgpu/%s_pfp_2.bin", chip_name);
9860aaafb73SMario Limonciello 		if (err == -ENODEV) {
9873a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
9883a3be8bbSYang Wang 						   "amdgpu/%s_pfp.bin", chip_name);
989727030b0SEvan Quan 		}
990727030b0SEvan Quan 	} else {
9913a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
9923a3be8bbSYang Wang 					   "amdgpu/%s_pfp.bin", chip_name);
993727030b0SEvan Quan 	}
994aaa36a97SAlex Deucher 	if (err)
995aaa36a97SAlex Deucher 		goto out;
996595fd013SJammy Zhou 	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
997595fd013SJammy Zhou 	adev->gfx.pfp_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
998595fd013SJammy Zhou 	adev->gfx.pfp_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
999aaa36a97SAlex Deucher 
1000727030b0SEvan Quan 	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
10013a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
10023a3be8bbSYang Wang 					   "amdgpu/%s_me_2.bin", chip_name);
10030aaafb73SMario Limonciello 		if (err == -ENODEV) {
10043a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
10053a3be8bbSYang Wang 						   "amdgpu/%s_me.bin", chip_name);
1006727030b0SEvan Quan 		}
1007727030b0SEvan Quan 	} else {
10083a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
10093a3be8bbSYang Wang 					   "amdgpu/%s_me.bin", chip_name);
1010727030b0SEvan Quan 	}
1011aaa36a97SAlex Deucher 	if (err)
1012aaa36a97SAlex Deucher 		goto out;
1013595fd013SJammy Zhou 	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
1014595fd013SJammy Zhou 	adev->gfx.me_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1015ae65a26dSMonk Liu 
1016595fd013SJammy Zhou 	adev->gfx.me_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1017aaa36a97SAlex Deucher 
1018727030b0SEvan Quan 	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
10193a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
10203a3be8bbSYang Wang 					   "amdgpu/%s_ce_2.bin", chip_name);
10210aaafb73SMario Limonciello 		if (err == -ENODEV) {
10223a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
10233a3be8bbSYang Wang 						   "amdgpu/%s_ce.bin", chip_name);
1024727030b0SEvan Quan 		}
1025727030b0SEvan Quan 	} else {
10263a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
10273a3be8bbSYang Wang 					   "amdgpu/%s_ce.bin", chip_name);
1028727030b0SEvan Quan 	}
1029aaa36a97SAlex Deucher 	if (err)
1030aaa36a97SAlex Deucher 		goto out;
1031595fd013SJammy Zhou 	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
1032595fd013SJammy Zhou 	adev->gfx.ce_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1033595fd013SJammy Zhou 	adev->gfx.ce_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1034aaa36a97SAlex Deucher 
103563a7c748STrigger Huang 	/*
103663a7c748STrigger Huang 	 * Support for MCBP/Virtualization in combination with chained IBs is
103763a7c748STrigger Huang 	 * formal released on feature version #46
103863a7c748STrigger Huang 	 */
103963a7c748STrigger Huang 	if (adev->gfx.ce_feature_version >= 46 &&
104063a7c748STrigger Huang 	    adev->gfx.pfp_feature_version >= 46) {
104163a7c748STrigger Huang 		adev->virt.chained_ib_support = true;
104263a7c748STrigger Huang 		DRM_INFO("Chained IB support enabled!\n");
104363a7c748STrigger Huang 	} else
104463a7c748STrigger Huang 		adev->virt.chained_ib_support = false;
104563a7c748STrigger Huang 
10463a3be8bbSYang Wang 	err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw,
10473a3be8bbSYang Wang 				   "amdgpu/%s_rlc.bin", chip_name);
1048aaa36a97SAlex Deucher 	if (err)
1049aaa36a97SAlex Deucher 		goto out;
10502b6cd977SEric Huang 	rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
10512b6cd977SEric Huang 	adev->gfx.rlc_fw_version = le32_to_cpu(rlc_hdr->header.ucode_version);
10522b6cd977SEric Huang 	adev->gfx.rlc_feature_version = le32_to_cpu(rlc_hdr->ucode_feature_version);
10532b6cd977SEric Huang 
10542b6cd977SEric Huang 	adev->gfx.rlc.save_and_restore_offset =
10552b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->save_and_restore_offset);
10562b6cd977SEric Huang 	adev->gfx.rlc.clear_state_descriptor_offset =
10572b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->clear_state_descriptor_offset);
10582b6cd977SEric Huang 	adev->gfx.rlc.avail_scratch_ram_locations =
10592b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->avail_scratch_ram_locations);
10602b6cd977SEric Huang 	adev->gfx.rlc.reg_restore_list_size =
10612b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_restore_list_size);
10622b6cd977SEric Huang 	adev->gfx.rlc.reg_list_format_start =
10632b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_format_start);
10642b6cd977SEric Huang 	adev->gfx.rlc.reg_list_format_separate_start =
10652b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_format_separate_start);
10662b6cd977SEric Huang 	adev->gfx.rlc.starting_offsets_start =
10672b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->starting_offsets_start);
10682b6cd977SEric Huang 	adev->gfx.rlc.reg_list_format_size_bytes =
10692b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_format_size_bytes);
10702b6cd977SEric Huang 	adev->gfx.rlc.reg_list_size_bytes =
10712b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_size_bytes);
10722b6cd977SEric Huang 
10732b6cd977SEric Huang 	adev->gfx.rlc.register_list_format =
10742b6cd977SEric Huang 			kmalloc(adev->gfx.rlc.reg_list_format_size_bytes +
10752b6cd977SEric Huang 					adev->gfx.rlc.reg_list_size_bytes, GFP_KERNEL);
10762b6cd977SEric Huang 
10772b6cd977SEric Huang 	if (!adev->gfx.rlc.register_list_format) {
10782b6cd977SEric Huang 		err = -ENOMEM;
10792b6cd977SEric Huang 		goto out;
10802b6cd977SEric Huang 	}
10812b6cd977SEric Huang 
1082ae17c999SSlava Grigorev 	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
10832b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
108406668916SA. Wilcox 	for (i = 0 ; i < (adev->gfx.rlc.reg_list_format_size_bytes >> 2); i++)
10852b6cd977SEric Huang 		adev->gfx.rlc.register_list_format[i] =	le32_to_cpu(tmp[i]);
10862b6cd977SEric Huang 
10872b6cd977SEric Huang 	adev->gfx.rlc.register_restore = adev->gfx.rlc.register_list_format + i;
10882b6cd977SEric Huang 
1089ae17c999SSlava Grigorev 	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
10902b6cd977SEric Huang 			le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
109106668916SA. Wilcox 	for (i = 0 ; i < (adev->gfx.rlc.reg_list_size_bytes >> 2); i++)
10922b6cd977SEric Huang 		adev->gfx.rlc.register_restore[i] = le32_to_cpu(tmp[i]);
1093aaa36a97SAlex Deucher 
1094727030b0SEvan Quan 	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
10953a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
10963a3be8bbSYang Wang 					   "amdgpu/%s_mec_2.bin", chip_name);
10970aaafb73SMario Limonciello 		if (err == -ENODEV) {
10983a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
10993a3be8bbSYang Wang 						   "amdgpu/%s_mec.bin", chip_name);
1100727030b0SEvan Quan 		}
1101727030b0SEvan Quan 	} else {
11023a3be8bbSYang Wang 		err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
11033a3be8bbSYang Wang 					   "amdgpu/%s_mec.bin", chip_name);
1104727030b0SEvan Quan 	}
1105aaa36a97SAlex Deucher 	if (err)
1106aaa36a97SAlex Deucher 		goto out;
1107595fd013SJammy Zhou 	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1108595fd013SJammy Zhou 	adev->gfx.mec_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1109595fd013SJammy Zhou 	adev->gfx.mec_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1110aaa36a97SAlex Deucher 
111197dde76aSAlex Deucher 	if ((adev->asic_type != CHIP_STONEY) &&
111297dde76aSAlex Deucher 	    (adev->asic_type != CHIP_TOPAZ)) {
1113727030b0SEvan Quan 		if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
11143a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
11153a3be8bbSYang Wang 						   "amdgpu/%s_mec2_2.bin", chip_name);
11160aaafb73SMario Limonciello 			if (err == -ENODEV) {
11173a3be8bbSYang Wang 				err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
11183a3be8bbSYang Wang 							   "amdgpu/%s_mec2.bin", chip_name);
1119727030b0SEvan Quan 			}
1120727030b0SEvan Quan 		} else {
11213a3be8bbSYang Wang 			err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
11223a3be8bbSYang Wang 						   "amdgpu/%s_mec2.bin", chip_name);
1123727030b0SEvan Quan 		}
1124aaa36a97SAlex Deucher 		if (!err) {
1125595fd013SJammy Zhou 			cp_hdr = (const struct gfx_firmware_header_v1_0 *)
1126595fd013SJammy Zhou 				adev->gfx.mec2_fw->data;
1127e3c7656cSSamuel Li 			adev->gfx.mec2_fw_version =
1128e3c7656cSSamuel Li 				le32_to_cpu(cp_hdr->header.ucode_version);
1129e3c7656cSSamuel Li 			adev->gfx.mec2_feature_version =
1130e3c7656cSSamuel Li 				le32_to_cpu(cp_hdr->ucode_feature_version);
1131aaa36a97SAlex Deucher 		} else {
1132aaa36a97SAlex Deucher 			err = 0;
1133aaa36a97SAlex Deucher 			adev->gfx.mec2_fw = NULL;
1134aaa36a97SAlex Deucher 		}
1135e3c7656cSSamuel Li 	}
1136aaa36a97SAlex Deucher 
1137aaa36a97SAlex Deucher 	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_PFP];
1138aaa36a97SAlex Deucher 	info->ucode_id = AMDGPU_UCODE_ID_CP_PFP;
1139aaa36a97SAlex Deucher 	info->fw = adev->gfx.pfp_fw;
1140aaa36a97SAlex Deucher 	header = (const struct common_firmware_header *)info->fw->data;
1141aaa36a97SAlex Deucher 	adev->firmware.fw_size +=
1142aaa36a97SAlex Deucher 		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1143aaa36a97SAlex Deucher 
1144aaa36a97SAlex Deucher 	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_ME];
1145aaa36a97SAlex Deucher 	info->ucode_id = AMDGPU_UCODE_ID_CP_ME;
1146aaa36a97SAlex Deucher 	info->fw = adev->gfx.me_fw;
1147aaa36a97SAlex Deucher 	header = (const struct common_firmware_header *)info->fw->data;
1148aaa36a97SAlex Deucher 	adev->firmware.fw_size +=
1149aaa36a97SAlex Deucher 		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1150aaa36a97SAlex Deucher 
1151aaa36a97SAlex Deucher 	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_CE];
1152aaa36a97SAlex Deucher 	info->ucode_id = AMDGPU_UCODE_ID_CP_CE;
1153aaa36a97SAlex Deucher 	info->fw = adev->gfx.ce_fw;
1154aaa36a97SAlex Deucher 	header = (const struct common_firmware_header *)info->fw->data;
1155aaa36a97SAlex Deucher 	adev->firmware.fw_size +=
1156aaa36a97SAlex Deucher 		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1157aaa36a97SAlex Deucher 
1158aaa36a97SAlex Deucher 	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_RLC_G];
1159aaa36a97SAlex Deucher 	info->ucode_id = AMDGPU_UCODE_ID_RLC_G;
1160aaa36a97SAlex Deucher 	info->fw = adev->gfx.rlc_fw;
1161aaa36a97SAlex Deucher 	header = (const struct common_firmware_header *)info->fw->data;
1162aaa36a97SAlex Deucher 	adev->firmware.fw_size +=
1163aaa36a97SAlex Deucher 		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1164aaa36a97SAlex Deucher 
1165aaa36a97SAlex Deucher 	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC1];
1166aaa36a97SAlex Deucher 	info->ucode_id = AMDGPU_UCODE_ID_CP_MEC1;
1167aaa36a97SAlex Deucher 	info->fw = adev->gfx.mec_fw;
1168aaa36a97SAlex Deucher 	header = (const struct common_firmware_header *)info->fw->data;
1169aaa36a97SAlex Deucher 	adev->firmware.fw_size +=
1170aaa36a97SAlex Deucher 		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1171aaa36a97SAlex Deucher 
11724c2b2453SMonk Liu 	/* we need account JT in */
11734c2b2453SMonk Liu 	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
11744c2b2453SMonk Liu 	adev->firmware.fw_size +=
11754c2b2453SMonk Liu 		ALIGN(le32_to_cpu(cp_hdr->jt_size) << 2, PAGE_SIZE);
11764c2b2453SMonk Liu 
1177bed5712eSMonk Liu 	if (amdgpu_sriov_vf(adev)) {
1178bed5712eSMonk Liu 		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_STORAGE];
1179bed5712eSMonk Liu 		info->ucode_id = AMDGPU_UCODE_ID_STORAGE;
1180bed5712eSMonk Liu 		info->fw = adev->gfx.mec_fw;
1181bed5712eSMonk Liu 		adev->firmware.fw_size +=
1182bed5712eSMonk Liu 			ALIGN(le32_to_cpu(64 * PAGE_SIZE), PAGE_SIZE);
1183bed5712eSMonk Liu 	}
1184bed5712eSMonk Liu 
1185aaa36a97SAlex Deucher 	if (adev->gfx.mec2_fw) {
1186aaa36a97SAlex Deucher 		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC2];
1187aaa36a97SAlex Deucher 		info->ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
1188aaa36a97SAlex Deucher 		info->fw = adev->gfx.mec2_fw;
1189aaa36a97SAlex Deucher 		header = (const struct common_firmware_header *)info->fw->data;
1190aaa36a97SAlex Deucher 		adev->firmware.fw_size +=
1191aaa36a97SAlex Deucher 			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1192aaa36a97SAlex Deucher 	}
1193aaa36a97SAlex Deucher 
1194aaa36a97SAlex Deucher out:
1195aaa36a97SAlex Deucher 	if (err) {
11963a3be8bbSYang Wang 		dev_err(adev->dev, "gfx8: Failed to load firmware %s gfx firmware\n", chip_name);
11970aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.pfp_fw);
11980aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.me_fw);
11990aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.ce_fw);
12000aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.rlc_fw);
12010aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.mec_fw);
12020aaafb73SMario Limonciello 		amdgpu_ucode_release(&adev->gfx.mec2_fw);
1203aaa36a97SAlex Deucher 	}
1204aaa36a97SAlex Deucher 	return err;
1205aaa36a97SAlex Deucher }
1206aaa36a97SAlex Deucher 
gfx_v8_0_get_csb_buffer(struct amdgpu_device * adev,volatile u32 * buffer)12072b6cd977SEric Huang static void gfx_v8_0_get_csb_buffer(struct amdgpu_device *adev,
12082b6cd977SEric Huang 				    volatile u32 *buffer)
12092b6cd977SEric Huang {
12102b6cd977SEric Huang 	u32 count = 0, i;
12112b6cd977SEric Huang 	const struct cs_section_def *sect = NULL;
12122b6cd977SEric Huang 	const struct cs_extent_def *ext = NULL;
12132b6cd977SEric Huang 
12142b6cd977SEric Huang 	if (adev->gfx.rlc.cs_data == NULL)
12152b6cd977SEric Huang 		return;
12162b6cd977SEric Huang 	if (buffer == NULL)
12172b6cd977SEric Huang 		return;
12182b6cd977SEric Huang 
12192b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
12202b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
12212b6cd977SEric Huang 
12222b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
12232b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(0x80000000);
12242b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(0x80000000);
12252b6cd977SEric Huang 
12262b6cd977SEric Huang 	for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
12272b6cd977SEric Huang 		for (ext = sect->section; ext->extent != NULL; ++ext) {
12282b6cd977SEric Huang 			if (sect->id == SECT_CONTEXT) {
12292b6cd977SEric Huang 				buffer[count++] =
12302b6cd977SEric Huang 					cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
12312b6cd977SEric Huang 				buffer[count++] = cpu_to_le32(ext->reg_index -
12322b6cd977SEric Huang 						PACKET3_SET_CONTEXT_REG_START);
12332b6cd977SEric Huang 				for (i = 0; i < ext->reg_count; i++)
12342b6cd977SEric Huang 					buffer[count++] = cpu_to_le32(ext->extent[i]);
12352b6cd977SEric Huang 			} else {
12362b6cd977SEric Huang 				return;
12372b6cd977SEric Huang 			}
12382b6cd977SEric Huang 		}
12392b6cd977SEric Huang 	}
12402b6cd977SEric Huang 
12412b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
12422b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG -
12432b6cd977SEric Huang 			PACKET3_SET_CONTEXT_REG_START);
124434817db6SAlex Deucher 	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
124534817db6SAlex Deucher 	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
12462b6cd977SEric Huang 
12472b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
12482b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
12492b6cd977SEric Huang 
12502b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
12512b6cd977SEric Huang 	buffer[count++] = cpu_to_le32(0);
12522b6cd977SEric Huang }
12532b6cd977SEric Huang 
gfx_v8_0_cp_jump_table_num(struct amdgpu_device * adev)1254106c7d61SLikun Gao static int gfx_v8_0_cp_jump_table_num(struct amdgpu_device *adev)
1255fb16007bSAlex Deucher {
1256fb16007bSAlex Deucher 	if (adev->asic_type == CHIP_CARRIZO)
1257106c7d61SLikun Gao 		return 5;
1258106c7d61SLikun Gao 	else
1259106c7d61SLikun Gao 		return 4;
1260fb16007bSAlex Deucher }
1261fb16007bSAlex Deucher 
gfx_v8_0_rlc_init(struct amdgpu_device * adev)12622b6cd977SEric Huang static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)
12632b6cd977SEric Huang {
12642b6cd977SEric Huang 	const struct cs_section_def *cs_data;
12652b6cd977SEric Huang 	int r;
12662b6cd977SEric Huang 
12672b6cd977SEric Huang 	adev->gfx.rlc.cs_data = vi_cs_data;
12682b6cd977SEric Huang 
12692b6cd977SEric Huang 	cs_data = adev->gfx.rlc.cs_data;
12702b6cd977SEric Huang 
12712b6cd977SEric Huang 	if (cs_data) {
1272106c7d61SLikun Gao 		/* init clear state block */
1273106c7d61SLikun Gao 		r = amdgpu_gfx_rlc_init_csb(adev);
1274106c7d61SLikun Gao 		if (r)
12752b6cd977SEric Huang 			return r;
12762b6cd977SEric Huang 	}
12772b6cd977SEric Huang 
1278fb16007bSAlex Deucher 	if ((adev->asic_type == CHIP_CARRIZO) ||
1279fb16007bSAlex Deucher 	    (adev->asic_type == CHIP_STONEY)) {
128007cf1a0bSAlex Deucher 		adev->gfx.rlc.cp_table_size = ALIGN(96 * 5 * 4, 2048) + (64 * 1024); /* JT + GDS */
1281106c7d61SLikun Gao 		r = amdgpu_gfx_rlc_init_cpt(adev);
1282106c7d61SLikun Gao 		if (r)
1283fb16007bSAlex Deucher 			return r;
1284fb16007bSAlex Deucher 	}
1285fb16007bSAlex Deucher 
1286460c484fSJacob He 	/* init spm vmid with 0xf */
1287460c484fSJacob He 	if (adev->gfx.rlc.funcs->update_spm_vmid)
1288b5387349SYuanShang 		adev->gfx.rlc.funcs->update_spm_vmid(adev, NULL, 0xf);
1289460c484fSJacob He 
12902b6cd977SEric Huang 	return 0;
12912b6cd977SEric Huang }
12922b6cd977SEric Huang 
gfx_v8_0_mec_fini(struct amdgpu_device * adev)1293aaa36a97SAlex Deucher static void gfx_v8_0_mec_fini(struct amdgpu_device *adev)
1294aaa36a97SAlex Deucher {
1295078af1a3SChristian König 	amdgpu_bo_free_kernel(&adev->gfx.mec.hpd_eop_obj, NULL, NULL);
1296aaa36a97SAlex Deucher }
1297aaa36a97SAlex Deucher 
gfx_v8_0_mec_init(struct amdgpu_device * adev)1298aaa36a97SAlex Deucher static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
1299aaa36a97SAlex Deucher {
1300aaa36a97SAlex Deucher 	int r;
1301aaa36a97SAlex Deucher 	u32 *hpd;
130242794b27SAndres Rodriguez 	size_t mec_hpd_size;
1303aaa36a97SAlex Deucher 
1304be697aa3SLe Ma 	bitmap_zero(adev->gfx.mec_bitmap[0].queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
130578c16834SAndres Rodriguez 
130678c16834SAndres Rodriguez 	/* take ownership of the relevant compute queues */
130741f6a99aSAlex Deucher 	amdgpu_gfx_compute_queue_acquire(adev);
130878c16834SAndres Rodriguez 
130978c16834SAndres Rodriguez 	mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
1310a300de40SMonk Liu 	if (mec_hpd_size) {
1311a4a02777SChristian König 		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
131258ab2c08SChristian König 					      AMDGPU_GEM_DOMAIN_VRAM |
131358ab2c08SChristian König 					      AMDGPU_GEM_DOMAIN_GTT,
1314a4a02777SChristian König 					      &adev->gfx.mec.hpd_eop_obj,
1315a4a02777SChristian König 					      &adev->gfx.mec.hpd_eop_gpu_addr,
1316a4a02777SChristian König 					      (void **)&hpd);
1317aaa36a97SAlex Deucher 		if (r) {
1318aaa36a97SAlex Deucher 			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
1319aaa36a97SAlex Deucher 			return r;
1320aaa36a97SAlex Deucher 		}
1321aaa36a97SAlex Deucher 
132242794b27SAndres Rodriguez 		memset(hpd, 0, mec_hpd_size);
1323aaa36a97SAlex Deucher 
1324aaa36a97SAlex Deucher 		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
1325aaa36a97SAlex Deucher 		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
1326a300de40SMonk Liu 	}
1327aaa36a97SAlex Deucher 
1328aaa36a97SAlex Deucher 	return 0;
1329aaa36a97SAlex Deucher }
1330aaa36a97SAlex Deucher 
1331ccba7691SAlex Deucher static const u32 vgpr_init_compute_shader[] =
1332ccba7691SAlex Deucher {
1333ccba7691SAlex Deucher 	0x7e000209, 0x7e020208,
1334ccba7691SAlex Deucher 	0x7e040207, 0x7e060206,
1335ccba7691SAlex Deucher 	0x7e080205, 0x7e0a0204,
1336ccba7691SAlex Deucher 	0x7e0c0203, 0x7e0e0202,
1337ccba7691SAlex Deucher 	0x7e100201, 0x7e120200,
1338ccba7691SAlex Deucher 	0x7e140209, 0x7e160208,
1339ccba7691SAlex Deucher 	0x7e180207, 0x7e1a0206,
1340ccba7691SAlex Deucher 	0x7e1c0205, 0x7e1e0204,
1341ccba7691SAlex Deucher 	0x7e200203, 0x7e220202,
1342ccba7691SAlex Deucher 	0x7e240201, 0x7e260200,
1343ccba7691SAlex Deucher 	0x7e280209, 0x7e2a0208,
1344ccba7691SAlex Deucher 	0x7e2c0207, 0x7e2e0206,
1345ccba7691SAlex Deucher 	0x7e300205, 0x7e320204,
1346ccba7691SAlex Deucher 	0x7e340203, 0x7e360202,
1347ccba7691SAlex Deucher 	0x7e380201, 0x7e3a0200,
1348ccba7691SAlex Deucher 	0x7e3c0209, 0x7e3e0208,
1349ccba7691SAlex Deucher 	0x7e400207, 0x7e420206,
1350ccba7691SAlex Deucher 	0x7e440205, 0x7e460204,
1351ccba7691SAlex Deucher 	0x7e480203, 0x7e4a0202,
1352ccba7691SAlex Deucher 	0x7e4c0201, 0x7e4e0200,
1353ccba7691SAlex Deucher 	0x7e500209, 0x7e520208,
1354ccba7691SAlex Deucher 	0x7e540207, 0x7e560206,
1355ccba7691SAlex Deucher 	0x7e580205, 0x7e5a0204,
1356ccba7691SAlex Deucher 	0x7e5c0203, 0x7e5e0202,
1357ccba7691SAlex Deucher 	0x7e600201, 0x7e620200,
1358ccba7691SAlex Deucher 	0x7e640209, 0x7e660208,
1359ccba7691SAlex Deucher 	0x7e680207, 0x7e6a0206,
1360ccba7691SAlex Deucher 	0x7e6c0205, 0x7e6e0204,
1361ccba7691SAlex Deucher 	0x7e700203, 0x7e720202,
1362ccba7691SAlex Deucher 	0x7e740201, 0x7e760200,
1363ccba7691SAlex Deucher 	0x7e780209, 0x7e7a0208,
1364ccba7691SAlex Deucher 	0x7e7c0207, 0x7e7e0206,
1365ccba7691SAlex Deucher 	0xbf8a0000, 0xbf810000,
1366ccba7691SAlex Deucher };
1367ccba7691SAlex Deucher 
1368ccba7691SAlex Deucher static const u32 sgpr_init_compute_shader[] =
1369ccba7691SAlex Deucher {
1370ccba7691SAlex Deucher 	0xbe8a0100, 0xbe8c0102,
1371ccba7691SAlex Deucher 	0xbe8e0104, 0xbe900106,
1372ccba7691SAlex Deucher 	0xbe920108, 0xbe940100,
1373ccba7691SAlex Deucher 	0xbe960102, 0xbe980104,
1374ccba7691SAlex Deucher 	0xbe9a0106, 0xbe9c0108,
1375ccba7691SAlex Deucher 	0xbe9e0100, 0xbea00102,
1376ccba7691SAlex Deucher 	0xbea20104, 0xbea40106,
1377ccba7691SAlex Deucher 	0xbea60108, 0xbea80100,
1378ccba7691SAlex Deucher 	0xbeaa0102, 0xbeac0104,
1379ccba7691SAlex Deucher 	0xbeae0106, 0xbeb00108,
1380ccba7691SAlex Deucher 	0xbeb20100, 0xbeb40102,
1381ccba7691SAlex Deucher 	0xbeb60104, 0xbeb80106,
1382ccba7691SAlex Deucher 	0xbeba0108, 0xbebc0100,
1383ccba7691SAlex Deucher 	0xbebe0102, 0xbec00104,
1384ccba7691SAlex Deucher 	0xbec20106, 0xbec40108,
1385ccba7691SAlex Deucher 	0xbec60100, 0xbec80102,
1386ccba7691SAlex Deucher 	0xbee60004, 0xbee70005,
1387ccba7691SAlex Deucher 	0xbeea0006, 0xbeeb0007,
1388ccba7691SAlex Deucher 	0xbee80008, 0xbee90009,
1389ccba7691SAlex Deucher 	0xbefc0000, 0xbf8a0000,
1390ccba7691SAlex Deucher 	0xbf810000, 0x00000000,
1391ccba7691SAlex Deucher };
1392ccba7691SAlex Deucher 
1393ccba7691SAlex Deucher static const u32 vgpr_init_regs[] =
1394ccba7691SAlex Deucher {
1395ccba7691SAlex Deucher 	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xffffffff,
139638610f15SNicolai Hähnle 	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1397ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_X, 256*4,
1398ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Y, 1,
1399ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Z, 1,
140038610f15SNicolai Hähnle 	mmCOMPUTE_PGM_RSRC1, 0x100004f, /* VGPRS=15 (64 logical VGPRs), SGPRS=1 (16 SGPRs), BULKY=1 */
1401ccba7691SAlex Deucher 	mmCOMPUTE_PGM_RSRC2, 20,
1402ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1403ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1404ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1405ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1406ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1407ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1408ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1409ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1410ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1411ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1412ccba7691SAlex Deucher };
1413ccba7691SAlex Deucher 
1414ccba7691SAlex Deucher static const u32 sgpr1_init_regs[] =
1415ccba7691SAlex Deucher {
1416ccba7691SAlex Deucher 	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0x0f,
141738610f15SNicolai Hähnle 	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1418ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_X, 256*5,
1419ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Y, 1,
1420ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Z, 1,
142138610f15SNicolai Hähnle 	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1422ccba7691SAlex Deucher 	mmCOMPUTE_PGM_RSRC2, 20,
1423ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1424ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1425ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1426ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1427ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1428ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1429ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1430ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1431ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1432ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1433ccba7691SAlex Deucher };
1434ccba7691SAlex Deucher 
1435ccba7691SAlex Deucher static const u32 sgpr2_init_regs[] =
1436ccba7691SAlex Deucher {
1437ccba7691SAlex Deucher 	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xf0,
1438ccba7691SAlex Deucher 	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000,
1439ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_X, 256*5,
1440ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Y, 1,
1441ccba7691SAlex Deucher 	mmCOMPUTE_NUM_THREAD_Z, 1,
144238610f15SNicolai Hähnle 	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1443ccba7691SAlex Deucher 	mmCOMPUTE_PGM_RSRC2, 20,
1444ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1445ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1446ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1447ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1448ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1449ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1450ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1451ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1452ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1453ccba7691SAlex Deucher 	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1454ccba7691SAlex Deucher };
1455ccba7691SAlex Deucher 
1456ccba7691SAlex Deucher static const u32 sec_ded_counter_registers[] =
1457ccba7691SAlex Deucher {
1458ccba7691SAlex Deucher 	mmCPC_EDC_ATC_CNT,
1459ccba7691SAlex Deucher 	mmCPC_EDC_SCRATCH_CNT,
1460ccba7691SAlex Deucher 	mmCPC_EDC_UCODE_CNT,
1461ccba7691SAlex Deucher 	mmCPF_EDC_ATC_CNT,
1462ccba7691SAlex Deucher 	mmCPF_EDC_ROQ_CNT,
1463ccba7691SAlex Deucher 	mmCPF_EDC_TAG_CNT,
1464ccba7691SAlex Deucher 	mmCPG_EDC_ATC_CNT,
1465ccba7691SAlex Deucher 	mmCPG_EDC_DMA_CNT,
1466ccba7691SAlex Deucher 	mmCPG_EDC_TAG_CNT,
1467ccba7691SAlex Deucher 	mmDC_EDC_CSINVOC_CNT,
1468ccba7691SAlex Deucher 	mmDC_EDC_RESTORE_CNT,
1469ccba7691SAlex Deucher 	mmDC_EDC_STATE_CNT,
1470ccba7691SAlex Deucher 	mmGDS_EDC_CNT,
1471ccba7691SAlex Deucher 	mmGDS_EDC_GRBM_CNT,
1472ccba7691SAlex Deucher 	mmGDS_EDC_OA_DED,
1473ccba7691SAlex Deucher 	mmSPI_EDC_CNT,
1474ccba7691SAlex Deucher 	mmSQC_ATC_EDC_GATCL1_CNT,
1475ccba7691SAlex Deucher 	mmSQC_EDC_CNT,
1476ccba7691SAlex Deucher 	mmSQ_EDC_DED_CNT,
1477ccba7691SAlex Deucher 	mmSQ_EDC_INFO,
1478ccba7691SAlex Deucher 	mmSQ_EDC_SEC_CNT,
1479ccba7691SAlex Deucher 	mmTCC_EDC_CNT,
1480ccba7691SAlex Deucher 	mmTCP_ATC_EDC_GATCL1_CNT,
1481ccba7691SAlex Deucher 	mmTCP_EDC_CNT,
1482ccba7691SAlex Deucher 	mmTD_EDC_CNT
1483ccba7691SAlex Deucher };
1484ccba7691SAlex Deucher 
gfx_v8_0_do_edc_gpr_workarounds(struct amdgpu_device * adev)1485ccba7691SAlex Deucher static int gfx_v8_0_do_edc_gpr_workarounds(struct amdgpu_device *adev)
1486ccba7691SAlex Deucher {
1487ccba7691SAlex Deucher 	struct amdgpu_ring *ring = &adev->gfx.compute_ring[0];
1488ccba7691SAlex Deucher 	struct amdgpu_ib ib;
1489f54d1867SChris Wilson 	struct dma_fence *f = NULL;
1490ccba7691SAlex Deucher 	int r, i;
1491ccba7691SAlex Deucher 	u32 tmp;
1492ccba7691SAlex Deucher 	unsigned total_size, vgpr_offset, sgpr_offset;
1493ccba7691SAlex Deucher 	u64 gpu_addr;
1494ccba7691SAlex Deucher 
1495ccba7691SAlex Deucher 	/* only supported on CZ */
1496ccba7691SAlex Deucher 	if (adev->asic_type != CHIP_CARRIZO)
1497ccba7691SAlex Deucher 		return 0;
1498ccba7691SAlex Deucher 
1499ccba7691SAlex Deucher 	/* bail if the compute ring is not ready */
1500c66ed765SAndrey Grodzovsky 	if (!ring->sched.ready)
1501ccba7691SAlex Deucher 		return 0;
1502ccba7691SAlex Deucher 
1503ccba7691SAlex Deucher 	tmp = RREG32(mmGB_EDC_MODE);
1504ccba7691SAlex Deucher 	WREG32(mmGB_EDC_MODE, 0);
1505ccba7691SAlex Deucher 
1506ccba7691SAlex Deucher 	total_size =
1507ccba7691SAlex Deucher 		(((ARRAY_SIZE(vgpr_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1508ccba7691SAlex Deucher 	total_size +=
1509ccba7691SAlex Deucher 		(((ARRAY_SIZE(sgpr1_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1510ccba7691SAlex Deucher 	total_size +=
1511ccba7691SAlex Deucher 		(((ARRAY_SIZE(sgpr2_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1512ccba7691SAlex Deucher 	total_size = ALIGN(total_size, 256);
1513ccba7691SAlex Deucher 	vgpr_offset = total_size;
1514ccba7691SAlex Deucher 	total_size += ALIGN(sizeof(vgpr_init_compute_shader), 256);
1515ccba7691SAlex Deucher 	sgpr_offset = total_size;
1516ccba7691SAlex Deucher 	total_size += sizeof(sgpr_init_compute_shader);
1517ccba7691SAlex Deucher 
1518ccba7691SAlex Deucher 	/* allocate an indirect buffer to put the commands in */
1519ccba7691SAlex Deucher 	memset(&ib, 0, sizeof(ib));
1520c8e42d57Sxinhui pan 	r = amdgpu_ib_get(adev, NULL, total_size,
1521c8e42d57Sxinhui pan 					AMDGPU_IB_POOL_DIRECT, &ib);
1522ccba7691SAlex Deucher 	if (r) {
1523ccba7691SAlex Deucher 		DRM_ERROR("amdgpu: failed to get ib (%d).\n", r);
1524ccba7691SAlex Deucher 		return r;
1525ccba7691SAlex Deucher 	}
1526ccba7691SAlex Deucher 
1527ccba7691SAlex Deucher 	/* load the compute shaders */
1528ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(vgpr_init_compute_shader); i++)
1529ccba7691SAlex Deucher 		ib.ptr[i + (vgpr_offset / 4)] = vgpr_init_compute_shader[i];
1530ccba7691SAlex Deucher 
1531ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(sgpr_init_compute_shader); i++)
1532ccba7691SAlex Deucher 		ib.ptr[i + (sgpr_offset / 4)] = sgpr_init_compute_shader[i];
1533ccba7691SAlex Deucher 
1534ccba7691SAlex Deucher 	/* init the ib length to 0 */
1535ccba7691SAlex Deucher 	ib.length_dw = 0;
1536ccba7691SAlex Deucher 
1537ccba7691SAlex Deucher 	/* VGPR */
1538ccba7691SAlex Deucher 	/* write the register state for the compute dispatch */
1539ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(vgpr_init_regs); i += 2) {
1540ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1541ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = vgpr_init_regs[i] - PACKET3_SET_SH_REG_START;
1542ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = vgpr_init_regs[i + 1];
1543ccba7691SAlex Deucher 	}
1544ccba7691SAlex Deucher 	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1545ccba7691SAlex Deucher 	gpu_addr = (ib.gpu_addr + (u64)vgpr_offset) >> 8;
1546ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1547ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1548ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1549ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1550ccba7691SAlex Deucher 
1551ccba7691SAlex Deucher 	/* write dispatch packet */
1552ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1553ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 8; /* x */
1554ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* y */
1555ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* z */
1556ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] =
1557ccba7691SAlex Deucher 		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1558ccba7691SAlex Deucher 
1559ccba7691SAlex Deucher 	/* write CS partial flush packet */
1560ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1561ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1562ccba7691SAlex Deucher 
1563ccba7691SAlex Deucher 	/* SGPR1 */
1564ccba7691SAlex Deucher 	/* write the register state for the compute dispatch */
1565ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(sgpr1_init_regs); i += 2) {
1566ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1567ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i] - PACKET3_SET_SH_REG_START;
1568ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i + 1];
1569ccba7691SAlex Deucher 	}
1570ccba7691SAlex Deucher 	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1571ccba7691SAlex Deucher 	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1572ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1573ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1574ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1575ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1576ccba7691SAlex Deucher 
1577ccba7691SAlex Deucher 	/* write dispatch packet */
1578ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1579ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 8; /* x */
1580ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* y */
1581ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* z */
1582ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] =
1583ccba7691SAlex Deucher 		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1584ccba7691SAlex Deucher 
1585ccba7691SAlex Deucher 	/* write CS partial flush packet */
1586ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1587ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1588ccba7691SAlex Deucher 
1589ccba7691SAlex Deucher 	/* SGPR2 */
1590ccba7691SAlex Deucher 	/* write the register state for the compute dispatch */
1591ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(sgpr2_init_regs); i += 2) {
1592ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1593ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i] - PACKET3_SET_SH_REG_START;
1594ccba7691SAlex Deucher 		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i + 1];
1595ccba7691SAlex Deucher 	}
1596ccba7691SAlex Deucher 	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1597ccba7691SAlex Deucher 	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1598ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1599ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1600ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1601ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1602ccba7691SAlex Deucher 
1603ccba7691SAlex Deucher 	/* write dispatch packet */
1604ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1605ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 8; /* x */
1606ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* y */
1607ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = 1; /* z */
1608ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] =
1609ccba7691SAlex Deucher 		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1610ccba7691SAlex Deucher 
1611ccba7691SAlex Deucher 	/* write CS partial flush packet */
1612ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1613ccba7691SAlex Deucher 	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1614ccba7691SAlex Deucher 
1615ccba7691SAlex Deucher 	/* shedule the ib on the ring */
161650ddc75eSJunwei Zhang 	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
1617ccba7691SAlex Deucher 	if (r) {
1618ccba7691SAlex Deucher 		DRM_ERROR("amdgpu: ib submit failed (%d).\n", r);
1619ccba7691SAlex Deucher 		goto fail;
1620ccba7691SAlex Deucher 	}
1621ccba7691SAlex Deucher 
1622ccba7691SAlex Deucher 	/* wait for the GPU to finish processing the IB */
1623f54d1867SChris Wilson 	r = dma_fence_wait(f, false);
1624ccba7691SAlex Deucher 	if (r) {
1625ccba7691SAlex Deucher 		DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
1626ccba7691SAlex Deucher 		goto fail;
1627ccba7691SAlex Deucher 	}
1628ccba7691SAlex Deucher 
1629ccba7691SAlex Deucher 	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, DED_MODE, 2);
1630ccba7691SAlex Deucher 	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, PROP_FED, 1);
1631ccba7691SAlex Deucher 	WREG32(mmGB_EDC_MODE, tmp);
1632ccba7691SAlex Deucher 
1633ccba7691SAlex Deucher 	tmp = RREG32(mmCC_GC_EDC_CONFIG);
1634ccba7691SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CC_GC_EDC_CONFIG, DIS_EDC, 0) | 1;
1635ccba7691SAlex Deucher 	WREG32(mmCC_GC_EDC_CONFIG, tmp);
1636ccba7691SAlex Deucher 
1637ccba7691SAlex Deucher 
1638ccba7691SAlex Deucher 	/* read back registers to clear the counters */
1639ccba7691SAlex Deucher 	for (i = 0; i < ARRAY_SIZE(sec_ded_counter_registers); i++)
1640ccba7691SAlex Deucher 		RREG32(sec_ded_counter_registers[i]);
1641ccba7691SAlex Deucher 
1642ccba7691SAlex Deucher fail:
1643cc55c45dSMonk Liu 	amdgpu_ib_free(adev, &ib, NULL);
1644f54d1867SChris Wilson 	dma_fence_put(f);
1645ccba7691SAlex Deucher 
1646ccba7691SAlex Deucher 	return r;
1647ccba7691SAlex Deucher }
1648ccba7691SAlex Deucher 
gfx_v8_0_gpu_early_init(struct amdgpu_device * adev)164968182d90SFlora Cui static int gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
16500bde3a95SAlex Deucher {
16510bde3a95SAlex Deucher 	u32 gb_addr_config;
1652e98042dbSyu kuai 	u32 mc_arb_ramcfg;
16530bde3a95SAlex Deucher 	u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
16540bde3a95SAlex Deucher 	u32 tmp;
165568182d90SFlora Cui 	int ret;
16560bde3a95SAlex Deucher 
16570bde3a95SAlex Deucher 	switch (adev->asic_type) {
16580bde3a95SAlex Deucher 	case CHIP_TOPAZ:
16590bde3a95SAlex Deucher 		adev->gfx.config.max_shader_engines = 1;
16600bde3a95SAlex Deucher 		adev->gfx.config.max_tile_pipes = 2;
16610bde3a95SAlex Deucher 		adev->gfx.config.max_cu_per_sh = 6;
16620bde3a95SAlex Deucher 		adev->gfx.config.max_sh_per_se = 1;
16630bde3a95SAlex Deucher 		adev->gfx.config.max_backends_per_se = 2;
16640bde3a95SAlex Deucher 		adev->gfx.config.max_texture_channel_caches = 2;
16650bde3a95SAlex Deucher 		adev->gfx.config.max_gprs = 256;
16660bde3a95SAlex Deucher 		adev->gfx.config.max_gs_threads = 32;
16670bde3a95SAlex Deucher 		adev->gfx.config.max_hw_contexts = 8;
16680bde3a95SAlex Deucher 
16690bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
16700bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
16710bde3a95SAlex Deucher 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
16720bde3a95SAlex Deucher 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
16730bde3a95SAlex Deucher 		gb_addr_config = TOPAZ_GB_ADDR_CONFIG_GOLDEN;
16740bde3a95SAlex Deucher 		break;
16750bde3a95SAlex Deucher 	case CHIP_FIJI:
16760bde3a95SAlex Deucher 		adev->gfx.config.max_shader_engines = 4;
16770bde3a95SAlex Deucher 		adev->gfx.config.max_tile_pipes = 16;
16780bde3a95SAlex Deucher 		adev->gfx.config.max_cu_per_sh = 16;
16790bde3a95SAlex Deucher 		adev->gfx.config.max_sh_per_se = 1;
16800bde3a95SAlex Deucher 		adev->gfx.config.max_backends_per_se = 4;
16815f2e816bSFlora Cui 		adev->gfx.config.max_texture_channel_caches = 16;
16820bde3a95SAlex Deucher 		adev->gfx.config.max_gprs = 256;
16830bde3a95SAlex Deucher 		adev->gfx.config.max_gs_threads = 32;
16840bde3a95SAlex Deucher 		adev->gfx.config.max_hw_contexts = 8;
16850bde3a95SAlex Deucher 
16860bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
16870bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
16880bde3a95SAlex Deucher 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
16890bde3a95SAlex Deucher 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
16900bde3a95SAlex Deucher 		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
16910bde3a95SAlex Deucher 		break;
16922cc0c0b5SFlora Cui 	case CHIP_POLARIS11:
1693c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
169468182d90SFlora Cui 		ret = amdgpu_atombios_get_gfx_info(adev);
169568182d90SFlora Cui 		if (ret)
169668182d90SFlora Cui 			return ret;
169768182d90SFlora Cui 		adev->gfx.config.max_gprs = 256;
169868182d90SFlora Cui 		adev->gfx.config.max_gs_threads = 32;
169968182d90SFlora Cui 		adev->gfx.config.max_hw_contexts = 8;
170068182d90SFlora Cui 
170168182d90SFlora Cui 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
170268182d90SFlora Cui 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
170368182d90SFlora Cui 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
170468182d90SFlora Cui 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
17052cc0c0b5SFlora Cui 		gb_addr_config = POLARIS11_GB_ADDR_CONFIG_GOLDEN;
170668182d90SFlora Cui 		break;
17072cc0c0b5SFlora Cui 	case CHIP_POLARIS10:
170871765469SLeo Liu 	case CHIP_VEGAM:
170968182d90SFlora Cui 		ret = amdgpu_atombios_get_gfx_info(adev);
171068182d90SFlora Cui 		if (ret)
171168182d90SFlora Cui 			return ret;
171268182d90SFlora Cui 		adev->gfx.config.max_gprs = 256;
171368182d90SFlora Cui 		adev->gfx.config.max_gs_threads = 32;
171468182d90SFlora Cui 		adev->gfx.config.max_hw_contexts = 8;
171568182d90SFlora Cui 
171668182d90SFlora Cui 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
171768182d90SFlora Cui 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
171868182d90SFlora Cui 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
171968182d90SFlora Cui 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
172068182d90SFlora Cui 		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
172168182d90SFlora Cui 		break;
17220bde3a95SAlex Deucher 	case CHIP_TONGA:
17230bde3a95SAlex Deucher 		adev->gfx.config.max_shader_engines = 4;
17240bde3a95SAlex Deucher 		adev->gfx.config.max_tile_pipes = 8;
17250bde3a95SAlex Deucher 		adev->gfx.config.max_cu_per_sh = 8;
17260bde3a95SAlex Deucher 		adev->gfx.config.max_sh_per_se = 1;
17270bde3a95SAlex Deucher 		adev->gfx.config.max_backends_per_se = 2;
17280bde3a95SAlex Deucher 		adev->gfx.config.max_texture_channel_caches = 8;
17290bde3a95SAlex Deucher 		adev->gfx.config.max_gprs = 256;
17300bde3a95SAlex Deucher 		adev->gfx.config.max_gs_threads = 32;
17310bde3a95SAlex Deucher 		adev->gfx.config.max_hw_contexts = 8;
17320bde3a95SAlex Deucher 
17330bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
17340bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
17350bde3a95SAlex Deucher 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
17360bde3a95SAlex Deucher 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
17370bde3a95SAlex Deucher 		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
17380bde3a95SAlex Deucher 		break;
17390bde3a95SAlex Deucher 	case CHIP_CARRIZO:
17400bde3a95SAlex Deucher 		adev->gfx.config.max_shader_engines = 1;
17410bde3a95SAlex Deucher 		adev->gfx.config.max_tile_pipes = 2;
17420bde3a95SAlex Deucher 		adev->gfx.config.max_sh_per_se = 1;
17430bde3a95SAlex Deucher 		adev->gfx.config.max_backends_per_se = 2;
17440bde3a95SAlex Deucher 		adev->gfx.config.max_cu_per_sh = 8;
17450bde3a95SAlex Deucher 		adev->gfx.config.max_texture_channel_caches = 2;
17460bde3a95SAlex Deucher 		adev->gfx.config.max_gprs = 256;
17470bde3a95SAlex Deucher 		adev->gfx.config.max_gs_threads = 32;
17480bde3a95SAlex Deucher 		adev->gfx.config.max_hw_contexts = 8;
17490bde3a95SAlex Deucher 
17500bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
17510bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
17520bde3a95SAlex Deucher 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
17530bde3a95SAlex Deucher 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
17540bde3a95SAlex Deucher 		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
17550bde3a95SAlex Deucher 		break;
1756e3c7656cSSamuel Li 	case CHIP_STONEY:
1757e3c7656cSSamuel Li 		adev->gfx.config.max_shader_engines = 1;
1758e3c7656cSSamuel Li 		adev->gfx.config.max_tile_pipes = 2;
1759e3c7656cSSamuel Li 		adev->gfx.config.max_sh_per_se = 1;
1760e3c7656cSSamuel Li 		adev->gfx.config.max_backends_per_se = 1;
1761e3c7656cSSamuel Li 		adev->gfx.config.max_cu_per_sh = 3;
1762e3c7656cSSamuel Li 		adev->gfx.config.max_texture_channel_caches = 2;
1763e3c7656cSSamuel Li 		adev->gfx.config.max_gprs = 256;
1764e3c7656cSSamuel Li 		adev->gfx.config.max_gs_threads = 16;
1765e3c7656cSSamuel Li 		adev->gfx.config.max_hw_contexts = 8;
1766e3c7656cSSamuel Li 
1767e3c7656cSSamuel Li 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1768e3c7656cSSamuel Li 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1769e3c7656cSSamuel Li 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1770e3c7656cSSamuel Li 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1771e3c7656cSSamuel Li 		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
1772e3c7656cSSamuel Li 		break;
17730bde3a95SAlex Deucher 	default:
17740bde3a95SAlex Deucher 		adev->gfx.config.max_shader_engines = 2;
17750bde3a95SAlex Deucher 		adev->gfx.config.max_tile_pipes = 4;
17760bde3a95SAlex Deucher 		adev->gfx.config.max_cu_per_sh = 2;
17770bde3a95SAlex Deucher 		adev->gfx.config.max_sh_per_se = 1;
17780bde3a95SAlex Deucher 		adev->gfx.config.max_backends_per_se = 2;
17790bde3a95SAlex Deucher 		adev->gfx.config.max_texture_channel_caches = 4;
17800bde3a95SAlex Deucher 		adev->gfx.config.max_gprs = 256;
17810bde3a95SAlex Deucher 		adev->gfx.config.max_gs_threads = 32;
17820bde3a95SAlex Deucher 		adev->gfx.config.max_hw_contexts = 8;
17830bde3a95SAlex Deucher 
17840bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
17850bde3a95SAlex Deucher 		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
17860bde3a95SAlex Deucher 		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
17870bde3a95SAlex Deucher 		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
17880bde3a95SAlex Deucher 		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
17890bde3a95SAlex Deucher 		break;
17900bde3a95SAlex Deucher 	}
17910bde3a95SAlex Deucher 
17920bde3a95SAlex Deucher 	adev->gfx.config.mc_arb_ramcfg = RREG32(mmMC_ARB_RAMCFG);
17930bde3a95SAlex Deucher 	mc_arb_ramcfg = adev->gfx.config.mc_arb_ramcfg;
17940bde3a95SAlex Deucher 
179594b5c215SYong Zhao 	adev->gfx.config.num_banks = REG_GET_FIELD(mc_arb_ramcfg,
179694b5c215SYong Zhao 				MC_ARB_RAMCFG, NOOFBANK);
179794b5c215SYong Zhao 	adev->gfx.config.num_ranks = REG_GET_FIELD(mc_arb_ramcfg,
179894b5c215SYong Zhao 				MC_ARB_RAMCFG, NOOFRANKS);
179994b5c215SYong Zhao 
18000bde3a95SAlex Deucher 	adev->gfx.config.num_tile_pipes = adev->gfx.config.max_tile_pipes;
18010bde3a95SAlex Deucher 	adev->gfx.config.mem_max_burst_length_bytes = 256;
18020bde3a95SAlex Deucher 	if (adev->flags & AMD_IS_APU) {
18030bde3a95SAlex Deucher 		/* Get memory bank mapping mode. */
18040bde3a95SAlex Deucher 		tmp = RREG32(mmMC_FUS_DRAM0_BANK_ADDR_MAPPING);
18050bde3a95SAlex Deucher 		dimm00_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
18060bde3a95SAlex Deucher 		dimm01_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
18070bde3a95SAlex Deucher 
18080bde3a95SAlex Deucher 		tmp = RREG32(mmMC_FUS_DRAM1_BANK_ADDR_MAPPING);
18090bde3a95SAlex Deucher 		dimm10_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
18100bde3a95SAlex Deucher 		dimm11_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
18110bde3a95SAlex Deucher 
18120bde3a95SAlex Deucher 		/* Validate settings in case only one DIMM installed. */
18130bde3a95SAlex Deucher 		if ((dimm00_addr_map == 0) || (dimm00_addr_map == 3) || (dimm00_addr_map == 4) || (dimm00_addr_map > 12))
18140bde3a95SAlex Deucher 			dimm00_addr_map = 0;
18150bde3a95SAlex Deucher 		if ((dimm01_addr_map == 0) || (dimm01_addr_map == 3) || (dimm01_addr_map == 4) || (dimm01_addr_map > 12))
18160bde3a95SAlex Deucher 			dimm01_addr_map = 0;
18170bde3a95SAlex Deucher 		if ((dimm10_addr_map == 0) || (dimm10_addr_map == 3) || (dimm10_addr_map == 4) || (dimm10_addr_map > 12))
18180bde3a95SAlex Deucher 			dimm10_addr_map = 0;
18190bde3a95SAlex Deucher 		if ((dimm11_addr_map == 0) || (dimm11_addr_map == 3) || (dimm11_addr_map == 4) || (dimm11_addr_map > 12))
18200bde3a95SAlex Deucher 			dimm11_addr_map = 0;
18210bde3a95SAlex Deucher 
18220bde3a95SAlex Deucher 		/* If DIMM Addr map is 8GB, ROW size should be 2KB. Otherwise 1KB. */
18230bde3a95SAlex Deucher 		/* If ROW size(DIMM1) != ROW size(DMIMM0), ROW size should be larger one. */
18240bde3a95SAlex Deucher 		if ((dimm00_addr_map == 11) || (dimm01_addr_map == 11) || (dimm10_addr_map == 11) || (dimm11_addr_map == 11))
18250bde3a95SAlex Deucher 			adev->gfx.config.mem_row_size_in_kb = 2;
18260bde3a95SAlex Deucher 		else
18270bde3a95SAlex Deucher 			adev->gfx.config.mem_row_size_in_kb = 1;
18280bde3a95SAlex Deucher 	} else {
18290bde3a95SAlex Deucher 		tmp = REG_GET_FIELD(mc_arb_ramcfg, MC_ARB_RAMCFG, NOOFCOLS);
18300bde3a95SAlex Deucher 		adev->gfx.config.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
18310bde3a95SAlex Deucher 		if (adev->gfx.config.mem_row_size_in_kb > 4)
18320bde3a95SAlex Deucher 			adev->gfx.config.mem_row_size_in_kb = 4;
18330bde3a95SAlex Deucher 	}
18340bde3a95SAlex Deucher 
18350bde3a95SAlex Deucher 	adev->gfx.config.shader_engine_tile_size = 32;
18360bde3a95SAlex Deucher 	adev->gfx.config.num_gpus = 1;
18370bde3a95SAlex Deucher 	adev->gfx.config.multi_gpu_tile_size = 64;
18380bde3a95SAlex Deucher 
18390bde3a95SAlex Deucher 	/* fix up row size */
18400bde3a95SAlex Deucher 	switch (adev->gfx.config.mem_row_size_in_kb) {
18410bde3a95SAlex Deucher 	case 1:
18420bde3a95SAlex Deucher 	default:
18430bde3a95SAlex Deucher 		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 0);
18440bde3a95SAlex Deucher 		break;
18450bde3a95SAlex Deucher 	case 2:
18460bde3a95SAlex Deucher 		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 1);
18470bde3a95SAlex Deucher 		break;
18480bde3a95SAlex Deucher 	case 4:
18490bde3a95SAlex Deucher 		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 2);
18500bde3a95SAlex Deucher 		break;
18510bde3a95SAlex Deucher 	}
18520bde3a95SAlex Deucher 	adev->gfx.config.gb_addr_config = gb_addr_config;
185368182d90SFlora Cui 
185468182d90SFlora Cui 	return 0;
18550bde3a95SAlex Deucher }
18560bde3a95SAlex Deucher 
gfx_v8_0_compute_ring_init(struct amdgpu_device * adev,int ring_id,int mec,int pipe,int queue)1857e33fec48SAndres Rodriguez static int gfx_v8_0_compute_ring_init(struct amdgpu_device *adev, int ring_id,
1858e33fec48SAndres Rodriguez 					int mec, int pipe, int queue)
1859e33fec48SAndres Rodriguez {
1860e33fec48SAndres Rodriguez 	int r;
1861e33fec48SAndres Rodriguez 	unsigned irq_type;
1862e33fec48SAndres Rodriguez 	struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
18631c6d567bSNirmoy Das 	unsigned int hw_prio;
1864e33fec48SAndres Rodriguez 
1865e33fec48SAndres Rodriguez 	ring = &adev->gfx.compute_ring[ring_id];
1866e33fec48SAndres Rodriguez 
1867e33fec48SAndres Rodriguez 	/* mec0 is me1 */
1868e33fec48SAndres Rodriguez 	ring->me = mec + 1;
1869e33fec48SAndres Rodriguez 	ring->pipe = pipe;
1870e33fec48SAndres Rodriguez 	ring->queue = queue;
1871e33fec48SAndres Rodriguez 
1872e33fec48SAndres Rodriguez 	ring->ring_obj = NULL;
1873e33fec48SAndres Rodriguez 	ring->use_doorbell = true;
18749564f192SOak Zeng 	ring->doorbell_index = adev->doorbell_index.mec_ring0 + ring_id;
1875e33fec48SAndres Rodriguez 	ring->eop_gpu_addr = adev->gfx.mec.hpd_eop_gpu_addr
1876e33fec48SAndres Rodriguez 				+ (ring_id * GFX8_MEC_HPD_SIZE);
1877e33fec48SAndres Rodriguez 	sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
1878e33fec48SAndres Rodriguez 
1879e33fec48SAndres Rodriguez 	irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP
1880e33fec48SAndres Rodriguez 		+ ((ring->me - 1) * adev->gfx.mec.num_pipe_per_mec)
1881e33fec48SAndres Rodriguez 		+ ring->pipe;
1882e33fec48SAndres Rodriguez 
18838c0225d7SNirmoy Das 	hw_prio = amdgpu_gfx_is_high_priority_compute_queue(adev, ring) ?
18846f90a49bSGrigory Vasilyev 			AMDGPU_RING_PRIO_2 : AMDGPU_RING_PRIO_DEFAULT;
1885e33fec48SAndres Rodriguez 	/* type-2 packets are deprecated on MEC, use type-3 instead */
1886c107171bSChristian König 	r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq, irq_type,
1887c107171bSChristian König 			     hw_prio, NULL);
1888e33fec48SAndres Rodriguez 	if (r)
1889e33fec48SAndres Rodriguez 		return r;
1890e33fec48SAndres Rodriguez 
1891e33fec48SAndres Rodriguez 
1892e33fec48SAndres Rodriguez 	return 0;
1893e33fec48SAndres Rodriguez }
1894e33fec48SAndres Rodriguez 
18959bdc2092SAndrey Grodzovsky static void gfx_v8_0_sq_irq_work_func(struct work_struct *work);
18969bdc2092SAndrey Grodzovsky 
gfx_v8_0_sw_init(void * handle)18975fc3aeebSyanyang1 static int gfx_v8_0_sw_init(void *handle)
1898aaa36a97SAlex Deucher {
1899e33fec48SAndres Rodriguez 	int i, j, k, r, ring_id;
19004acd31e6SMa Jun 	int xcc_id = 0;
1901aaa36a97SAlex Deucher 	struct amdgpu_ring *ring;
19025fc3aeebSyanyang1 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1903aaa36a97SAlex Deucher 
19044853bbb6SAlex Deucher 	switch (adev->asic_type) {
19054853bbb6SAlex Deucher 	case CHIP_TONGA:
190671765469SLeo Liu 	case CHIP_CARRIZO:
190771765469SLeo Liu 	case CHIP_FIJI:
190871765469SLeo Liu 	case CHIP_POLARIS10:
19094853bbb6SAlex Deucher 	case CHIP_POLARIS11:
19104853bbb6SAlex Deucher 	case CHIP_POLARIS12:
191171765469SLeo Liu 	case CHIP_VEGAM:
19124853bbb6SAlex Deucher 		adev->gfx.mec.num_mec = 2;
19134853bbb6SAlex Deucher 		break;
19144853bbb6SAlex Deucher 	case CHIP_TOPAZ:
19154853bbb6SAlex Deucher 	case CHIP_STONEY:
19164853bbb6SAlex Deucher 	default:
19174853bbb6SAlex Deucher 		adev->gfx.mec.num_mec = 1;
19184853bbb6SAlex Deucher 		break;
19194853bbb6SAlex Deucher 	}
19204853bbb6SAlex Deucher 
19214853bbb6SAlex Deucher 	adev->gfx.mec.num_pipe_per_mec = 4;
19224853bbb6SAlex Deucher 	adev->gfx.mec.num_queue_per_pipe = 8;
19234853bbb6SAlex Deucher 
1924aaa36a97SAlex Deucher 	/* EOP Event */
19251ffdeca6SChristian König 	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_END_OF_PIPE, &adev->gfx.eop_irq);
1926aaa36a97SAlex Deucher 	if (r)
1927aaa36a97SAlex Deucher 		return r;
1928aaa36a97SAlex Deucher 
1929aaa36a97SAlex Deucher 	/* Privileged reg */
19301ffdeca6SChristian König 	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_PRIV_REG_FAULT,
1931d766e6a3SAlex Deucher 			      &adev->gfx.priv_reg_irq);
1932aaa36a97SAlex Deucher 	if (r)
1933aaa36a97SAlex Deucher 		return r;
1934aaa36a97SAlex Deucher 
1935aaa36a97SAlex Deucher 	/* Privileged inst */
19361ffdeca6SChristian König 	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_PRIV_INSTR_FAULT,
1937d766e6a3SAlex Deucher 			      &adev->gfx.priv_inst_irq);
1938aaa36a97SAlex Deucher 	if (r)
1939aaa36a97SAlex Deucher 		return r;
1940aaa36a97SAlex Deucher 
19415a2f2913SDavid Panariti 	/* Add CP EDC/ECC irq  */
19421ffdeca6SChristian König 	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_ECC_ERROR,
19435a2f2913SDavid Panariti 			      &adev->gfx.cp_ecc_error_irq);
19445a2f2913SDavid Panariti 	if (r)
19455a2f2913SDavid Panariti 		return r;
19465a2f2913SDavid Panariti 
194704ad26bbSDavid Panariti 	/* SQ interrupts. */
19481ffdeca6SChristian König 	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_SQ_INTERRUPT_MSG,
194904ad26bbSDavid Panariti 			      &adev->gfx.sq_irq);
195004ad26bbSDavid Panariti 	if (r) {
195104ad26bbSDavid Panariti 		DRM_ERROR("amdgpu_irq_add() for SQ failed: %d\n", r);
195204ad26bbSDavid Panariti 		return r;
195304ad26bbSDavid Panariti 	}
195404ad26bbSDavid Panariti 
19559bdc2092SAndrey Grodzovsky 	INIT_WORK(&adev->gfx.sq_work.work, gfx_v8_0_sq_irq_work_func);
19569bdc2092SAndrey Grodzovsky 
1957aaa36a97SAlex Deucher 	adev->gfx.gfx_current_status = AMDGPU_GFX_NORMAL_MODE;
1958aaa36a97SAlex Deucher 
1959aaa36a97SAlex Deucher 	r = gfx_v8_0_init_microcode(adev);
1960aaa36a97SAlex Deucher 	if (r) {
1961aaa36a97SAlex Deucher 		DRM_ERROR("Failed to load gfx firmware!\n");
1962aaa36a97SAlex Deucher 		return r;
1963aaa36a97SAlex Deucher 	}
1964aaa36a97SAlex Deucher 
1965fdb81fd7SLikun Gao 	r = adev->gfx.rlc.funcs->init(adev);
19662b6cd977SEric Huang 	if (r) {
19672b6cd977SEric Huang 		DRM_ERROR("Failed to init rlc BOs!\n");
19682b6cd977SEric Huang 		return r;
19692b6cd977SEric Huang 	}
19702b6cd977SEric Huang 
1971aaa36a97SAlex Deucher 	r = gfx_v8_0_mec_init(adev);
1972aaa36a97SAlex Deucher 	if (r) {
1973aaa36a97SAlex Deucher 		DRM_ERROR("Failed to init MEC BOs!\n");
1974aaa36a97SAlex Deucher 		return r;
1975aaa36a97SAlex Deucher 	}
1976aaa36a97SAlex Deucher 
1977aaa36a97SAlex Deucher 	/* set up the gfx ring */
1978aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
1979aaa36a97SAlex Deucher 		ring = &adev->gfx.gfx_ring[i];
1980aaa36a97SAlex Deucher 		ring->ring_obj = NULL;
1981aaa36a97SAlex Deucher 		sprintf(ring->name, "gfx");
1982aaa36a97SAlex Deucher 		/* no gfx doorbells on iceland */
1983aaa36a97SAlex Deucher 		if (adev->asic_type != CHIP_TOPAZ) {
1984aaa36a97SAlex Deucher 			ring->use_doorbell = true;
19859564f192SOak Zeng 			ring->doorbell_index = adev->doorbell_index.gfx_ring0;
1986aaa36a97SAlex Deucher 		}
1987aaa36a97SAlex Deucher 
198879887142SChristian König 		r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq,
19891c6d567bSNirmoy Das 				     AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP,
1990c107171bSChristian König 				     AMDGPU_RING_PRIO_DEFAULT, NULL);
1991aaa36a97SAlex Deucher 		if (r)
1992aaa36a97SAlex Deucher 			return r;
1993aaa36a97SAlex Deucher 	}
1994aaa36a97SAlex Deucher 
1995aaa36a97SAlex Deucher 
1996e33fec48SAndres Rodriguez 	/* set up the compute queues - allocate horizontally across pipes */
1997e33fec48SAndres Rodriguez 	ring_id = 0;
1998e33fec48SAndres Rodriguez 	for (i = 0; i < adev->gfx.mec.num_mec; ++i) {
1999e33fec48SAndres Rodriguez 		for (j = 0; j < adev->gfx.mec.num_queue_per_pipe; j++) {
2000e33fec48SAndres Rodriguez 			for (k = 0; k < adev->gfx.mec.num_pipe_per_mec; k++) {
2001be697aa3SLe Ma 				if (!amdgpu_gfx_is_mec_queue_enabled(adev, 0, i,
2002be697aa3SLe Ma 								     k, j))
200378c16834SAndres Rodriguez 					continue;
200478c16834SAndres Rodriguez 
2005e33fec48SAndres Rodriguez 				r = gfx_v8_0_compute_ring_init(adev,
2006e33fec48SAndres Rodriguez 								ring_id,
2007e33fec48SAndres Rodriguez 								i, k, j);
2008aaa36a97SAlex Deucher 				if (r)
2009aaa36a97SAlex Deucher 					return r;
201078c16834SAndres Rodriguez 
201178c16834SAndres Rodriguez 				ring_id++;
2012aaa36a97SAlex Deucher 			}
2013e33fec48SAndres Rodriguez 		}
2014aaa36a97SAlex Deucher 	}
2015aaa36a97SAlex Deucher 
2016def799c6SLe Ma 	r = amdgpu_gfx_kiq_init(adev, GFX8_MEC_HPD_SIZE, 0);
2017596c67d0SMonk Liu 	if (r) {
2018596c67d0SMonk Liu 		DRM_ERROR("Failed to init KIQ BOs!\n");
2019596c67d0SMonk Liu 		return r;
2020596c67d0SMonk Liu 	}
2021596c67d0SMonk Liu 
20224acd31e6SMa Jun 	r = amdgpu_gfx_kiq_init_ring(adev, xcc_id);
2023596c67d0SMonk Liu 	if (r)
2024596c67d0SMonk Liu 		return r;
2025596c67d0SMonk Liu 
2026b4e40676SDavid Panariti 	/* create MQD for all compute queues as well as KIQ for SRIOV case */
2027def799c6SLe Ma 	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct vi_mqd_allocation), 0);
2028596c67d0SMonk Liu 	if (r)
2029596c67d0SMonk Liu 		return r;
2030596c67d0SMonk Liu 
2031a101a899SKen Wang 	adev->gfx.ce_ram_size = 0x8000;
2032a101a899SKen Wang 
203368182d90SFlora Cui 	r = gfx_v8_0_gpu_early_init(adev);
203468182d90SFlora Cui 	if (r)
203568182d90SFlora Cui 		return r;
20360bde3a95SAlex Deucher 
2037aaa36a97SAlex Deucher 	return 0;
2038aaa36a97SAlex Deucher }
2039aaa36a97SAlex Deucher 
gfx_v8_0_sw_fini(void * handle)20405fc3aeebSyanyang1 static int gfx_v8_0_sw_fini(void *handle)
2041aaa36a97SAlex Deucher {
20425fc3aeebSyanyang1 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2043dca29491SChristian König 	int i;
2044aaa36a97SAlex Deucher 
2045aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
2046aaa36a97SAlex Deucher 		amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
2047aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.num_compute_rings; i++)
2048aaa36a97SAlex Deucher 		amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
2049aaa36a97SAlex Deucher 
2050def799c6SLe Ma 	amdgpu_gfx_mqd_sw_fini(adev, 0);
2051277bd337SLe Ma 	amdgpu_gfx_kiq_free_ring(&adev->gfx.kiq[0].ring);
2052def799c6SLe Ma 	amdgpu_gfx_kiq_fini(adev, 0);
2053596c67d0SMonk Liu 
2054aaa36a97SAlex Deucher 	gfx_v8_0_mec_fini(adev);
205588dfc9a3SLikun Gao 	amdgpu_gfx_rlc_fini(adev);
20569862def9SMonk Liu 	amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj,
20579862def9SMonk Liu 				&adev->gfx.rlc.clear_state_gpu_addr,
20589862def9SMonk Liu 				(void **)&adev->gfx.rlc.cs_ptr);
20599862def9SMonk Liu 	if ((adev->asic_type == CHIP_CARRIZO) ||
20609862def9SMonk Liu 	    (adev->asic_type == CHIP_STONEY)) {
20619862def9SMonk Liu 		amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj,
20629862def9SMonk Liu 				&adev->gfx.rlc.cp_table_gpu_addr,
20639862def9SMonk Liu 				(void **)&adev->gfx.rlc.cp_table_ptr);
20649862def9SMonk Liu 	}
206513331ac3SMonk Liu 	gfx_v8_0_free_microcode(adev);
20662b6cd977SEric Huang 
2067aaa36a97SAlex Deucher 	return 0;
2068aaa36a97SAlex Deucher }
2069aaa36a97SAlex Deucher 
gfx_v8_0_tiling_mode_table_init(struct amdgpu_device * adev)2070aaa36a97SAlex Deucher static void gfx_v8_0_tiling_mode_table_init(struct amdgpu_device *adev)
2071aaa36a97SAlex Deucher {
207290bea0abSTom St Denis 	uint32_t *modearray, *mod2array;
2073eb64526fSTom St Denis 	const u32 num_tile_mode_states = ARRAY_SIZE(adev->gfx.config.tile_mode_array);
2074eb64526fSTom St Denis 	const u32 num_secondary_tile_mode_states = ARRAY_SIZE(adev->gfx.config.macrotile_mode_array);
207590bea0abSTom St Denis 	u32 reg_offset;
2076aaa36a97SAlex Deucher 
207790bea0abSTom St Denis 	modearray = adev->gfx.config.tile_mode_array;
207890bea0abSTom St Denis 	mod2array = adev->gfx.config.macrotile_mode_array;
207990bea0abSTom St Denis 
208090bea0abSTom St Denis 	for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
208190bea0abSTom St Denis 		modearray[reg_offset] = 0;
208290bea0abSTom St Denis 
208390bea0abSTom St Denis 	for (reg_offset = 0; reg_offset <  num_secondary_tile_mode_states; reg_offset++)
208490bea0abSTom St Denis 		mod2array[reg_offset] = 0;
2085aaa36a97SAlex Deucher 
2086aaa36a97SAlex Deucher 	switch (adev->asic_type) {
2087aaa36a97SAlex Deucher 	case CHIP_TOPAZ:
208890bea0abSTom St Denis 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2089aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2090aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2091aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
209290bea0abSTom St Denis 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2093aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2094aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2095aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
209690bea0abSTom St Denis 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2097aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2098aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2099aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
210090bea0abSTom St Denis 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2101aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2102aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2103aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
210490bea0abSTom St Denis 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2105aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2106aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2107aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
210890bea0abSTom St Denis 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2109aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2110aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2111aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
211290bea0abSTom St Denis 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2113aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2114aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2115aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
211690bea0abSTom St Denis 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2117aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2));
211890bea0abSTom St Denis 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2119aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
2120aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2121aaa36a97SAlex Deucher 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
212290bea0abSTom St Denis 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2123aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2124aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2125aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
212690bea0abSTom St Denis 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2127aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2128aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2129aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
213090bea0abSTom St Denis 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2131aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2132aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2133aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
213490bea0abSTom St Denis 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2135aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2136aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2137aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
213890bea0abSTom St Denis 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2139aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2140aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2141aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
214290bea0abSTom St Denis 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2143aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2144aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2145aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
214690bea0abSTom St Denis 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2147aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2148aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2149aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
215090bea0abSTom St Denis 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2151aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2152aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2153aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
215490bea0abSTom St Denis 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2155aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2156aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2157aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
215890bea0abSTom St Denis 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2159aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2160aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2161aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
216290bea0abSTom St Denis 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2163aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2164aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2165aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
216690bea0abSTom St Denis 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2167aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2168aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2169aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
217090bea0abSTom St Denis 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2171aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2172aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2173aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
217490bea0abSTom St Denis 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2175aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2176aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2177aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
217890bea0abSTom St Denis 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2179aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2180aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2181aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
218290bea0abSTom St Denis 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2183aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2184aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2185aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
218690bea0abSTom St Denis 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2187aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
2188aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2189aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
219090bea0abSTom St Denis 
219190bea0abSTom St Denis 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2192aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2193aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2194aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
219590bea0abSTom St Denis 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2196aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2197aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2198aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
219990bea0abSTom St Denis 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2200aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2201aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2202aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
220390bea0abSTom St Denis 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2204aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2205aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2206aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
220790bea0abSTom St Denis 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2208aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2209aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2210aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
221190bea0abSTom St Denis 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2212aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2213aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2214aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
221590bea0abSTom St Denis 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2216aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2217aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2218aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
221990bea0abSTom St Denis 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2220aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2221aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2222aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
222390bea0abSTom St Denis 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2224aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2225aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2226aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
222790bea0abSTom St Denis 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2228aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2229aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2230aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
223190bea0abSTom St Denis 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2232aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2233aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2234aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
223590bea0abSTom St Denis 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2236aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2237aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2238aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
223990bea0abSTom St Denis 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2240aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2241aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2242aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
224390bea0abSTom St Denis 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2244aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2245aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2246aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_8_BANK));
224790bea0abSTom St Denis 
224890bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
224990bea0abSTom St Denis 			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
225090bea0abSTom St Denis 			    reg_offset != 23)
225190bea0abSTom St Denis 				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
225290bea0abSTom St Denis 
225390bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
225490bea0abSTom St Denis 			if (reg_offset != 7)
225590bea0abSTom St Denis 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
225690bea0abSTom St Denis 
22578cdacf44STom St Denis 		break;
2258af15a2d5SDavid Zhang 	case CHIP_FIJI:
225971765469SLeo Liu 	case CHIP_VEGAM:
226090bea0abSTom St Denis 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22615f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22625f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
22635f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
226490bea0abSTom St Denis 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22655f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22665f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
22675f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
226890bea0abSTom St Denis 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22695f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22705f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
22715f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
227290bea0abSTom St Denis 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22735f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22745f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
22755f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
227690bea0abSTom St Denis 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22775f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22785f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
22795f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
228090bea0abSTom St Denis 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
22815f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22825f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
22835f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
228490bea0abSTom St Denis 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
22855f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22865f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
22875f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
228890bea0abSTom St Denis 		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
22895f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
22905f2e816bSFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
22915f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
229290bea0abSTom St Denis 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
22935f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
229490bea0abSTom St Denis 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
22955f2e816bSFlora Cui 				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
22965f2e816bSFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
22975f2e816bSFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
229890bea0abSTom St Denis 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
22995f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23005f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
23015f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
230290bea0abSTom St Denis 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23035f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23045f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
23055f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
230690bea0abSTom St Denis 		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23075f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
23085f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
23095f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
231090bea0abSTom St Denis 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
23115f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23125f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23135f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
231490bea0abSTom St Denis 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
23155f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23165f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23175f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
231890bea0abSTom St Denis 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
23195f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23205f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23215f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
232290bea0abSTom St Denis 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23235f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23245f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23255f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
232690bea0abSTom St Denis 		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23275f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
23285f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23295f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
233090bea0abSTom St Denis 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
23315f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23325f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23335f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
233490bea0abSTom St Denis 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
23355f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23365f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23375f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
233890bea0abSTom St Denis 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
23395f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23405f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23415f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
234290bea0abSTom St Denis 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
23435f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23445f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23455f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
234690bea0abSTom St Denis 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
23475f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23485f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23495f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
235090bea0abSTom St Denis 		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
23515f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
23525f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23535f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
235490bea0abSTom St Denis 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
23555f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23565f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
23575f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
235890bea0abSTom St Denis 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
23595f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23605f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23615f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
236290bea0abSTom St Denis 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
23635f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23645f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
23655f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
236690bea0abSTom St Denis 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
23675f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23685f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
23695f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
237090bea0abSTom St Denis 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
23715f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23725f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
23735f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
237490bea0abSTom St Denis 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23755f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
23765f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
23775f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
237890bea0abSTom St Denis 		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
23795f2e816bSFlora Cui 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
23805f2e816bSFlora Cui 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
23815f2e816bSFlora Cui 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
238290bea0abSTom St Denis 
238390bea0abSTom St Denis 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
23845f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
23855f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
23865f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
238790bea0abSTom St Denis 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
23885f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
23895f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
23905f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
239190bea0abSTom St Denis 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
23925f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
23935f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
23945f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
239590bea0abSTom St Denis 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
23965f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
23975f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
23985f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
239990bea0abSTom St Denis 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24005f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
24015f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24025f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
240390bea0abSTom St Denis 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24045f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
24055f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24065f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
240790bea0abSTom St Denis 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24085f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
24095f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24105f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
241190bea0abSTom St Denis 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24125f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
24135f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
24145f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
241590bea0abSTom St Denis 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24165f2e816bSFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
24175f2e816bSFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
24185f2e816bSFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
241990bea0abSTom St Denis 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24205f2e816bSFlora Cui 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
24215f2e816bSFlora Cui 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24225f2e816bSFlora Cui 				 NUM_BANKS(ADDR_SURF_8_BANK));
242390bea0abSTom St Denis 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24245f2e816bSFlora Cui 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
24255f2e816bSFlora Cui 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24265f2e816bSFlora Cui 				 NUM_BANKS(ADDR_SURF_8_BANK));
242790bea0abSTom St Denis 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24285f2e816bSFlora Cui 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
24295f2e816bSFlora Cui 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
24305f2e816bSFlora Cui 				 NUM_BANKS(ADDR_SURF_8_BANK));
243190bea0abSTom St Denis 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24325f2e816bSFlora Cui 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
24335f2e816bSFlora Cui 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
24345f2e816bSFlora Cui 				 NUM_BANKS(ADDR_SURF_8_BANK));
243590bea0abSTom St Denis 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
24365f2e816bSFlora Cui 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
24375f2e816bSFlora Cui 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
24385f2e816bSFlora Cui 				 NUM_BANKS(ADDR_SURF_4_BANK));
243990bea0abSTom St Denis 
244090bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
244190bea0abSTom St Denis 			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
244290bea0abSTom St Denis 
244390bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
244490bea0abSTom St Denis 			if (reg_offset != 7)
244590bea0abSTom St Denis 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
244690bea0abSTom St Denis 
24475f2e816bSFlora Cui 		break;
2448aaa36a97SAlex Deucher 	case CHIP_TONGA:
244990bea0abSTom St Denis 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2450aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2451aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2452aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
245390bea0abSTom St Denis 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2454aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2455aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2456aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
245790bea0abSTom St Denis 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2458aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2459aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2460aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
246190bea0abSTom St Denis 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2462aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2463aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2464aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
246590bea0abSTom St Denis 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2466aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2467aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2468aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
246990bea0abSTom St Denis 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2470aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2471aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2472aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
247390bea0abSTom St Denis 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2474aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2475aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2476aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
247790bea0abSTom St Denis 		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2478aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2479aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2480aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
248190bea0abSTom St Denis 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2482aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
248390bea0abSTom St Denis 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2484aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2485aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2486aaa36a97SAlex Deucher 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
248790bea0abSTom St Denis 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2488aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2489aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2490aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
249190bea0abSTom St Denis 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2492aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2493aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2494aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
249590bea0abSTom St Denis 		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2496aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2497aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2498aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
249990bea0abSTom St Denis 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2500aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2501aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2502aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
250390bea0abSTom St Denis 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2504aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2505aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2506aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
250790bea0abSTom St Denis 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2508aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2509aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2510aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
251190bea0abSTom St Denis 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2512aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2513aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2514aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
251590bea0abSTom St Denis 		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2516aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2517aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2518aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
251990bea0abSTom St Denis 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2520aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2521aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2522aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
252390bea0abSTom St Denis 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2524aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2525aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2526aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
252790bea0abSTom St Denis 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2528aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2529aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2530aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
253190bea0abSTom St Denis 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2532aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2533aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2534aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
253590bea0abSTom St Denis 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2536aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2537aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2538aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
253990bea0abSTom St Denis 		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2540aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2541aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2542aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
254390bea0abSTom St Denis 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2544aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2545aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2546aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
254790bea0abSTom St Denis 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2548aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2549aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2550aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
255190bea0abSTom St Denis 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2552aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2553aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2554aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
255590bea0abSTom St Denis 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2556aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2557aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2558aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
255990bea0abSTom St Denis 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2560aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2561aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2562aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
256390bea0abSTom St Denis 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2564aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2565aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2566aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
256790bea0abSTom St Denis 		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2568aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2569aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2570aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
257190bea0abSTom St Denis 
257290bea0abSTom St Denis 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2573aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2574aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2575aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
257690bea0abSTom St Denis 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2577aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2578aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2579aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
258090bea0abSTom St Denis 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2581aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2582aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2583aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
258490bea0abSTom St Denis 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2585aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2586aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2587aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
258890bea0abSTom St Denis 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2589aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2590aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2591aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
259290bea0abSTom St Denis 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2593aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2594aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2595aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
259690bea0abSTom St Denis 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2597aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2598aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2599aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
260090bea0abSTom St Denis 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2601aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2602aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2603aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
260490bea0abSTom St Denis 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2605aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2606aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2607aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
260890bea0abSTom St Denis 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2609aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2610aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2611aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
261290bea0abSTom St Denis 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2613aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2614aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2615aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
261690bea0abSTom St Denis 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2617aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2618aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2619aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_8_BANK));
262090bea0abSTom St Denis 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2621aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2622aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2623aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_4_BANK));
262490bea0abSTom St Denis 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2625aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2626aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2627aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_4_BANK));
262890bea0abSTom St Denis 
262990bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
263090bea0abSTom St Denis 			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
263190bea0abSTom St Denis 
263290bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
263390bea0abSTom St Denis 			if (reg_offset != 7)
263490bea0abSTom St Denis 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
263590bea0abSTom St Denis 
2636aaa36a97SAlex Deucher 		break;
26372cc0c0b5SFlora Cui 	case CHIP_POLARIS11:
2638c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
263968182d90SFlora Cui 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
264068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
264168182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
264268182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
264368182d90SFlora Cui 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
264468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
264568182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
264668182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
264768182d90SFlora Cui 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
264868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
264968182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
265068182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
265168182d90SFlora Cui 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
265268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
265368182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
265468182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
265568182d90SFlora Cui 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
265668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
265768182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
265868182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
265968182d90SFlora Cui 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
266068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
266168182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
266268182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
266368182d90SFlora Cui 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
266468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
266568182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
266668182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
266768182d90SFlora Cui 		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
266868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
266968182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
267068182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
267168182d90SFlora Cui 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
267268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16));
267368182d90SFlora Cui 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
267468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
267568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
267668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
267768182d90SFlora Cui 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
267868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
267968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
268068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
268168182d90SFlora Cui 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
268268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
268368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
268468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
268568182d90SFlora Cui 		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
268668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
268768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
268868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
268968182d90SFlora Cui 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
269068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
269168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
269268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
269368182d90SFlora Cui 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
269468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
269568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
269668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
269768182d90SFlora Cui 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
269868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
269968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
270068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
270168182d90SFlora Cui 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
270268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
270368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
270468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
270568182d90SFlora Cui 		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
270668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
270768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
270868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
270968182d90SFlora Cui 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
271068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
271168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
271268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
271368182d90SFlora Cui 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
271468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
271568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
271668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
271768182d90SFlora Cui 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
271868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
271968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
272068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
272168182d90SFlora Cui 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
272268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
272368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
272468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
272568182d90SFlora Cui 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
272668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
272768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
272868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
272968182d90SFlora Cui 		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
273068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
273168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
273268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
273368182d90SFlora Cui 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
273468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
273568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
273668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
273768182d90SFlora Cui 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
273868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
273968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
274068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
274168182d90SFlora Cui 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
274268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
274368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
274468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
274568182d90SFlora Cui 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
274668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
274768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
274868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
274968182d90SFlora Cui 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
275068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
275168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
275268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
275368182d90SFlora Cui 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
275468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
275568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
275668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
275768182d90SFlora Cui 		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
275868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
275968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
276068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
276168182d90SFlora Cui 
276268182d90SFlora Cui 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
276368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
276468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
276568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
276668182d90SFlora Cui 
276768182d90SFlora Cui 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
276868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
276968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
277068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
277168182d90SFlora Cui 
277268182d90SFlora Cui 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
277368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
277468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
277568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
277668182d90SFlora Cui 
277768182d90SFlora Cui 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
277868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
277968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
278068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
278168182d90SFlora Cui 
278268182d90SFlora Cui 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
278368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
278468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
278568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
278668182d90SFlora Cui 
278768182d90SFlora Cui 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
278868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
278968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
279068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
279168182d90SFlora Cui 
279268182d90SFlora Cui 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
279368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
279468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
279568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
279668182d90SFlora Cui 
279768182d90SFlora Cui 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
279868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
279968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
280068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
280168182d90SFlora Cui 
280268182d90SFlora Cui 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
280368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
280468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
280568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
280668182d90SFlora Cui 
280768182d90SFlora Cui 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
280868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
280968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
281068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
281168182d90SFlora Cui 
281268182d90SFlora Cui 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
281368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
281468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
281568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
281668182d90SFlora Cui 
281768182d90SFlora Cui 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
281868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
281968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
282068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
282168182d90SFlora Cui 
282268182d90SFlora Cui 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
282368182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
282468182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
282568182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
282668182d90SFlora Cui 
282768182d90SFlora Cui 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
282868182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
282968182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
283068182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_4_BANK));
283168182d90SFlora Cui 
283268182d90SFlora Cui 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
283368182d90SFlora Cui 			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
283468182d90SFlora Cui 
283568182d90SFlora Cui 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
283668182d90SFlora Cui 			if (reg_offset != 7)
283768182d90SFlora Cui 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
283868182d90SFlora Cui 
283968182d90SFlora Cui 		break;
28402cc0c0b5SFlora Cui 	case CHIP_POLARIS10:
284168182d90SFlora Cui 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
284268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
284368182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
284468182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
284568182d90SFlora Cui 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
284668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
284768182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
284868182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
284968182d90SFlora Cui 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
285068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
285168182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
285268182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
285368182d90SFlora Cui 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
285468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
285568182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
285668182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
285768182d90SFlora Cui 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
285868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
285968182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
286068182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
286168182d90SFlora Cui 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
286268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
286368182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
286468182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
286568182d90SFlora Cui 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
286668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
286768182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
286868182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
286968182d90SFlora Cui 		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
287068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
287168182d90SFlora Cui 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
287268182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
287368182d90SFlora Cui 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
287468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
287568182d90SFlora Cui 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
287668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
287768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
287868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
287968182d90SFlora Cui 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
288068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
288168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
288268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
288368182d90SFlora Cui 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
288468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
288568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
288668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
288768182d90SFlora Cui 		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
288868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
288968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
289068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
289168182d90SFlora Cui 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
289268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
289368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
289468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
289568182d90SFlora Cui 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
289668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
289768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
289868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
289968182d90SFlora Cui 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
290068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
290168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
290268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
290368182d90SFlora Cui 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
290468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
290568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
290668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
290768182d90SFlora Cui 		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
290868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
290968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
291068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
291168182d90SFlora Cui 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
291268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
291368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
291468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
291568182d90SFlora Cui 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
291668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
291768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
291868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
291968182d90SFlora Cui 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
292068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
292168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
292268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
292368182d90SFlora Cui 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
292468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
292568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
292668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
292768182d90SFlora Cui 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
292868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
292968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
293068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
293168182d90SFlora Cui 		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
293268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
293368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
293468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
293568182d90SFlora Cui 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
293668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
293768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
293868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
293968182d90SFlora Cui 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
294068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
294168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
294268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
294368182d90SFlora Cui 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
294468182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
294568182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
294668182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
294768182d90SFlora Cui 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
294868182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
294968182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
295068182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
295168182d90SFlora Cui 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
295268182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
295368182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
295468182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
295568182d90SFlora Cui 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
295668182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
295768182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
295868182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
295968182d90SFlora Cui 		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
296068182d90SFlora Cui 				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
296168182d90SFlora Cui 				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
296268182d90SFlora Cui 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
296368182d90SFlora Cui 
296468182d90SFlora Cui 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
296568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
296668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
296768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
296868182d90SFlora Cui 
296968182d90SFlora Cui 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
297068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
297168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
297268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
297368182d90SFlora Cui 
297468182d90SFlora Cui 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
297568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
297668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
297768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
297868182d90SFlora Cui 
297968182d90SFlora Cui 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
298068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
298168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
298268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
298368182d90SFlora Cui 
298468182d90SFlora Cui 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
298568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
298668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
298768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
298868182d90SFlora Cui 
298968182d90SFlora Cui 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
299068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
299168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
299268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
299368182d90SFlora Cui 
299468182d90SFlora Cui 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
299568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
299668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
299768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
299868182d90SFlora Cui 
299968182d90SFlora Cui 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
300068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
300168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
300268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
300368182d90SFlora Cui 
300468182d90SFlora Cui 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
300568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
300668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
300768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
300868182d90SFlora Cui 
300968182d90SFlora Cui 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
301068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
301168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
301268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
301368182d90SFlora Cui 
301468182d90SFlora Cui 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
301568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
301668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
301768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_16_BANK));
301868182d90SFlora Cui 
301968182d90SFlora Cui 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
302068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
302168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
302268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_8_BANK));
302368182d90SFlora Cui 
302468182d90SFlora Cui 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
302568182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
302668182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
302768182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_4_BANK));
302868182d90SFlora Cui 
302968182d90SFlora Cui 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
303068182d90SFlora Cui 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
303168182d90SFlora Cui 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
303268182d90SFlora Cui 				NUM_BANKS(ADDR_SURF_4_BANK));
303368182d90SFlora Cui 
303468182d90SFlora Cui 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
303568182d90SFlora Cui 			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
303668182d90SFlora Cui 
303768182d90SFlora Cui 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
303868182d90SFlora Cui 			if (reg_offset != 7)
303968182d90SFlora Cui 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
304068182d90SFlora Cui 
304168182d90SFlora Cui 		break;
3042e3c7656cSSamuel Li 	case CHIP_STONEY:
304390bea0abSTom St Denis 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3044e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3045e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3046e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
304790bea0abSTom St Denis 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3048e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3049e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3050e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
305190bea0abSTom St Denis 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3052e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3053e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3054e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
305590bea0abSTom St Denis 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3056e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3057e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3058e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
305990bea0abSTom St Denis 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3060e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3061e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3062e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
306390bea0abSTom St Denis 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3064e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3065e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3066e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
306790bea0abSTom St Denis 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3068e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3069e3c7656cSSamuel Li 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3070e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
307190bea0abSTom St Denis 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3072e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2));
307390bea0abSTom St Denis 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3074e3c7656cSSamuel Li 				PIPE_CONFIG(ADDR_SURF_P2) |
3075e3c7656cSSamuel Li 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3076e3c7656cSSamuel Li 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
307790bea0abSTom St Denis 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3078e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3079e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3080e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
308190bea0abSTom St Denis 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3082e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3083e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3084e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
308590bea0abSTom St Denis 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3086e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3087e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3088e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
308990bea0abSTom St Denis 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3090e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3091e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3092e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
309390bea0abSTom St Denis 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3094e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3095e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3096e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
309790bea0abSTom St Denis 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3098e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3099e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3100e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
310190bea0abSTom St Denis 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3102e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3103e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3104e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
310590bea0abSTom St Denis 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3106e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3107e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3108e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
310990bea0abSTom St Denis 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3110e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3111e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3112e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
311390bea0abSTom St Denis 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3114e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3115e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3116e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
311790bea0abSTom St Denis 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3118e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3119e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3120e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
312190bea0abSTom St Denis 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3122e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3123e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3124e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
312590bea0abSTom St Denis 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3126e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3127e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3128e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
312990bea0abSTom St Denis 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3130e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3131e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3132e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
313390bea0abSTom St Denis 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3134e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3135e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3136e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
313790bea0abSTom St Denis 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3138e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3139e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3140e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
314190bea0abSTom St Denis 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3142e3c7656cSSamuel Li 				 PIPE_CONFIG(ADDR_SURF_P2) |
3143e3c7656cSSamuel Li 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3144e3c7656cSSamuel Li 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
314590bea0abSTom St Denis 
314690bea0abSTom St Denis 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3147e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3148e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3149e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
315090bea0abSTom St Denis 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3151e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3152e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3153e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
315490bea0abSTom St Denis 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3155e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3156e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3157e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
315890bea0abSTom St Denis 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3159e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3160e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3161e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
316290bea0abSTom St Denis 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3163e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3164e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3165e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
316690bea0abSTom St Denis 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3167e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3168e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3169e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
317090bea0abSTom St Denis 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3171e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3172e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3173e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_8_BANK));
317490bea0abSTom St Denis 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3175e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3176e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3177e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_16_BANK));
317890bea0abSTom St Denis 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3179e3c7656cSSamuel Li 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3180e3c7656cSSamuel Li 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3181e3c7656cSSamuel Li 				NUM_BANKS(ADDR_SURF_16_BANK));
318290bea0abSTom St Denis 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3183e3c7656cSSamuel Li 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3184e3c7656cSSamuel Li 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3185e3c7656cSSamuel Li 				 NUM_BANKS(ADDR_SURF_16_BANK));
318690bea0abSTom St Denis 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3187e3c7656cSSamuel Li 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3188e3c7656cSSamuel Li 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3189e3c7656cSSamuel Li 				 NUM_BANKS(ADDR_SURF_16_BANK));
319090bea0abSTom St Denis 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3191e3c7656cSSamuel Li 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3192e3c7656cSSamuel Li 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3193e3c7656cSSamuel Li 				 NUM_BANKS(ADDR_SURF_16_BANK));
319490bea0abSTom St Denis 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3195e3c7656cSSamuel Li 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3196e3c7656cSSamuel Li 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3197e3c7656cSSamuel Li 				 NUM_BANKS(ADDR_SURF_16_BANK));
319890bea0abSTom St Denis 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3199e3c7656cSSamuel Li 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3200e3c7656cSSamuel Li 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3201e3c7656cSSamuel Li 				 NUM_BANKS(ADDR_SURF_8_BANK));
320290bea0abSTom St Denis 
320390bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
320490bea0abSTom St Denis 			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
320590bea0abSTom St Denis 			    reg_offset != 23)
320690bea0abSTom St Denis 				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
320790bea0abSTom St Denis 
320890bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
320990bea0abSTom St Denis 			if (reg_offset != 7)
321090bea0abSTom St Denis 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
321190bea0abSTom St Denis 
3212e3c7656cSSamuel Li 		break;
3213e3c7656cSSamuel Li 	default:
321490bea0abSTom St Denis 		dev_warn(adev->dev,
321590bea0abSTom St Denis 			 "Unknown chip type (%d) in function gfx_v8_0_tiling_mode_table_init() falling through to CHIP_CARRIZO\n",
321690bea0abSTom St Denis 			 adev->asic_type);
3217df561f66SGustavo A. R. Silva 		fallthrough;
321890bea0abSTom St Denis 
3219aaa36a97SAlex Deucher 	case CHIP_CARRIZO:
322090bea0abSTom St Denis 		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3221aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3222aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3223aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
322490bea0abSTom St Denis 		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3225aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3226aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3227aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
322890bea0abSTom St Denis 		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3229aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3230aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3231aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
323290bea0abSTom St Denis 		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3233aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3234aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3235aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
323690bea0abSTom St Denis 		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3237aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3238aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3239aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
324090bea0abSTom St Denis 		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3241aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3242aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3243aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
324490bea0abSTom St Denis 		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3245aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3246aaa36a97SAlex Deucher 				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3247aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
324890bea0abSTom St Denis 		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3249aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2));
325090bea0abSTom St Denis 		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3251aaa36a97SAlex Deucher 				PIPE_CONFIG(ADDR_SURF_P2) |
3252aaa36a97SAlex Deucher 				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3253aaa36a97SAlex Deucher 				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
325490bea0abSTom St Denis 		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3255aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3256aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3257aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
325890bea0abSTom St Denis 		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3259aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3260aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3261aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
326290bea0abSTom St Denis 		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3263aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3264aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3265aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
326690bea0abSTom St Denis 		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3267aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3268aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3269aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
327090bea0abSTom St Denis 		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3271aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3272aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3273aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
327490bea0abSTom St Denis 		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3275aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3276aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3277aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
327890bea0abSTom St Denis 		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3279aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3280aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3281aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
328290bea0abSTom St Denis 		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3283aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3284aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3285aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
328690bea0abSTom St Denis 		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3287aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3288aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3289aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
329090bea0abSTom St Denis 		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3291aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3292aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3293aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
329490bea0abSTom St Denis 		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3295aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3296aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3297aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
329890bea0abSTom St Denis 		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3299aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3300aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3301aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
330290bea0abSTom St Denis 		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3303aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3304aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3305aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
330690bea0abSTom St Denis 		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3307aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3308aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3309aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
331090bea0abSTom St Denis 		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3311aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3312aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3313aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
331490bea0abSTom St Denis 		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3315aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3316aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3317aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
331890bea0abSTom St Denis 		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3319aaa36a97SAlex Deucher 				 PIPE_CONFIG(ADDR_SURF_P2) |
3320aaa36a97SAlex Deucher 				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3321aaa36a97SAlex Deucher 				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
332290bea0abSTom St Denis 
332390bea0abSTom St Denis 		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3324aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3325aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3326aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
332790bea0abSTom St Denis 		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3328aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3329aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3330aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
333190bea0abSTom St Denis 		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3332aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3333aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3334aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
333590bea0abSTom St Denis 		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3336aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3337aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3338aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
333990bea0abSTom St Denis 		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3340aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3341aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3342aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
334390bea0abSTom St Denis 		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3344aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3345aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3346aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
334790bea0abSTom St Denis 		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3348aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3349aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3350aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_8_BANK));
335190bea0abSTom St Denis 		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3352aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3353aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3354aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
335590bea0abSTom St Denis 		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3356aaa36a97SAlex Deucher 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3357aaa36a97SAlex Deucher 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3358aaa36a97SAlex Deucher 				NUM_BANKS(ADDR_SURF_16_BANK));
335990bea0abSTom St Denis 		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3360aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3361aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3362aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
336390bea0abSTom St Denis 		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3364aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3365aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3366aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
336790bea0abSTom St Denis 		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3368aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3369aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3370aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
337190bea0abSTom St Denis 		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3372aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3373aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3374aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_16_BANK));
337590bea0abSTom St Denis 		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3376aaa36a97SAlex Deucher 				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3377aaa36a97SAlex Deucher 				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3378aaa36a97SAlex Deucher 				 NUM_BANKS(ADDR_SURF_8_BANK));
337990bea0abSTom St Denis 
338090bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
338190bea0abSTom St Denis 			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
338290bea0abSTom St Denis 			    reg_offset != 23)
338390bea0abSTom St Denis 				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
338490bea0abSTom St Denis 
338590bea0abSTom St Denis 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
338690bea0abSTom St Denis 			if (reg_offset != 7)
338790bea0abSTom St Denis 				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
338890bea0abSTom St Denis 
3389aaa36a97SAlex Deucher 		break;
3390aaa36a97SAlex Deucher 	}
3391aaa36a97SAlex Deucher }
3392aaa36a97SAlex Deucher 
gfx_v8_0_select_se_sh(struct amdgpu_device * adev,u32 se_num,u32 sh_num,u32 instance,int xcc_id)339305fb7291SAlex Deucher static void gfx_v8_0_select_se_sh(struct amdgpu_device *adev,
3394d51ac6d0SLe Ma 				  u32 se_num, u32 sh_num, u32 instance,
3395d51ac6d0SLe Ma 				  int xcc_id)
3396aaa36a97SAlex Deucher {
33979559ef5bSTom St Denis 	u32 data;
33989559ef5bSTom St Denis 
33999559ef5bSTom St Denis 	if (instance == 0xffffffff)
34009559ef5bSTom St Denis 		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES, 1);
34019559ef5bSTom St Denis 	else
34029559ef5bSTom St Denis 		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
3403aaa36a97SAlex Deucher 
34045003f278STom St Denis 	if (se_num == 0xffffffff)
3405aaa36a97SAlex Deucher 		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
34065003f278STom St Denis 	else
34075003f278STom St Denis 		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
34085003f278STom St Denis 
34095003f278STom St Denis 	if (sh_num == 0xffffffff)
3410aaa36a97SAlex Deucher 		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
34115003f278STom St Denis 	else
3412aaa36a97SAlex Deucher 		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
34135003f278STom St Denis 
3414aaa36a97SAlex Deucher 	WREG32(mmGRBM_GFX_INDEX, data);
3415aaa36a97SAlex Deucher }
3416aaa36a97SAlex Deucher 
gfx_v8_0_select_me_pipe_q(struct amdgpu_device * adev,u32 me,u32 pipe,u32 q,u32 vm,u32 xcc_id)3417f7a9ee81SAndrey Grodzovsky static void gfx_v8_0_select_me_pipe_q(struct amdgpu_device *adev,
3418553f973aSTom St Denis 				  u32 me, u32 pipe, u32 q, u32 vm, u32 xcc_id)
3419f7a9ee81SAndrey Grodzovsky {
34200fa4246eSTom St Denis 	vi_srbm_select(adev, me, pipe, q, vm);
3421f7a9ee81SAndrey Grodzovsky }
3422f7a9ee81SAndrey Grodzovsky 
gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device * adev)34238f8e00c1SAlex Deucher static u32 gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device *adev)
3424aaa36a97SAlex Deucher {
3425aaa36a97SAlex Deucher 	u32 data, mask;
3426aaa36a97SAlex Deucher 
34275003f278STom St Denis 	data =  RREG32(mmCC_RB_BACKEND_DISABLE) |
34285003f278STom St Denis 		RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3429aaa36a97SAlex Deucher 
34305003f278STom St Denis 	data = REG_GET_FIELD(data, GC_USER_RB_BACKEND_DISABLE, BACKEND_DISABLE);
3431aaa36a97SAlex Deucher 
3432378506a7SAlex Deucher 	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_backends_per_se /
34338f8e00c1SAlex Deucher 					 adev->gfx.config.max_sh_per_se);
3434aaa36a97SAlex Deucher 
34358f8e00c1SAlex Deucher 	return (~data) & mask;
3436aaa36a97SAlex Deucher }
3437aaa36a97SAlex Deucher 
3438167ac573SHuang Rui static void
gfx_v8_0_raster_config(struct amdgpu_device * adev,u32 * rconf,u32 * rconf1)3439167ac573SHuang Rui gfx_v8_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
3440167ac573SHuang Rui {
3441167ac573SHuang Rui 	switch (adev->asic_type) {
3442167ac573SHuang Rui 	case CHIP_FIJI:
344371765469SLeo Liu 	case CHIP_VEGAM:
3444167ac573SHuang Rui 		*rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
3445167ac573SHuang Rui 			  RB_XSEL2(1) | PKR_MAP(2) |
3446167ac573SHuang Rui 			  PKR_XSEL(1) | PKR_YSEL(1) |
3447167ac573SHuang Rui 			  SE_MAP(2) | SE_XSEL(2) | SE_YSEL(3);
3448167ac573SHuang Rui 		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
3449167ac573SHuang Rui 			   SE_PAIR_YSEL(2);
3450167ac573SHuang Rui 		break;
3451167ac573SHuang Rui 	case CHIP_TONGA:
3452167ac573SHuang Rui 	case CHIP_POLARIS10:
3453167ac573SHuang Rui 		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3454167ac573SHuang Rui 			  SE_XSEL(1) | SE_YSEL(1);
3455167ac573SHuang Rui 		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(2) |
3456167ac573SHuang Rui 			   SE_PAIR_YSEL(2);
3457167ac573SHuang Rui 		break;
3458167ac573SHuang Rui 	case CHIP_TOPAZ:
3459167ac573SHuang Rui 	case CHIP_CARRIZO:
3460167ac573SHuang Rui 		*rconf |= RB_MAP_PKR0(2);
3461167ac573SHuang Rui 		*rconf1 |= 0x0;
3462167ac573SHuang Rui 		break;
3463167ac573SHuang Rui 	case CHIP_POLARIS11:
3464c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
3465167ac573SHuang Rui 		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3466167ac573SHuang Rui 			  SE_XSEL(1) | SE_YSEL(1);
3467167ac573SHuang Rui 		*rconf1 |= 0x0;
3468167ac573SHuang Rui 		break;
3469167ac573SHuang Rui 	case CHIP_STONEY:
3470167ac573SHuang Rui 		*rconf |= 0x0;
3471167ac573SHuang Rui 		*rconf1 |= 0x0;
3472167ac573SHuang Rui 		break;
3473167ac573SHuang Rui 	default:
3474167ac573SHuang Rui 		DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
3475167ac573SHuang Rui 		break;
3476167ac573SHuang Rui 	}
3477167ac573SHuang Rui }
3478167ac573SHuang Rui 
3479167ac573SHuang Rui static void
gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device * adev,u32 raster_config,u32 raster_config_1,unsigned rb_mask,unsigned num_rb)3480167ac573SHuang Rui gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device *adev,
3481167ac573SHuang Rui 					u32 raster_config, u32 raster_config_1,
3482167ac573SHuang Rui 					unsigned rb_mask, unsigned num_rb)
3483167ac573SHuang Rui {
3484167ac573SHuang Rui 	unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
3485167ac573SHuang Rui 	unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
3486167ac573SHuang Rui 	unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
3487167ac573SHuang Rui 	unsigned rb_per_se = num_rb / num_se;
3488167ac573SHuang Rui 	unsigned se_mask[4];
3489167ac573SHuang Rui 	unsigned se;
3490167ac573SHuang Rui 
3491167ac573SHuang Rui 	se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
3492167ac573SHuang Rui 	se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
3493167ac573SHuang Rui 	se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
3494167ac573SHuang Rui 	se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
3495167ac573SHuang Rui 
3496167ac573SHuang Rui 	WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
3497167ac573SHuang Rui 	WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
3498167ac573SHuang Rui 	WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
3499167ac573SHuang Rui 
3500167ac573SHuang Rui 	if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
3501167ac573SHuang Rui 			     (!se_mask[2] && !se_mask[3]))) {
3502167ac573SHuang Rui 		raster_config_1 &= ~SE_PAIR_MAP_MASK;
3503167ac573SHuang Rui 
3504167ac573SHuang Rui 		if (!se_mask[0] && !se_mask[1]) {
3505167ac573SHuang Rui 			raster_config_1 |=
3506167ac573SHuang Rui 				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
3507167ac573SHuang Rui 		} else {
3508167ac573SHuang Rui 			raster_config_1 |=
3509167ac573SHuang Rui 				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
3510167ac573SHuang Rui 		}
3511167ac573SHuang Rui 	}
3512167ac573SHuang Rui 
3513167ac573SHuang Rui 	for (se = 0; se < num_se; se++) {
3514167ac573SHuang Rui 		unsigned raster_config_se = raster_config;
3515167ac573SHuang Rui 		unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
3516167ac573SHuang Rui 		unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
3517167ac573SHuang Rui 		int idx = (se / 2) * 2;
3518167ac573SHuang Rui 
3519167ac573SHuang Rui 		if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
3520167ac573SHuang Rui 			raster_config_se &= ~SE_MAP_MASK;
3521167ac573SHuang Rui 
3522167ac573SHuang Rui 			if (!se_mask[idx]) {
3523167ac573SHuang Rui 				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
3524167ac573SHuang Rui 			} else {
3525167ac573SHuang Rui 				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
3526167ac573SHuang Rui 			}
3527167ac573SHuang Rui 		}
3528167ac573SHuang Rui 
3529167ac573SHuang Rui 		pkr0_mask &= rb_mask;
3530167ac573SHuang Rui 		pkr1_mask &= rb_mask;
3531167ac573SHuang Rui 		if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
3532167ac573SHuang Rui 			raster_config_se &= ~PKR_MAP_MASK;
3533167ac573SHuang Rui 
3534167ac573SHuang Rui 			if (!pkr0_mask) {
3535167ac573SHuang Rui 				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
3536167ac573SHuang Rui 			} else {
3537167ac573SHuang Rui 				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
3538167ac573SHuang Rui 			}
3539167ac573SHuang Rui 		}
3540167ac573SHuang Rui 
3541167ac573SHuang Rui 		if (rb_per_se >= 2) {
3542167ac573SHuang Rui 			unsigned rb0_mask = 1 << (se * rb_per_se);
3543167ac573SHuang Rui 			unsigned rb1_mask = rb0_mask << 1;
3544167ac573SHuang Rui 
3545167ac573SHuang Rui 			rb0_mask &= rb_mask;
3546167ac573SHuang Rui 			rb1_mask &= rb_mask;
3547167ac573SHuang Rui 			if (!rb0_mask || !rb1_mask) {
3548167ac573SHuang Rui 				raster_config_se &= ~RB_MAP_PKR0_MASK;
3549167ac573SHuang Rui 
3550167ac573SHuang Rui 				if (!rb0_mask) {
3551167ac573SHuang Rui 					raster_config_se |=
3552167ac573SHuang Rui 						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
3553167ac573SHuang Rui 				} else {
3554167ac573SHuang Rui 					raster_config_se |=
3555167ac573SHuang Rui 						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
3556167ac573SHuang Rui 				}
3557167ac573SHuang Rui 			}
3558167ac573SHuang Rui 
3559167ac573SHuang Rui 			if (rb_per_se > 2) {
3560167ac573SHuang Rui 				rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
3561167ac573SHuang Rui 				rb1_mask = rb0_mask << 1;
3562167ac573SHuang Rui 				rb0_mask &= rb_mask;
3563167ac573SHuang Rui 				rb1_mask &= rb_mask;
3564167ac573SHuang Rui 				if (!rb0_mask || !rb1_mask) {
3565167ac573SHuang Rui 					raster_config_se &= ~RB_MAP_PKR1_MASK;
3566167ac573SHuang Rui 
3567167ac573SHuang Rui 					if (!rb0_mask) {
3568167ac573SHuang Rui 						raster_config_se |=
3569167ac573SHuang Rui 							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
3570167ac573SHuang Rui 					} else {
3571167ac573SHuang Rui 						raster_config_se |=
3572167ac573SHuang Rui 							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
3573167ac573SHuang Rui 					}
3574167ac573SHuang Rui 				}
3575167ac573SHuang Rui 			}
3576167ac573SHuang Rui 		}
3577167ac573SHuang Rui 
3578167ac573SHuang Rui 		/* GRBM_GFX_INDEX has a different offset on VI */
3579d51ac6d0SLe Ma 		gfx_v8_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff, 0);
3580167ac573SHuang Rui 		WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
3581167ac573SHuang Rui 		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3582167ac573SHuang Rui 	}
3583167ac573SHuang Rui 
3584167ac573SHuang Rui 	/* GRBM_GFX_INDEX has a different offset on VI */
3585d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3586167ac573SHuang Rui }
3587167ac573SHuang Rui 
gfx_v8_0_setup_rb(struct amdgpu_device * adev)35888f8e00c1SAlex Deucher static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)
3589aaa36a97SAlex Deucher {
3590aaa36a97SAlex Deucher 	int i, j;
3591aac1e3caSAlex Deucher 	u32 data;
3592167ac573SHuang Rui 	u32 raster_config = 0, raster_config_1 = 0;
35938f8e00c1SAlex Deucher 	u32 active_rbs = 0;
35946157bd7aSFlora Cui 	u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
35956157bd7aSFlora Cui 					adev->gfx.config.max_sh_per_se;
3596167ac573SHuang Rui 	unsigned num_rb_pipes;
3597aaa36a97SAlex Deucher 
3598aaa36a97SAlex Deucher 	mutex_lock(&adev->grbm_idx_mutex);
35998f8e00c1SAlex Deucher 	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
36008f8e00c1SAlex Deucher 		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3601d51ac6d0SLe Ma 			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
36028f8e00c1SAlex Deucher 			data = gfx_v8_0_get_rb_active_bitmap(adev);
36038f8e00c1SAlex Deucher 			active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
36046157bd7aSFlora Cui 					       rb_bitmap_width_per_sh);
3605aaa36a97SAlex Deucher 		}
3606aaa36a97SAlex Deucher 	}
3607d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3608aaa36a97SAlex Deucher 
36098f8e00c1SAlex Deucher 	adev->gfx.config.backend_enable_mask = active_rbs;
3610aac1e3caSAlex Deucher 	adev->gfx.config.num_rbs = hweight32(active_rbs);
3611167ac573SHuang Rui 
3612167ac573SHuang Rui 	num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
3613167ac573SHuang Rui 			     adev->gfx.config.max_shader_engines, 16);
3614167ac573SHuang Rui 
3615167ac573SHuang Rui 	gfx_v8_0_raster_config(adev, &raster_config, &raster_config_1);
3616167ac573SHuang Rui 
3617167ac573SHuang Rui 	if (!adev->gfx.config.backend_enable_mask ||
3618167ac573SHuang Rui 			adev->gfx.config.num_rbs >= num_rb_pipes) {
3619167ac573SHuang Rui 		WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
3620167ac573SHuang Rui 		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3621167ac573SHuang Rui 	} else {
3622167ac573SHuang Rui 		gfx_v8_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
3623167ac573SHuang Rui 							adev->gfx.config.backend_enable_mask,
3624167ac573SHuang Rui 							num_rb_pipes);
3625167ac573SHuang Rui 	}
3626167ac573SHuang Rui 
3627392f0c77SAlex Deucher 	/* cache the values for userspace */
3628392f0c77SAlex Deucher 	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3629392f0c77SAlex Deucher 		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3630d51ac6d0SLe Ma 			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
3631392f0c77SAlex Deucher 			adev->gfx.config.rb_config[i][j].rb_backend_disable =
3632392f0c77SAlex Deucher 				RREG32(mmCC_RB_BACKEND_DISABLE);
3633392f0c77SAlex Deucher 			adev->gfx.config.rb_config[i][j].user_rb_backend_disable =
3634392f0c77SAlex Deucher 				RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3635392f0c77SAlex Deucher 			adev->gfx.config.rb_config[i][j].raster_config =
3636392f0c77SAlex Deucher 				RREG32(mmPA_SC_RASTER_CONFIG);
3637392f0c77SAlex Deucher 			adev->gfx.config.rb_config[i][j].raster_config_1 =
3638392f0c77SAlex Deucher 				RREG32(mmPA_SC_RASTER_CONFIG_1);
3639392f0c77SAlex Deucher 		}
3640392f0c77SAlex Deucher 	}
3641d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3642167ac573SHuang Rui 	mutex_unlock(&adev->grbm_idx_mutex);
3643aaa36a97SAlex Deucher }
3644aaa36a97SAlex Deucher 
3645c5ce5115SLee Jones #define DEFAULT_SH_MEM_BASES	(0x6000)
3646cd06bf68SBen Goz /**
364735c7a952SAlex Deucher  * gfx_v8_0_init_compute_vmid - gart enable
3648cd06bf68SBen Goz  *
3649dc102c43SAndres Rodriguez  * @adev: amdgpu_device pointer
3650cd06bf68SBen Goz  *
3651cd06bf68SBen Goz  * Initialize compute vmid sh_mem registers
3652cd06bf68SBen Goz  *
3653cd06bf68SBen Goz  */
gfx_v8_0_init_compute_vmid(struct amdgpu_device * adev)365435c7a952SAlex Deucher static void gfx_v8_0_init_compute_vmid(struct amdgpu_device *adev)
3655cd06bf68SBen Goz {
3656cd06bf68SBen Goz 	int i;
3657cd06bf68SBen Goz 	uint32_t sh_mem_config;
3658cd06bf68SBen Goz 	uint32_t sh_mem_bases;
3659cd06bf68SBen Goz 
3660cd06bf68SBen Goz 	/*
3661cd06bf68SBen Goz 	 * Configure apertures:
3662cd06bf68SBen Goz 	 * LDS:         0x60000000'00000000 - 0x60000001'00000000 (4GB)
3663cd06bf68SBen Goz 	 * Scratch:     0x60000001'00000000 - 0x60000002'00000000 (4GB)
3664cd06bf68SBen Goz 	 * GPUVM:       0x60010000'00000000 - 0x60020000'00000000 (1TB)
3665cd06bf68SBen Goz 	 */
3666cd06bf68SBen Goz 	sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16);
3667cd06bf68SBen Goz 
3668cd06bf68SBen Goz 	sh_mem_config = SH_MEM_ADDRESS_MODE_HSA64 <<
3669cd06bf68SBen Goz 			SH_MEM_CONFIG__ADDRESS_MODE__SHIFT |
3670cd06bf68SBen Goz 			SH_MEM_ALIGNMENT_MODE_UNALIGNED <<
3671cd06bf68SBen Goz 			SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT |
3672cd06bf68SBen Goz 			MTYPE_CC << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT |
3673cd06bf68SBen Goz 			SH_MEM_CONFIG__PRIVATE_ATC_MASK;
3674cd06bf68SBen Goz 
3675cd06bf68SBen Goz 	mutex_lock(&adev->srbm_mutex);
367640111ec2SFelix Kuehling 	for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) {
3677cd06bf68SBen Goz 		vi_srbm_select(adev, 0, 0, 0, i);
3678cd06bf68SBen Goz 		/* CP and shaders */
3679cd06bf68SBen Goz 		WREG32(mmSH_MEM_CONFIG, sh_mem_config);
3680cd06bf68SBen Goz 		WREG32(mmSH_MEM_APE1_BASE, 1);
3681cd06bf68SBen Goz 		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3682cd06bf68SBen Goz 		WREG32(mmSH_MEM_BASES, sh_mem_bases);
3683cd06bf68SBen Goz 	}
3684cd06bf68SBen Goz 	vi_srbm_select(adev, 0, 0, 0, 0);
3685cd06bf68SBen Goz 	mutex_unlock(&adev->srbm_mutex);
3686ad28e024SJoseph Greathouse 
3687ad28e024SJoseph Greathouse 	/* Initialize all compute VMIDs to have no GDS, GWS, or OA
3688ab5a7fb6SJulia Lawall 	   access. These should be enabled by FW for target VMIDs. */
368940111ec2SFelix Kuehling 	for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) {
3690ad28e024SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[i].mem_base, 0);
3691ad28e024SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[i].mem_size, 0);
3692ad28e024SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[i].gws, 0);
3693ad28e024SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[i].oa, 0);
3694ad28e024SJoseph Greathouse 	}
36952c897318SJoseph Greathouse }
3696fbdc5d8dSJoseph Greathouse 
gfx_v8_0_init_gds_vmid(struct amdgpu_device * adev)36972c897318SJoseph Greathouse static void gfx_v8_0_init_gds_vmid(struct amdgpu_device *adev)
36982c897318SJoseph Greathouse {
36992c897318SJoseph Greathouse 	int vmid;
37002c897318SJoseph Greathouse 
37012c897318SJoseph Greathouse 	/*
37022c897318SJoseph Greathouse 	 * Initialize all compute and user-gfx VMIDs to have no GDS, GWS, or OA
37032c897318SJoseph Greathouse 	 * access. Compute VMIDs should be enabled by FW for target VMIDs,
37042c897318SJoseph Greathouse 	 * the driver can enable them for graphics. VMID0 should maintain
37052c897318SJoseph Greathouse 	 * access so that HWS firmware can save/restore entries.
37062c897318SJoseph Greathouse 	 */
370768fce5f0SNirmoy Das 	for (vmid = 1; vmid < AMDGPU_NUM_VMID; vmid++) {
37082c897318SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[vmid].mem_base, 0);
37092c897318SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[vmid].mem_size, 0);
37102c897318SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[vmid].gws, 0);
37112c897318SJoseph Greathouse 		WREG32(amdgpu_gds_reg_offset[vmid].oa, 0);
3712fbdc5d8dSJoseph Greathouse 	}
3713cd06bf68SBen Goz }
3714cd06bf68SBen Goz 
gfx_v8_0_config_init(struct amdgpu_device * adev)3715df6e2c4aSJunwei Zhang static void gfx_v8_0_config_init(struct amdgpu_device *adev)
3716df6e2c4aSJunwei Zhang {
3717df6e2c4aSJunwei Zhang 	switch (adev->asic_type) {
3718df6e2c4aSJunwei Zhang 	default:
3719df6e2c4aSJunwei Zhang 		adev->gfx.config.double_offchip_lds_buf = 1;
3720df6e2c4aSJunwei Zhang 		break;
3721df6e2c4aSJunwei Zhang 	case CHIP_CARRIZO:
3722df6e2c4aSJunwei Zhang 	case CHIP_STONEY:
3723df6e2c4aSJunwei Zhang 		adev->gfx.config.double_offchip_lds_buf = 0;
3724df6e2c4aSJunwei Zhang 		break;
3725df6e2c4aSJunwei Zhang 	}
3726df6e2c4aSJunwei Zhang }
3727df6e2c4aSJunwei Zhang 
gfx_v8_0_constants_init(struct amdgpu_device * adev)3728434e6df2SRex Zhu static void gfx_v8_0_constants_init(struct amdgpu_device *adev)
3729aaa36a97SAlex Deucher {
37308fe73328SJunwei Zhang 	u32 tmp, sh_static_mem_cfg;
3731aaa36a97SAlex Deucher 	int i;
3732aaa36a97SAlex Deucher 
373361cb8cefSTom St Denis 	WREG32_FIELD(GRBM_CNTL, READ_TIMEOUT, 0xFF);
37340bde3a95SAlex Deucher 	WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
37350bde3a95SAlex Deucher 	WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
37360bde3a95SAlex Deucher 	WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
3737aaa36a97SAlex Deucher 
3738aaa36a97SAlex Deucher 	gfx_v8_0_tiling_mode_table_init(adev);
37398f8e00c1SAlex Deucher 	gfx_v8_0_setup_rb(adev);
37407dae69a2SAlex Deucher 	gfx_v8_0_get_cu_info(adev);
3741df6e2c4aSJunwei Zhang 	gfx_v8_0_config_init(adev);
3742aaa36a97SAlex Deucher 
3743aaa36a97SAlex Deucher 	/* XXX SH_MEM regs */
3744aaa36a97SAlex Deucher 	/* where to put LDS, scratch, GPUVM in FSA64 space */
37458fe73328SJunwei Zhang 	sh_static_mem_cfg = REG_SET_FIELD(0, SH_STATIC_MEM_CONFIG,
37468fe73328SJunwei Zhang 				   SWIZZLE_ENABLE, 1);
37478fe73328SJunwei Zhang 	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
37488fe73328SJunwei Zhang 				   ELEMENT_SIZE, 1);
37498fe73328SJunwei Zhang 	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
37508fe73328SJunwei Zhang 				   INDEX_STRIDE, 3);
3751111159b5SFelix Kuehling 	WREG32(mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg);
3752111159b5SFelix Kuehling 
3753aaa36a97SAlex Deucher 	mutex_lock(&adev->srbm_mutex);
37547645670dSChristian König 	for (i = 0; i < adev->vm_manager.id_mgr[0].num_ids; i++) {
3755aaa36a97SAlex Deucher 		vi_srbm_select(adev, 0, 0, 0, i);
3756aaa36a97SAlex Deucher 		/* CP and shaders */
3757aaa36a97SAlex Deucher 		if (i == 0) {
3758aaa36a97SAlex Deucher 			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_UC);
3759aaa36a97SAlex Deucher 			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
376074a5d165SJack Xiao 			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
376174a5d165SJack Xiao 					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3762aaa36a97SAlex Deucher 			WREG32(mmSH_MEM_CONFIG, tmp);
37638fe73328SJunwei Zhang 			WREG32(mmSH_MEM_BASES, 0);
3764aaa36a97SAlex Deucher 		} else {
3765aaa36a97SAlex Deucher 			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_NC);
37668fe73328SJunwei Zhang 			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
376774a5d165SJack Xiao 			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
376874a5d165SJack Xiao 					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3769aaa36a97SAlex Deucher 			WREG32(mmSH_MEM_CONFIG, tmp);
3770770d13b1SChristian König 			tmp = adev->gmc.shared_aperture_start >> 48;
37718fe73328SJunwei Zhang 			WREG32(mmSH_MEM_BASES, tmp);
3772aaa36a97SAlex Deucher 		}
3773aaa36a97SAlex Deucher 
3774aaa36a97SAlex Deucher 		WREG32(mmSH_MEM_APE1_BASE, 1);
3775aaa36a97SAlex Deucher 		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3776aaa36a97SAlex Deucher 	}
3777aaa36a97SAlex Deucher 	vi_srbm_select(adev, 0, 0, 0, 0);
3778aaa36a97SAlex Deucher 	mutex_unlock(&adev->srbm_mutex);
3779aaa36a97SAlex Deucher 
378035c7a952SAlex Deucher 	gfx_v8_0_init_compute_vmid(adev);
37812c897318SJoseph Greathouse 	gfx_v8_0_init_gds_vmid(adev);
3782cd06bf68SBen Goz 
3783aaa36a97SAlex Deucher 	mutex_lock(&adev->grbm_idx_mutex);
3784aaa36a97SAlex Deucher 	/*
3785aaa36a97SAlex Deucher 	 * making sure that the following register writes will be broadcasted
3786aaa36a97SAlex Deucher 	 * to all the shaders
3787aaa36a97SAlex Deucher 	 */
3788d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3789aaa36a97SAlex Deucher 
3790aaa36a97SAlex Deucher 	WREG32(mmPA_SC_FIFO_SIZE,
3791aaa36a97SAlex Deucher 		   (adev->gfx.config.sc_prim_fifo_size_frontend <<
3792aaa36a97SAlex Deucher 			PA_SC_FIFO_SIZE__SC_FRONTEND_PRIM_FIFO_SIZE__SHIFT) |
3793aaa36a97SAlex Deucher 		   (adev->gfx.config.sc_prim_fifo_size_backend <<
3794aaa36a97SAlex Deucher 			PA_SC_FIFO_SIZE__SC_BACKEND_PRIM_FIFO_SIZE__SHIFT) |
3795aaa36a97SAlex Deucher 		   (adev->gfx.config.sc_hiz_tile_fifo_size <<
3796aaa36a97SAlex Deucher 			PA_SC_FIFO_SIZE__SC_HIZ_TILE_FIFO_SIZE__SHIFT) |
3797aaa36a97SAlex Deucher 		   (adev->gfx.config.sc_earlyz_tile_fifo_size <<
3798aaa36a97SAlex Deucher 			PA_SC_FIFO_SIZE__SC_EARLYZ_TILE_FIFO_SIZE__SHIFT));
3799d2383267Sozeng 
3800d2383267Sozeng 	tmp = RREG32(mmSPI_ARB_PRIORITY);
3801d2383267Sozeng 	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS0, 2);
3802d2383267Sozeng 	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS1, 2);
3803d2383267Sozeng 	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS2, 2);
3804d2383267Sozeng 	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS3, 2);
3805d2383267Sozeng 	WREG32(mmSPI_ARB_PRIORITY, tmp);
3806d2383267Sozeng 
3807aaa36a97SAlex Deucher 	mutex_unlock(&adev->grbm_idx_mutex);
3808aaa36a97SAlex Deucher 
3809aaa36a97SAlex Deucher }
3810aaa36a97SAlex Deucher 
gfx_v8_0_wait_for_rlc_serdes(struct amdgpu_device * adev)3811aaa36a97SAlex Deucher static void gfx_v8_0_wait_for_rlc_serdes(struct amdgpu_device *adev)
3812aaa36a97SAlex Deucher {
3813aaa36a97SAlex Deucher 	u32 i, j, k;
3814aaa36a97SAlex Deucher 	u32 mask;
3815aaa36a97SAlex Deucher 
3816aaa36a97SAlex Deucher 	mutex_lock(&adev->grbm_idx_mutex);
3817aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3818aaa36a97SAlex Deucher 		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3819d51ac6d0SLe Ma 			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
3820aaa36a97SAlex Deucher 			for (k = 0; k < adev->usec_timeout; k++) {
3821aaa36a97SAlex Deucher 				if (RREG32(mmRLC_SERDES_CU_MASTER_BUSY) == 0)
3822aaa36a97SAlex Deucher 					break;
3823aaa36a97SAlex Deucher 				udelay(1);
3824aaa36a97SAlex Deucher 			}
38251366b2d0Spding 			if (k == adev->usec_timeout) {
38261366b2d0Spding 				gfx_v8_0_select_se_sh(adev, 0xffffffff,
3827d51ac6d0SLe Ma 						      0xffffffff, 0xffffffff, 0);
38281366b2d0Spding 				mutex_unlock(&adev->grbm_idx_mutex);
38291366b2d0Spding 				DRM_INFO("Timeout wait for RLC serdes %u,%u\n",
38301366b2d0Spding 					 i, j);
38311366b2d0Spding 				return;
38321366b2d0Spding 			}
3833aaa36a97SAlex Deucher 		}
3834aaa36a97SAlex Deucher 	}
3835d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3836aaa36a97SAlex Deucher 	mutex_unlock(&adev->grbm_idx_mutex);
3837aaa36a97SAlex Deucher 
3838aaa36a97SAlex Deucher 	mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
3839aaa36a97SAlex Deucher 		RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
3840aaa36a97SAlex Deucher 		RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
3841aaa36a97SAlex Deucher 		RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
3842aaa36a97SAlex Deucher 	for (k = 0; k < adev->usec_timeout; k++) {
3843aaa36a97SAlex Deucher 		if ((RREG32(mmRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
3844aaa36a97SAlex Deucher 			break;
3845aaa36a97SAlex Deucher 		udelay(1);
3846aaa36a97SAlex Deucher 	}
3847aaa36a97SAlex Deucher }
3848aaa36a97SAlex Deucher 
gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device * adev,bool enable)3849aaa36a97SAlex Deucher static void gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
3850aaa36a97SAlex Deucher 					       bool enable)
3851aaa36a97SAlex Deucher {
3852aaa36a97SAlex Deucher 	u32 tmp = RREG32(mmCP_INT_CNTL_RING0);
3853aaa36a97SAlex Deucher 
38540d07db7eSTom St Denis 	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE, enable ? 1 : 0);
38550d07db7eSTom St Denis 	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_EMPTY_INT_ENABLE, enable ? 1 : 0);
38560d07db7eSTom St Denis 	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CMP_BUSY_INT_ENABLE, enable ? 1 : 0);
38570d07db7eSTom St Denis 	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, GFX_IDLE_INT_ENABLE, enable ? 1 : 0);
38580d07db7eSTom St Denis 
3859aaa36a97SAlex Deucher 	WREG32(mmCP_INT_CNTL_RING0, tmp);
3860aaa36a97SAlex Deucher }
3861aaa36a97SAlex Deucher 
gfx_v8_0_init_csb(struct amdgpu_device * adev)38622b6cd977SEric Huang static void gfx_v8_0_init_csb(struct amdgpu_device *adev)
38632b6cd977SEric Huang {
386482a829dcSMonk Liu 	adev->gfx.rlc.funcs->get_csb_buffer(adev, adev->gfx.rlc.cs_ptr);
38652b6cd977SEric Huang 	/* csib */
38662b6cd977SEric Huang 	WREG32(mmRLC_CSIB_ADDR_HI,
38672b6cd977SEric Huang 			adev->gfx.rlc.clear_state_gpu_addr >> 32);
38682b6cd977SEric Huang 	WREG32(mmRLC_CSIB_ADDR_LO,
38692b6cd977SEric Huang 			adev->gfx.rlc.clear_state_gpu_addr & 0xfffffffc);
38702b6cd977SEric Huang 	WREG32(mmRLC_CSIB_LENGTH,
38712b6cd977SEric Huang 			adev->gfx.rlc.clear_state_size);
38722b6cd977SEric Huang }
38732b6cd977SEric Huang 
gfx_v8_0_parse_ind_reg_list(int * register_list_format,int ind_offset,int list_size,int * unique_indices,int * indices_count,int max_indices,int * ind_start_offsets,int * offset_count,int max_offset)38742b6cd977SEric Huang static void gfx_v8_0_parse_ind_reg_list(int *register_list_format,
38752b6cd977SEric Huang 				int ind_offset,
38762b6cd977SEric Huang 				int list_size,
38772b6cd977SEric Huang 				int *unique_indices,
38782b6cd977SEric Huang 				int *indices_count,
38792b6cd977SEric Huang 				int max_indices,
38802b6cd977SEric Huang 				int *ind_start_offsets,
38812b6cd977SEric Huang 				int *offset_count,
38822b6cd977SEric Huang 				int max_offset)
38832b6cd977SEric Huang {
38842b6cd977SEric Huang 	int indices;
38852b6cd977SEric Huang 	bool new_entry = true;
38862b6cd977SEric Huang 
38872b6cd977SEric Huang 	for (; ind_offset < list_size; ind_offset++) {
38882b6cd977SEric Huang 
38892b6cd977SEric Huang 		if (new_entry) {
38902b6cd977SEric Huang 			new_entry = false;
38912b6cd977SEric Huang 			ind_start_offsets[*offset_count] = ind_offset;
38922b6cd977SEric Huang 			*offset_count = *offset_count + 1;
38932b6cd977SEric Huang 			BUG_ON(*offset_count >= max_offset);
38942b6cd977SEric Huang 		}
38952b6cd977SEric Huang 
38962b6cd977SEric Huang 		if (register_list_format[ind_offset] == 0xFFFFFFFF) {
38972b6cd977SEric Huang 			new_entry = true;
38982b6cd977SEric Huang 			continue;
38992b6cd977SEric Huang 		}
39002b6cd977SEric Huang 
39012b6cd977SEric Huang 		ind_offset += 2;
39022b6cd977SEric Huang 
39032b6cd977SEric Huang 		/* look for the matching indice */
39042b6cd977SEric Huang 		for (indices = 0;
39052b6cd977SEric Huang 			indices < *indices_count;
39062b6cd977SEric Huang 			indices++) {
39072b6cd977SEric Huang 			if (unique_indices[indices] ==
39082b6cd977SEric Huang 				register_list_format[ind_offset])
39092b6cd977SEric Huang 				break;
39102b6cd977SEric Huang 		}
39112b6cd977SEric Huang 
39122b6cd977SEric Huang 		if (indices >= *indices_count) {
39132b6cd977SEric Huang 			unique_indices[*indices_count] =
39142b6cd977SEric Huang 				register_list_format[ind_offset];
39152b6cd977SEric Huang 			indices = *indices_count;
39162b6cd977SEric Huang 			*indices_count = *indices_count + 1;
39172b6cd977SEric Huang 			BUG_ON(*indices_count >= max_indices);
39182b6cd977SEric Huang 		}
39192b6cd977SEric Huang 
39202b6cd977SEric Huang 		register_list_format[ind_offset] = indices;
39212b6cd977SEric Huang 	}
39222b6cd977SEric Huang }
39232b6cd977SEric Huang 
gfx_v8_0_init_save_restore_list(struct amdgpu_device * adev)39242b6cd977SEric Huang static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
39252b6cd977SEric Huang {
39262b6cd977SEric Huang 	int i, temp, data;
39272b6cd977SEric Huang 	int unique_indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
39282b6cd977SEric Huang 	int indices_count = 0;
39292b6cd977SEric Huang 	int indirect_start_offsets[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
39302b6cd977SEric Huang 	int offset_count = 0;
39312b6cd977SEric Huang 
39322b6cd977SEric Huang 	int list_size;
39332b6cd977SEric Huang 	unsigned int *register_list_format =
3934d12c2022SFuqian Huang 		kmemdup(adev->gfx.rlc.register_list_format,
3935d12c2022SFuqian Huang 			adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
39363f12325aSRavikant B Sharma 	if (!register_list_format)
39372b6cd977SEric Huang 		return -ENOMEM;
39382b6cd977SEric Huang 
39392b6cd977SEric Huang 	gfx_v8_0_parse_ind_reg_list(register_list_format,
39402b6cd977SEric Huang 				RLC_FormatDirectRegListLength,
39412b6cd977SEric Huang 				adev->gfx.rlc.reg_list_format_size_bytes >> 2,
39422b6cd977SEric Huang 				unique_indices,
39432b6cd977SEric Huang 				&indices_count,
3944c1b24a14SJérémy Lefaure 				ARRAY_SIZE(unique_indices),
39452b6cd977SEric Huang 				indirect_start_offsets,
39462b6cd977SEric Huang 				&offset_count,
3947c1b24a14SJérémy Lefaure 				ARRAY_SIZE(indirect_start_offsets));
39482b6cd977SEric Huang 
39492b6cd977SEric Huang 	/* save and restore list */
395061cb8cefSTom St Denis 	WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
39512b6cd977SEric Huang 
39522b6cd977SEric Huang 	WREG32(mmRLC_SRM_ARAM_ADDR, 0);
39532b6cd977SEric Huang 	for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
39542b6cd977SEric Huang 		WREG32(mmRLC_SRM_ARAM_DATA, adev->gfx.rlc.register_restore[i]);
39552b6cd977SEric Huang 
39562b6cd977SEric Huang 	/* indirect list */
39572b6cd977SEric Huang 	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_list_format_start);
39582b6cd977SEric Huang 	for (i = 0; i < adev->gfx.rlc.reg_list_format_size_bytes >> 2; i++)
39592b6cd977SEric Huang 		WREG32(mmRLC_GPM_SCRATCH_DATA, register_list_format[i]);
39602b6cd977SEric Huang 
39612b6cd977SEric Huang 	list_size = adev->gfx.rlc.reg_list_size_bytes >> 2;
39622b6cd977SEric Huang 	list_size = list_size >> 1;
39632b6cd977SEric Huang 	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_restore_list_size);
39642b6cd977SEric Huang 	WREG32(mmRLC_GPM_SCRATCH_DATA, list_size);
39652b6cd977SEric Huang 
39662b6cd977SEric Huang 	/* starting offsets starts */
39672b6cd977SEric Huang 	WREG32(mmRLC_GPM_SCRATCH_ADDR,
39682b6cd977SEric Huang 		adev->gfx.rlc.starting_offsets_start);
3969c1b24a14SJérémy Lefaure 	for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
39702b6cd977SEric Huang 		WREG32(mmRLC_GPM_SCRATCH_DATA,
39712b6cd977SEric Huang 				indirect_start_offsets[i]);
39722b6cd977SEric Huang 
39732b6cd977SEric Huang 	/* unique indices */
39742b6cd977SEric Huang 	temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
39752b6cd977SEric Huang 	data = mmRLC_SRM_INDEX_CNTL_DATA_0;
3976c1b24a14SJérémy Lefaure 	for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
3977202e0b22SRex Zhu 		if (unique_indices[i] != 0) {
3978b85c9d2aSMonk Liu 			WREG32(temp + i, unique_indices[i] & 0x3FFFF);
3979b85c9d2aSMonk Liu 			WREG32(data + i, unique_indices[i] >> 20);
3980202e0b22SRex Zhu 		}
39812b6cd977SEric Huang 	}
39822b6cd977SEric Huang 	kfree(register_list_format);
39832b6cd977SEric Huang 
39842b6cd977SEric Huang 	return 0;
39852b6cd977SEric Huang }
39862b6cd977SEric Huang 
gfx_v8_0_enable_save_restore_machine(struct amdgpu_device * adev)39872b6cd977SEric Huang static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
39882b6cd977SEric Huang {
398961cb8cefSTom St Denis 	WREG32_FIELD(RLC_SRM_CNTL, SRM_ENABLE, 1);
39902b6cd977SEric Huang }
39912b6cd977SEric Huang 
gfx_v8_0_init_power_gating(struct amdgpu_device * adev)3992fb16007bSAlex Deucher static void gfx_v8_0_init_power_gating(struct amdgpu_device *adev)
3993f4bfffddSEric Huang {
3994f4bfffddSEric Huang 	uint32_t data;
3995f4bfffddSEric Huang 
399661cb8cefSTom St Denis 	WREG32_FIELD(CP_RB_WPTR_POLL_CNTL, IDLE_POLL_COUNT, 0x60);
3997f4bfffddSEric Huang 
399861cb8cefSTom St Denis 	data = REG_SET_FIELD(0, RLC_PG_DELAY, POWER_UP_DELAY, 0x10);
399961cb8cefSTom St Denis 	data = REG_SET_FIELD(data, RLC_PG_DELAY, POWER_DOWN_DELAY, 0x10);
400061cb8cefSTom St Denis 	data = REG_SET_FIELD(data, RLC_PG_DELAY, CMD_PROPAGATE_DELAY, 0x10);
400161cb8cefSTom St Denis 	data = REG_SET_FIELD(data, RLC_PG_DELAY, MEM_SLEEP_DELAY, 0x10);
4002f4bfffddSEric Huang 	WREG32(mmRLC_PG_DELAY, data);
4003f4bfffddSEric Huang 
400461cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_DELAY_2, SERDES_CMD_DELAY, 0x3);
400561cb8cefSTom St Denis 	WREG32_FIELD(RLC_AUTO_PG_CTRL, GRBM_REG_SAVE_GFX_IDLE_THRESHOLD, 0x55f0);
4006c4d17b81SRex Zhu 
4007f4bfffddSEric Huang }
4008f4bfffddSEric Huang 
cz_enable_sck_slow_down_on_power_up(struct amdgpu_device * adev,bool enable)40092c547165SAlex Deucher static void cz_enable_sck_slow_down_on_power_up(struct amdgpu_device *adev,
40102c547165SAlex Deucher 						bool enable)
40112c547165SAlex Deucher {
401261cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PU_ENABLE, enable ? 1 : 0);
40132c547165SAlex Deucher }
40142c547165SAlex Deucher 
cz_enable_sck_slow_down_on_power_down(struct amdgpu_device * adev,bool enable)40152c547165SAlex Deucher static void cz_enable_sck_slow_down_on_power_down(struct amdgpu_device *adev,
40162c547165SAlex Deucher 						  bool enable)
40172c547165SAlex Deucher {
401861cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PD_ENABLE, enable ? 1 : 0);
40192c547165SAlex Deucher }
40202c547165SAlex Deucher 
cz_enable_cp_power_gating(struct amdgpu_device * adev,bool enable)40212c547165SAlex Deucher static void cz_enable_cp_power_gating(struct amdgpu_device *adev, bool enable)
40222c547165SAlex Deucher {
4023eb584241SRex Zhu 	WREG32_FIELD(RLC_PG_CNTL, CP_PG_DISABLE, enable ? 0 : 1);
40242c547165SAlex Deucher }
40252c547165SAlex Deucher 
gfx_v8_0_init_pg(struct amdgpu_device * adev)40262b6cd977SEric Huang static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
40272b6cd977SEric Huang {
4028c4d17b81SRex Zhu 	if ((adev->asic_type == CHIP_CARRIZO) ||
4029c4d17b81SRex Zhu 	    (adev->asic_type == CHIP_STONEY)) {
40302b6cd977SEric Huang 		gfx_v8_0_init_csb(adev);
40312b6cd977SEric Huang 		gfx_v8_0_init_save_restore_list(adev);
40322b6cd977SEric Huang 		gfx_v8_0_enable_save_restore_machine(adev);
4033fb16007bSAlex Deucher 		WREG32(mmRLC_JUMP_TABLE_RESTORE, adev->gfx.rlc.cp_table_gpu_addr >> 8);
4034fb16007bSAlex Deucher 		gfx_v8_0_init_power_gating(adev);
4035fb16007bSAlex Deucher 		WREG32(mmRLC_PG_ALWAYS_ON_CU_MASK, adev->gfx.cu_info.ao_cu_mask);
4036c4642a47SJunwei Zhang 	} else if ((adev->asic_type == CHIP_POLARIS11) ||
403771765469SLeo Liu 		   (adev->asic_type == CHIP_POLARIS12) ||
403871765469SLeo Liu 		   (adev->asic_type == CHIP_VEGAM)) {
4039c4d17b81SRex Zhu 		gfx_v8_0_init_csb(adev);
4040c4d17b81SRex Zhu 		gfx_v8_0_init_save_restore_list(adev);
4041c4d17b81SRex Zhu 		gfx_v8_0_enable_save_restore_machine(adev);
4042fb16007bSAlex Deucher 		gfx_v8_0_init_power_gating(adev);
4043fb16007bSAlex Deucher 	}
4044c4d17b81SRex Zhu 
40452b6cd977SEric Huang }
40462b6cd977SEric Huang 
gfx_v8_0_rlc_stop(struct amdgpu_device * adev)4047761c2e82SBaoyou Xie static void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
4048aaa36a97SAlex Deucher {
404961cb8cefSTom St Denis 	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 0);
4050aaa36a97SAlex Deucher 
4051aaa36a97SAlex Deucher 	gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4052aaa36a97SAlex Deucher 	gfx_v8_0_wait_for_rlc_serdes(adev);
4053aaa36a97SAlex Deucher }
4054aaa36a97SAlex Deucher 
gfx_v8_0_rlc_reset(struct amdgpu_device * adev)4055aaa36a97SAlex Deucher static void gfx_v8_0_rlc_reset(struct amdgpu_device *adev)
4056aaa36a97SAlex Deucher {
405761cb8cefSTom St Denis 	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
4058aaa36a97SAlex Deucher 	udelay(50);
405961cb8cefSTom St Denis 
406061cb8cefSTom St Denis 	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
4061aaa36a97SAlex Deucher 	udelay(50);
4062aaa36a97SAlex Deucher }
4063aaa36a97SAlex Deucher 
gfx_v8_0_rlc_start(struct amdgpu_device * adev)4064aaa36a97SAlex Deucher static void gfx_v8_0_rlc_start(struct amdgpu_device *adev)
4065aaa36a97SAlex Deucher {
406661cb8cefSTom St Denis 	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 1);
4067aaa36a97SAlex Deucher 
4068aaa36a97SAlex Deucher 	/* carrizo do enable cp interrupt after cp inited */
4069e3c7656cSSamuel Li 	if (!(adev->flags & AMD_IS_APU))
4070aaa36a97SAlex Deucher 		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4071aaa36a97SAlex Deucher 
4072aaa36a97SAlex Deucher 	udelay(50);
4073aaa36a97SAlex Deucher }
4074aaa36a97SAlex Deucher 
gfx_v8_0_rlc_resume(struct amdgpu_device * adev)4075aaa36a97SAlex Deucher static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
4076aaa36a97SAlex Deucher {
407731edd7c0STiecheng Zhou 	if (amdgpu_sriov_vf(adev)) {
407831edd7c0STiecheng Zhou 		gfx_v8_0_init_csb(adev);
407931edd7c0STiecheng Zhou 		return 0;
408031edd7c0STiecheng Zhou 	}
408131edd7c0STiecheng Zhou 
4082fdb81fd7SLikun Gao 	adev->gfx.rlc.funcs->stop(adev);
4083fdb81fd7SLikun Gao 	adev->gfx.rlc.funcs->reset(adev);
40842b6cd977SEric Huang 	gfx_v8_0_init_pg(adev);
4085fdb81fd7SLikun Gao 	adev->gfx.rlc.funcs->start(adev);
4086aaa36a97SAlex Deucher 
4087aaa36a97SAlex Deucher 	return 0;
4088aaa36a97SAlex Deucher }
4089aaa36a97SAlex Deucher 
gfx_v8_0_cp_gfx_enable(struct amdgpu_device * adev,bool enable)4090aaa36a97SAlex Deucher static void gfx_v8_0_cp_gfx_enable(struct amdgpu_device *adev, bool enable)
4091aaa36a97SAlex Deucher {
4092aaa36a97SAlex Deucher 	u32 tmp = RREG32(mmCP_ME_CNTL);
4093aaa36a97SAlex Deucher 
4094aaa36a97SAlex Deucher 	if (enable) {
4095aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 0);
4096aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 0);
4097aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 0);
4098aaa36a97SAlex Deucher 	} else {
4099aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
4100aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
4101aaa36a97SAlex Deucher 		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
4102aaa36a97SAlex Deucher 	}
4103aaa36a97SAlex Deucher 	WREG32(mmCP_ME_CNTL, tmp);
4104aaa36a97SAlex Deucher 	udelay(50);
4105aaa36a97SAlex Deucher }
4106aaa36a97SAlex Deucher 
gfx_v8_0_get_csb_size(struct amdgpu_device * adev)4107aaa36a97SAlex Deucher static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev)
4108aaa36a97SAlex Deucher {
4109aaa36a97SAlex Deucher 	u32 count = 0;
4110aaa36a97SAlex Deucher 	const struct cs_section_def *sect = NULL;
4111aaa36a97SAlex Deucher 	const struct cs_extent_def *ext = NULL;
4112aaa36a97SAlex Deucher 
4113aaa36a97SAlex Deucher 	/* begin clear state */
4114aaa36a97SAlex Deucher 	count += 2;
4115aaa36a97SAlex Deucher 	/* context control state */
4116aaa36a97SAlex Deucher 	count += 3;
4117aaa36a97SAlex Deucher 
4118aaa36a97SAlex Deucher 	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4119aaa36a97SAlex Deucher 		for (ext = sect->section; ext->extent != NULL; ++ext) {
4120aaa36a97SAlex Deucher 			if (sect->id == SECT_CONTEXT)
4121aaa36a97SAlex Deucher 				count += 2 + ext->reg_count;
4122aaa36a97SAlex Deucher 			else
4123aaa36a97SAlex Deucher 				return 0;
4124aaa36a97SAlex Deucher 		}
4125aaa36a97SAlex Deucher 	}
4126aaa36a97SAlex Deucher 	/* pa_sc_raster_config/pa_sc_raster_config1 */
4127aaa36a97SAlex Deucher 	count += 4;
4128aaa36a97SAlex Deucher 	/* end clear state */
4129aaa36a97SAlex Deucher 	count += 2;
4130aaa36a97SAlex Deucher 	/* clear state */
4131aaa36a97SAlex Deucher 	count += 2;
4132aaa36a97SAlex Deucher 
4133aaa36a97SAlex Deucher 	return count;
4134aaa36a97SAlex Deucher }
4135aaa36a97SAlex Deucher 
gfx_v8_0_cp_gfx_start(struct amdgpu_device * adev)4136aaa36a97SAlex Deucher static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
4137aaa36a97SAlex Deucher {
4138aaa36a97SAlex Deucher 	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
4139aaa36a97SAlex Deucher 	const struct cs_section_def *sect = NULL;
4140aaa36a97SAlex Deucher 	const struct cs_extent_def *ext = NULL;
4141aaa36a97SAlex Deucher 	int r, i;
4142aaa36a97SAlex Deucher 
4143aaa36a97SAlex Deucher 	/* init the CP */
4144aaa36a97SAlex Deucher 	WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
4145aaa36a97SAlex Deucher 	WREG32(mmCP_ENDIAN_SWAP, 0);
4146aaa36a97SAlex Deucher 	WREG32(mmCP_DEVICE_ID, 1);
4147aaa36a97SAlex Deucher 
4148aaa36a97SAlex Deucher 	gfx_v8_0_cp_gfx_enable(adev, true);
4149aaa36a97SAlex Deucher 
4150a27de35cSChristian König 	r = amdgpu_ring_alloc(ring, gfx_v8_0_get_csb_size(adev) + 4);
4151aaa36a97SAlex Deucher 	if (r) {
4152aaa36a97SAlex Deucher 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
4153aaa36a97SAlex Deucher 		return r;
4154aaa36a97SAlex Deucher 	}
4155aaa36a97SAlex Deucher 
4156aaa36a97SAlex Deucher 	/* clear state buffer */
4157aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4158aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4159aaa36a97SAlex Deucher 
4160aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4161aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x80000000);
4162aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x80000000);
4163aaa36a97SAlex Deucher 
4164aaa36a97SAlex Deucher 	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4165aaa36a97SAlex Deucher 		for (ext = sect->section; ext->extent != NULL; ++ext) {
4166aaa36a97SAlex Deucher 			if (sect->id == SECT_CONTEXT) {
4167aaa36a97SAlex Deucher 				amdgpu_ring_write(ring,
4168aaa36a97SAlex Deucher 				       PACKET3(PACKET3_SET_CONTEXT_REG,
4169aaa36a97SAlex Deucher 					       ext->reg_count));
4170aaa36a97SAlex Deucher 				amdgpu_ring_write(ring,
4171aaa36a97SAlex Deucher 				       ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
4172aaa36a97SAlex Deucher 				for (i = 0; i < ext->reg_count; i++)
4173aaa36a97SAlex Deucher 					amdgpu_ring_write(ring, ext->extent[i]);
4174aaa36a97SAlex Deucher 			}
4175aaa36a97SAlex Deucher 		}
4176aaa36a97SAlex Deucher 	}
4177aaa36a97SAlex Deucher 
4178aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4179aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
418093442184SAlex Deucher 	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config);
418193442184SAlex Deucher 	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config_1);
4182aaa36a97SAlex Deucher 
4183aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4184aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4185aaa36a97SAlex Deucher 
4186aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4187aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
4188aaa36a97SAlex Deucher 
4189aaa36a97SAlex Deucher 	/* init the CE partitions */
4190aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4191aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4192aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x8000);
4193aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x8000);
4194aaa36a97SAlex Deucher 
4195a27de35cSChristian König 	amdgpu_ring_commit(ring);
4196aaa36a97SAlex Deucher 
4197aaa36a97SAlex Deucher 	return 0;
4198aaa36a97SAlex Deucher }
gfx_v8_0_set_cpg_door_bell(struct amdgpu_device * adev,struct amdgpu_ring * ring)41994f339b29SRex Zhu static void gfx_v8_0_set_cpg_door_bell(struct amdgpu_device *adev, struct amdgpu_ring *ring)
42004f339b29SRex Zhu {
42014f339b29SRex Zhu 	u32 tmp;
42024f339b29SRex Zhu 	/* no gfx doorbells on iceland */
42034f339b29SRex Zhu 	if (adev->asic_type == CHIP_TOPAZ)
42044f339b29SRex Zhu 		return;
42054f339b29SRex Zhu 
42064f339b29SRex Zhu 	tmp = RREG32(mmCP_RB_DOORBELL_CONTROL);
42074f339b29SRex Zhu 
42084f339b29SRex Zhu 	if (ring->use_doorbell) {
42094f339b29SRex Zhu 		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
42104f339b29SRex Zhu 				DOORBELL_OFFSET, ring->doorbell_index);
42114f339b29SRex Zhu 		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
42124f339b29SRex Zhu 						DOORBELL_HIT, 0);
42134f339b29SRex Zhu 		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
42144f339b29SRex Zhu 					    DOORBELL_EN, 1);
42154f339b29SRex Zhu 	} else {
42164f339b29SRex Zhu 		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, DOORBELL_EN, 0);
42174f339b29SRex Zhu 	}
42184f339b29SRex Zhu 
42194f339b29SRex Zhu 	WREG32(mmCP_RB_DOORBELL_CONTROL, tmp);
42204f339b29SRex Zhu 
42214f339b29SRex Zhu 	if (adev->flags & AMD_IS_APU)
42224f339b29SRex Zhu 		return;
42234f339b29SRex Zhu 
42244f339b29SRex Zhu 	tmp = REG_SET_FIELD(0, CP_RB_DOORBELL_RANGE_LOWER,
42254f339b29SRex Zhu 					DOORBELL_RANGE_LOWER,
42269564f192SOak Zeng 					adev->doorbell_index.gfx_ring0);
42274f339b29SRex Zhu 	WREG32(mmCP_RB_DOORBELL_RANGE_LOWER, tmp);
42284f339b29SRex Zhu 
42294f339b29SRex Zhu 	WREG32(mmCP_RB_DOORBELL_RANGE_UPPER,
42304f339b29SRex Zhu 		CP_RB_DOORBELL_RANGE_UPPER__DOORBELL_RANGE_UPPER_MASK);
42314f339b29SRex Zhu }
4232aaa36a97SAlex Deucher 
gfx_v8_0_cp_gfx_resume(struct amdgpu_device * adev)4233aaa36a97SAlex Deucher static int gfx_v8_0_cp_gfx_resume(struct amdgpu_device *adev)
4234aaa36a97SAlex Deucher {
4235aaa36a97SAlex Deucher 	struct amdgpu_ring *ring;
4236aaa36a97SAlex Deucher 	u32 tmp;
4237aaa36a97SAlex Deucher 	u32 rb_bufsz;
423842e8cb50SFrank Min 	u64 rb_addr, rptr_addr, wptr_gpu_addr;
4239aaa36a97SAlex Deucher 
4240aaa36a97SAlex Deucher 	/* Set the write pointer delay */
4241aaa36a97SAlex Deucher 	WREG32(mmCP_RB_WPTR_DELAY, 0);
4242aaa36a97SAlex Deucher 
4243aaa36a97SAlex Deucher 	/* set the RB to use vmid 0 */
4244aaa36a97SAlex Deucher 	WREG32(mmCP_RB_VMID, 0);
4245aaa36a97SAlex Deucher 
4246aaa36a97SAlex Deucher 	/* Set ring buffer size */
4247aaa36a97SAlex Deucher 	ring = &adev->gfx.gfx_ring[0];
4248aaa36a97SAlex Deucher 	rb_bufsz = order_base_2(ring->ring_size / 8);
4249aaa36a97SAlex Deucher 	tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
4250aaa36a97SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
4251aaa36a97SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MTYPE, 3);
4252aaa36a97SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MIN_IB_AVAILSZ, 1);
4253aaa36a97SAlex Deucher #ifdef __BIG_ENDIAN
4254aaa36a97SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, BUF_SWAP, 1);
4255aaa36a97SAlex Deucher #endif
4256aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_CNTL, tmp);
4257aaa36a97SAlex Deucher 
4258aaa36a97SAlex Deucher 	/* Initialize the ring buffer's read and write pointers */
4259aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_CNTL, tmp | CP_RB0_CNTL__RB_RPTR_WR_ENA_MASK);
4260aaa36a97SAlex Deucher 	ring->wptr = 0;
4261536fbf94SKen Wang 	WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
4262aaa36a97SAlex Deucher 
4263aaa36a97SAlex Deucher 	/* set the wb address wether it's enabled or not */
42643748424bSJack Xiao 	rptr_addr = ring->rptr_gpu_addr;
4265aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_RPTR_ADDR, lower_32_bits(rptr_addr));
4266aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_RPTR_ADDR_HI, upper_32_bits(rptr_addr) & 0xFF);
4267aaa36a97SAlex Deucher 
42683748424bSJack Xiao 	wptr_gpu_addr = ring->wptr_gpu_addr;
426942e8cb50SFrank Min 	WREG32(mmCP_RB_WPTR_POLL_ADDR_LO, lower_32_bits(wptr_gpu_addr));
427042e8cb50SFrank Min 	WREG32(mmCP_RB_WPTR_POLL_ADDR_HI, upper_32_bits(wptr_gpu_addr));
4271aaa36a97SAlex Deucher 	mdelay(1);
4272aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_CNTL, tmp);
4273aaa36a97SAlex Deucher 
4274aaa36a97SAlex Deucher 	rb_addr = ring->gpu_addr >> 8;
4275aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_BASE, rb_addr);
4276aaa36a97SAlex Deucher 	WREG32(mmCP_RB0_BASE_HI, upper_32_bits(rb_addr));
4277aaa36a97SAlex Deucher 
42784f339b29SRex Zhu 	gfx_v8_0_set_cpg_door_bell(adev, ring);
4279aaa36a97SAlex Deucher 	/* start the ring */
4280f6bd7942SMonk Liu 	amdgpu_ring_clear_ring(ring);
4281aaa36a97SAlex Deucher 	gfx_v8_0_cp_gfx_start(adev);
4282aaa36a97SAlex Deucher 
4283c6064de4STiecheng Zhou 	return 0;
4284aaa36a97SAlex Deucher }
4285aaa36a97SAlex Deucher 
gfx_v8_0_cp_compute_enable(struct amdgpu_device * adev,bool enable)4286aaa36a97SAlex Deucher static void gfx_v8_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
4287aaa36a97SAlex Deucher {
4288aaa36a97SAlex Deucher 	if (enable) {
4289aaa36a97SAlex Deucher 		WREG32(mmCP_MEC_CNTL, 0);
4290aaa36a97SAlex Deucher 	} else {
4291aaa36a97SAlex Deucher 		WREG32(mmCP_MEC_CNTL, (CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK));
4292277bd337SLe Ma 		adev->gfx.kiq[0].ring.sched.ready = false;
4293aaa36a97SAlex Deucher 	}
4294aaa36a97SAlex Deucher 	udelay(50);
4295aaa36a97SAlex Deucher }
4296aaa36a97SAlex Deucher 
42974e638ae9SXiangliang Yu /* KIQ functions */
gfx_v8_0_kiq_setting(struct amdgpu_ring * ring)42984e638ae9SXiangliang Yu static void gfx_v8_0_kiq_setting(struct amdgpu_ring *ring)
42994e638ae9SXiangliang Yu {
43004e638ae9SXiangliang Yu 	uint32_t tmp;
43014e638ae9SXiangliang Yu 	struct amdgpu_device *adev = ring->adev;
43024e638ae9SXiangliang Yu 
43034e638ae9SXiangliang Yu 	/* tell RLC which is KIQ queue */
43044e638ae9SXiangliang Yu 	tmp = RREG32(mmRLC_CP_SCHEDULERS);
43054e638ae9SXiangliang Yu 	tmp &= 0xffffff00;
43064e638ae9SXiangliang Yu 	tmp |= (ring->me << 5) | (ring->pipe << 3) | (ring->queue);
43074e638ae9SXiangliang Yu 	WREG32(mmRLC_CP_SCHEDULERS, tmp);
43084e638ae9SXiangliang Yu 	tmp |= 0x80;
43094e638ae9SXiangliang Yu 	WREG32(mmRLC_CP_SCHEDULERS, tmp);
43104e638ae9SXiangliang Yu }
43114e638ae9SXiangliang Yu 
gfx_v8_0_kiq_kcq_enable(struct amdgpu_device * adev)4312346586d5SAlex Deucher static int gfx_v8_0_kiq_kcq_enable(struct amdgpu_device *adev)
43134e638ae9SXiangliang Yu {
4314277bd337SLe Ma 	struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
4315de65513aSAndres Rodriguez 	uint64_t queue_mask = 0;
4316f776952bSAlex Deucher 	int r, i;
4317f776952bSAlex Deucher 
4318de65513aSAndres Rodriguez 	for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
4319be697aa3SLe Ma 		if (!test_bit(i, adev->gfx.mec_bitmap[0].queue_bitmap))
4320de65513aSAndres Rodriguez 			continue;
4321de65513aSAndres Rodriguez 
4322de65513aSAndres Rodriguez 		/* This situation may be hit in the future if a new HW
4323de65513aSAndres Rodriguez 		 * generation exposes more than 64 queues. If so, the
4324de65513aSAndres Rodriguez 		 * definition of queue_mask needs updating */
43251d11ee89SDan Carpenter 		if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
4326de65513aSAndres Rodriguez 			DRM_ERROR("Invalid KCQ enabled: %d\n", i);
4327de65513aSAndres Rodriguez 			break;
43284e638ae9SXiangliang Yu 		}
43294e638ae9SXiangliang Yu 
4330de65513aSAndres Rodriguez 		queue_mask |= (1ull << i);
4331de65513aSAndres Rodriguez 	}
43324e638ae9SXiangliang Yu 
43336c10b5ccSRex Zhu 	r = amdgpu_ring_alloc(kiq_ring, (8 * adev->gfx.num_compute_rings) + 8);
4334f776952bSAlex Deucher 	if (r) {
4335f776952bSAlex Deucher 		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
4336f776952bSAlex Deucher 		return r;
4337f776952bSAlex Deucher 	}
4338346586d5SAlex Deucher 	/* set resources */
4339346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6));
4340346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, 0);	/* vmid_mask:0 queue_type:0 (KIQ) */
4341de65513aSAndres Rodriguez 	amdgpu_ring_write(kiq_ring, lower_32_bits(queue_mask));	/* queue mask lo */
4342de65513aSAndres Rodriguez 	amdgpu_ring_write(kiq_ring, upper_32_bits(queue_mask));	/* queue mask hi */
4343346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, 0);	/* gws mask lo */
4344346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, 0);	/* gws mask hi */
4345346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, 0);	/* oac mask */
4346346586d5SAlex Deucher 	amdgpu_ring_write(kiq_ring, 0);	/* gds heap base:0, gds heap size:0 */
4347c3a49ab5SAlex Deucher 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4348c3a49ab5SAlex Deucher 		struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
4349c3a49ab5SAlex Deucher 		uint64_t mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
43503748424bSJack Xiao 		uint64_t wptr_addr = ring->wptr_gpu_addr;
4351c3a49ab5SAlex Deucher 
4352f776952bSAlex Deucher 		/* map queues */
43534e638ae9SXiangliang Yu 		amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_MAP_QUEUES, 5));
43544e638ae9SXiangliang Yu 		/* Q_sel:0, vmid:0, vidmem: 1, engine:0, num_Q:1*/
43553d7e30b3SAlex Deucher 		amdgpu_ring_write(kiq_ring,
43563d7e30b3SAlex Deucher 				  PACKET3_MAP_QUEUES_NUM_QUEUES(1));
43573d7e30b3SAlex Deucher 		amdgpu_ring_write(kiq_ring,
43583d7e30b3SAlex Deucher 				  PACKET3_MAP_QUEUES_DOORBELL_OFFSET(ring->doorbell_index) |
43593d7e30b3SAlex Deucher 				  PACKET3_MAP_QUEUES_QUEUE(ring->queue) |
43603d7e30b3SAlex Deucher 				  PACKET3_MAP_QUEUES_PIPE(ring->pipe) |
43613d7e30b3SAlex Deucher 				  PACKET3_MAP_QUEUES_ME(ring->me == 1 ? 0 : 1)); /* doorbell */
43624e638ae9SXiangliang Yu 		amdgpu_ring_write(kiq_ring, lower_32_bits(mqd_addr));
43634e638ae9SXiangliang Yu 		amdgpu_ring_write(kiq_ring, upper_32_bits(mqd_addr));
43644e638ae9SXiangliang Yu 		amdgpu_ring_write(kiq_ring, lower_32_bits(wptr_addr));
43654e638ae9SXiangliang Yu 		amdgpu_ring_write(kiq_ring, upper_32_bits(wptr_addr));
4366c3a49ab5SAlex Deucher 	}
4367f776952bSAlex Deucher 
4368c6064de4STiecheng Zhou 	amdgpu_ring_commit(kiq_ring);
4369c6064de4STiecheng Zhou 
4370c6064de4STiecheng Zhou 	return 0;
43714e638ae9SXiangliang Yu }
43724e638ae9SXiangliang Yu 
gfx_v8_0_deactivate_hqd(struct amdgpu_device * adev,u32 req)437334130fb1SAndres Rodriguez static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
437434130fb1SAndres Rodriguez {
437534130fb1SAndres Rodriguez 	int i, r = 0;
437634130fb1SAndres Rodriguez 
437734130fb1SAndres Rodriguez 	if (RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK) {
437834130fb1SAndres Rodriguez 		WREG32_FIELD(CP_HQD_DEQUEUE_REQUEST, DEQUEUE_REQ, req);
437934130fb1SAndres Rodriguez 		for (i = 0; i < adev->usec_timeout; i++) {
438034130fb1SAndres Rodriguez 			if (!(RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
438134130fb1SAndres Rodriguez 				break;
438234130fb1SAndres Rodriguez 			udelay(1);
438334130fb1SAndres Rodriguez 		}
438434130fb1SAndres Rodriguez 		if (i == adev->usec_timeout)
438534130fb1SAndres Rodriguez 			r = -ETIMEDOUT;
438634130fb1SAndres Rodriguez 	}
438734130fb1SAndres Rodriguez 	WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
438834130fb1SAndres Rodriguez 	WREG32(mmCP_HQD_PQ_RPTR, 0);
438934130fb1SAndres Rodriguez 	WREG32(mmCP_HQD_PQ_WPTR, 0);
439034130fb1SAndres Rodriguez 
439134130fb1SAndres Rodriguez 	return r;
43924e638ae9SXiangliang Yu }
43934e638ae9SXiangliang Yu 
gfx_v8_0_mqd_set_priority(struct amdgpu_ring * ring,struct vi_mqd * mqd)439433abcb1fSNirmoy Das static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)
439533abcb1fSNirmoy Das {
439633abcb1fSNirmoy Das 	struct amdgpu_device *adev = ring->adev;
439733abcb1fSNirmoy Das 
439833abcb1fSNirmoy Das 	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
43998c0225d7SNirmoy Das 		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring)) {
440033abcb1fSNirmoy Das 			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
440133abcb1fSNirmoy Das 			mqd->cp_hqd_queue_priority =
440233abcb1fSNirmoy Das 				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
440333abcb1fSNirmoy Das 		}
440433abcb1fSNirmoy Das 	}
440533abcb1fSNirmoy Das }
440633abcb1fSNirmoy Das 
gfx_v8_0_mqd_init(struct amdgpu_ring * ring)4407a2140e00SAlex Deucher static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
44084e638ae9SXiangliang Yu {
4409015c2360SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
4410a2140e00SAlex Deucher 	struct vi_mqd *mqd = ring->mqd_ptr;
44114e638ae9SXiangliang Yu 	uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr;
44124e638ae9SXiangliang Yu 	uint32_t tmp;
44134e638ae9SXiangliang Yu 
44144e638ae9SXiangliang Yu 	mqd->header = 0xC0310800;
44154e638ae9SXiangliang Yu 	mqd->compute_pipelinestat_enable = 0x00000001;
44164e638ae9SXiangliang Yu 	mqd->compute_static_thread_mgmt_se0 = 0xffffffff;
44174e638ae9SXiangliang Yu 	mqd->compute_static_thread_mgmt_se1 = 0xffffffff;
44184e638ae9SXiangliang Yu 	mqd->compute_static_thread_mgmt_se2 = 0xffffffff;
44194e638ae9SXiangliang Yu 	mqd->compute_static_thread_mgmt_se3 = 0xffffffff;
44204e638ae9SXiangliang Yu 	mqd->compute_misc_reserved = 0x00000003;
44216b0fa871SRex Zhu 	mqd->dynamic_cu_mask_addr_lo = lower_32_bits(ring->mqd_gpu_addr
44222d6fb105SAlex Deucher 						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
44236b0fa871SRex Zhu 	mqd->dynamic_cu_mask_addr_hi = upper_32_bits(ring->mqd_gpu_addr
44242d6fb105SAlex Deucher 						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
442534534610SAlex Deucher 	eop_base_addr = ring->eop_gpu_addr >> 8;
44264e638ae9SXiangliang Yu 	mqd->cp_hqd_eop_base_addr_lo = eop_base_addr;
44274e638ae9SXiangliang Yu 	mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(eop_base_addr);
44284e638ae9SXiangliang Yu 
44294e638ae9SXiangliang Yu 	/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
44304e638ae9SXiangliang Yu 	tmp = RREG32(mmCP_HQD_EOP_CONTROL);
44314e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_EOP_CONTROL, EOP_SIZE,
4432268cb4c7SAndres Rodriguez 			(order_base_2(GFX8_MEC_HPD_SIZE / 4) - 1));
44334e638ae9SXiangliang Yu 
44344e638ae9SXiangliang Yu 	mqd->cp_hqd_eop_control = tmp;
44354e638ae9SXiangliang Yu 
44364e638ae9SXiangliang Yu 	/* enable doorbell? */
4437bb215962STom St Denis 	tmp = REG_SET_FIELD(RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL),
4438bb215962STom St Denis 			    CP_HQD_PQ_DOORBELL_CONTROL,
4439bb215962STom St Denis 			    DOORBELL_EN,
4440bb215962STom St Denis 			    ring->use_doorbell ? 1 : 0);
44414e638ae9SXiangliang Yu 
44424e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_doorbell_control = tmp;
44434e638ae9SXiangliang Yu 
44444e638ae9SXiangliang Yu 	/* set the pointer to the MQD */
4445015c2360SAlex Deucher 	mqd->cp_mqd_base_addr_lo = ring->mqd_gpu_addr & 0xfffffffc;
4446015c2360SAlex Deucher 	mqd->cp_mqd_base_addr_hi = upper_32_bits(ring->mqd_gpu_addr);
44474e638ae9SXiangliang Yu 
44484e638ae9SXiangliang Yu 	/* set MQD vmid to 0 */
44494e638ae9SXiangliang Yu 	tmp = RREG32(mmCP_MQD_CONTROL);
44504e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_MQD_CONTROL, VMID, 0);
44514e638ae9SXiangliang Yu 	mqd->cp_mqd_control = tmp;
44524e638ae9SXiangliang Yu 
44534e638ae9SXiangliang Yu 	/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
44544e638ae9SXiangliang Yu 	hqd_gpu_addr = ring->gpu_addr >> 8;
44554e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_base_lo = hqd_gpu_addr;
44564e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
44574e638ae9SXiangliang Yu 
44584e638ae9SXiangliang Yu 	/* set up the HQD, this is similar to CP_RB0_CNTL */
44594e638ae9SXiangliang Yu 	tmp = RREG32(mmCP_HQD_PQ_CONTROL);
44604e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, QUEUE_SIZE,
44614e638ae9SXiangliang Yu 			    (order_base_2(ring->ring_size / 4) - 1));
44624e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE,
446384203554SHaohui Mai 			(order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1));
44644e638ae9SXiangliang Yu #ifdef __BIG_ENDIAN
44654e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1);
44664e638ae9SXiangliang Yu #endif
44674e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
44684e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ROQ_PQ_IB_FLIP, 0);
44694e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
44704e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
44714e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_control = tmp;
44724e638ae9SXiangliang Yu 
44734e638ae9SXiangliang Yu 	/* set the wb address whether it's enabled or not */
44743748424bSJack Xiao 	wb_gpu_addr = ring->rptr_gpu_addr;
44754e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr & 0xfffffffc;
44764e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_rptr_report_addr_hi =
44774e638ae9SXiangliang Yu 		upper_32_bits(wb_gpu_addr) & 0xffff;
44784e638ae9SXiangliang Yu 
44794e638ae9SXiangliang Yu 	/* only used if CP_PQ_WPTR_POLL_CNTL.CP_PQ_WPTR_POLL_CNTL__EN_MASK=1 */
44803748424bSJack Xiao 	wb_gpu_addr = ring->wptr_gpu_addr;
44814e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_wptr_poll_addr_lo = wb_gpu_addr & 0xfffffffc;
44824e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
44834e638ae9SXiangliang Yu 
44844e638ae9SXiangliang Yu 	tmp = 0;
44854e638ae9SXiangliang Yu 	/* enable the doorbell if requested */
44864e638ae9SXiangliang Yu 	if (ring->use_doorbell) {
44874e638ae9SXiangliang Yu 		tmp = RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
44884e638ae9SXiangliang Yu 		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
44894e638ae9SXiangliang Yu 				DOORBELL_OFFSET, ring->doorbell_index);
44904e638ae9SXiangliang Yu 
44914e638ae9SXiangliang Yu 		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
44924e638ae9SXiangliang Yu 					 DOORBELL_EN, 1);
44934e638ae9SXiangliang Yu 		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
44944e638ae9SXiangliang Yu 					 DOORBELL_SOURCE, 0);
44954e638ae9SXiangliang Yu 		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
44964e638ae9SXiangliang Yu 					 DOORBELL_HIT, 0);
44974e638ae9SXiangliang Yu 	}
44984e638ae9SXiangliang Yu 
44994e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_doorbell_control = tmp;
45004e638ae9SXiangliang Yu 
45014e638ae9SXiangliang Yu 	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
45024e638ae9SXiangliang Yu 	ring->wptr = 0;
45034e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_wptr = ring->wptr;
45044e638ae9SXiangliang Yu 	mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
45054e638ae9SXiangliang Yu 
45064e638ae9SXiangliang Yu 	/* set the vmid for the queue */
45074e638ae9SXiangliang Yu 	mqd->cp_hqd_vmid = 0;
45084e638ae9SXiangliang Yu 
45094e638ae9SXiangliang Yu 	tmp = RREG32(mmCP_HQD_PERSISTENT_STATE);
45104e638ae9SXiangliang Yu 	tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53);
45114e638ae9SXiangliang Yu 	mqd->cp_hqd_persistent_state = tmp;
45124e638ae9SXiangliang Yu 
4513ed6f55d1SAlex Deucher 	/* set MTYPE */
4514ed6f55d1SAlex Deucher 	tmp = RREG32(mmCP_HQD_IB_CONTROL);
4515ed6f55d1SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
4516ed6f55d1SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MTYPE, 3);
4517ed6f55d1SAlex Deucher 	mqd->cp_hqd_ib_control = tmp;
4518ed6f55d1SAlex Deucher 
4519ed6f55d1SAlex Deucher 	tmp = RREG32(mmCP_HQD_IQ_TIMER);
4520ed6f55d1SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_HQD_IQ_TIMER, MTYPE, 3);
4521ed6f55d1SAlex Deucher 	mqd->cp_hqd_iq_timer = tmp;
4522ed6f55d1SAlex Deucher 
4523ed6f55d1SAlex Deucher 	tmp = RREG32(mmCP_HQD_CTX_SAVE_CONTROL);
4524ed6f55d1SAlex Deucher 	tmp = REG_SET_FIELD(tmp, CP_HQD_CTX_SAVE_CONTROL, MTYPE, 3);
4525ed6f55d1SAlex Deucher 	mqd->cp_hqd_ctx_save_control = tmp;
4526ed6f55d1SAlex Deucher 
452797bf47b2SAndres Rodriguez 	/* defaults */
452897bf47b2SAndres Rodriguez 	mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
452997bf47b2SAndres Rodriguez 	mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
453097bf47b2SAndres Rodriguez 	mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
453197bf47b2SAndres Rodriguez 	mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
453297bf47b2SAndres Rodriguez 	mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
453397bf47b2SAndres Rodriguez 	mqd->cp_hqd_cntl_stack_size = RREG32(mmCP_HQD_CNTL_STACK_SIZE);
453497bf47b2SAndres Rodriguez 	mqd->cp_hqd_wg_state_offset = RREG32(mmCP_HQD_WG_STATE_OFFSET);
453597bf47b2SAndres Rodriguez 	mqd->cp_hqd_ctx_save_size = RREG32(mmCP_HQD_CTX_SAVE_SIZE);
453697bf47b2SAndres Rodriguez 	mqd->cp_hqd_eop_done_events = RREG32(mmCP_HQD_EOP_EVENTS);
453797bf47b2SAndres Rodriguez 	mqd->cp_hqd_error = RREG32(mmCP_HQD_ERROR);
453897bf47b2SAndres Rodriguez 	mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
453997bf47b2SAndres Rodriguez 	mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
454097bf47b2SAndres Rodriguez 
454133abcb1fSNirmoy Das 	/* set static priority for a queue/ring */
454233abcb1fSNirmoy Das 	gfx_v8_0_mqd_set_priority(ring, mqd);
454333abcb1fSNirmoy Das 	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
454433abcb1fSNirmoy Das 
45450e5b7a95SHuang Rui 	/* map_queues packet doesn't need activate the queue,
45460e5b7a95SHuang Rui 	 * so only kiq need set this field.
45470e5b7a95SHuang Rui 	 */
45480e5b7a95SHuang Rui 	if (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)
45494e638ae9SXiangliang Yu 		mqd->cp_hqd_active = 1;
45504e638ae9SXiangliang Yu 
45514e638ae9SXiangliang Yu 	return 0;
45524e638ae9SXiangliang Yu }
45534e638ae9SXiangliang Yu 
gfx_v8_0_mqd_commit(struct amdgpu_device * adev,struct vi_mqd * mqd)4554f3167919SNirmoy Das static int gfx_v8_0_mqd_commit(struct amdgpu_device *adev,
455597bf47b2SAndres Rodriguez 			struct vi_mqd *mqd)
45564e638ae9SXiangliang Yu {
4557894700f3SAndres Rodriguez 	uint32_t mqd_reg;
4558894700f3SAndres Rodriguez 	uint32_t *mqd_data;
4559894700f3SAndres Rodriguez 
4560894700f3SAndres Rodriguez 	/* HQD registers extend from mmCP_MQD_BASE_ADDR to mmCP_HQD_ERROR */
4561894700f3SAndres Rodriguez 	mqd_data = &mqd->cp_mqd_base_addr_lo;
45624e638ae9SXiangliang Yu 
45634e638ae9SXiangliang Yu 	/* disable wptr polling */
45640ac642c5STom St Denis 	WREG32_FIELD(CP_PQ_WPTR_POLL_CNTL, EN, 0);
45654e638ae9SXiangliang Yu 
4566894700f3SAndres Rodriguez 	/* program all HQD registers */
4567ecd910ebSAndres Rodriguez 	for (mqd_reg = mmCP_HQD_VMID; mqd_reg <= mmCP_HQD_EOP_CONTROL; mqd_reg++)
4568ecd910ebSAndres Rodriguez 		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
45694e638ae9SXiangliang Yu 
4570ecd910ebSAndres Rodriguez 	/* Tonga errata: EOP RPTR/WPTR should be left unmodified.
4571ecd910ebSAndres Rodriguez 	 * This is safe since EOP RPTR==WPTR for any inactive HQD
4572ecd910ebSAndres Rodriguez 	 * on ASICs that do not support context-save.
4573ecd910ebSAndres Rodriguez 	 * EOP writes/reads can start anywhere in the ring.
4574ecd910ebSAndres Rodriguez 	 */
4575ecd910ebSAndres Rodriguez 	if (adev->asic_type != CHIP_TONGA) {
4576ecd910ebSAndres Rodriguez 		WREG32(mmCP_HQD_EOP_RPTR, mqd->cp_hqd_eop_rptr);
4577ecd910ebSAndres Rodriguez 		WREG32(mmCP_HQD_EOP_WPTR, mqd->cp_hqd_eop_wptr);
4578ecd910ebSAndres Rodriguez 		WREG32(mmCP_HQD_EOP_WPTR_MEM, mqd->cp_hqd_eop_wptr_mem);
45794e638ae9SXiangliang Yu 	}
45804e638ae9SXiangliang Yu 
4581ecd910ebSAndres Rodriguez 	for (mqd_reg = mmCP_HQD_EOP_EVENTS; mqd_reg <= mmCP_HQD_ERROR; mqd_reg++)
4582894700f3SAndres Rodriguez 		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
45834e638ae9SXiangliang Yu 
4584894700f3SAndres Rodriguez 	/* activate the HQD */
4585894700f3SAndres Rodriguez 	for (mqd_reg = mmCP_MQD_BASE_ADDR; mqd_reg <= mmCP_HQD_ACTIVE; mqd_reg++)
4586894700f3SAndres Rodriguez 		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
45874e638ae9SXiangliang Yu 
45884e638ae9SXiangliang Yu 	return 0;
45894e638ae9SXiangliang Yu }
45904e638ae9SXiangliang Yu 
gfx_v8_0_kiq_init_queue(struct amdgpu_ring * ring)4591a2140e00SAlex Deucher static int gfx_v8_0_kiq_init_queue(struct amdgpu_ring *ring)
45924e638ae9SXiangliang Yu {
45934e638ae9SXiangliang Yu 	struct amdgpu_device *adev = ring->adev;
4594a2140e00SAlex Deucher 	struct vi_mqd *mqd = ring->mqd_ptr;
45954e638ae9SXiangliang Yu 
459639300115SAlex Deucher 	gfx_v8_0_kiq_setting(ring);
45974e638ae9SXiangliang Yu 
459853b3f8f4SDennis Li 	if (amdgpu_in_reset(adev)) { /* for GPU_RESET case */
45991fb37a3dSMonk Liu 		/* reset MQD to a clean status */
4600def799c6SLe Ma 		if (adev->gfx.kiq[0].mqd_backup)
4601def799c6SLe Ma 			memcpy(mqd, adev->gfx.kiq[0].mqd_backup, sizeof(struct vi_mqd_allocation));
46021fb37a3dSMonk Liu 
46031fb37a3dSMonk Liu 		/* reset ring buffer */
46041fb37a3dSMonk Liu 		ring->wptr = 0;
46051fb37a3dSMonk Liu 		amdgpu_ring_clear_ring(ring);
46061fb37a3dSMonk Liu 		mutex_lock(&adev->srbm_mutex);
46071fb37a3dSMonk Liu 		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
460897bf47b2SAndres Rodriguez 		gfx_v8_0_mqd_commit(adev, mqd);
46091fb37a3dSMonk Liu 		vi_srbm_select(adev, 0, 0, 0, 0);
46101fb37a3dSMonk Liu 		mutex_unlock(&adev->srbm_mutex);
4611a545e491SAlex Deucher 	} else {
46126b0fa871SRex Zhu 		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
46132d6fb105SAlex Deucher 		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
46142d6fb105SAlex Deucher 		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
4615ec4927d4SVictor Zhao 		if (amdgpu_sriov_vf(adev) && adev->in_suspend)
4616ec4927d4SVictor Zhao 			amdgpu_ring_clear_ring(ring);
4617a545e491SAlex Deucher 		mutex_lock(&adev->srbm_mutex);
4618a545e491SAlex Deucher 		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4619a545e491SAlex Deucher 		gfx_v8_0_mqd_init(ring);
462097bf47b2SAndres Rodriguez 		gfx_v8_0_mqd_commit(adev, mqd);
4621a545e491SAlex Deucher 		vi_srbm_select(adev, 0, 0, 0, 0);
4622a545e491SAlex Deucher 		mutex_unlock(&adev->srbm_mutex);
4623a545e491SAlex Deucher 
4624def799c6SLe Ma 		if (adev->gfx.kiq[0].mqd_backup)
4625def799c6SLe Ma 			memcpy(adev->gfx.kiq[0].mqd_backup, mqd, sizeof(struct vi_mqd_allocation));
46261fb37a3dSMonk Liu 	}
46271fb37a3dSMonk Liu 
4628dcf75843SAlex Deucher 	return 0;
46294e638ae9SXiangliang Yu }
46304e638ae9SXiangliang Yu 
gfx_v8_0_kcq_init_queue(struct amdgpu_ring * ring)463139300115SAlex Deucher static int gfx_v8_0_kcq_init_queue(struct amdgpu_ring *ring)
463239300115SAlex Deucher {
463339300115SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
463439300115SAlex Deucher 	struct vi_mqd *mqd = ring->mqd_ptr;
463539300115SAlex Deucher 	int mqd_idx = ring - &adev->gfx.compute_ring[0];
463639300115SAlex Deucher 
463753b3f8f4SDennis Li 	if (!amdgpu_in_reset(adev) && !adev->in_suspend) {
46386b0fa871SRex Zhu 		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
46392d6fb105SAlex Deucher 		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
46402d6fb105SAlex Deucher 		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
464139300115SAlex Deucher 		mutex_lock(&adev->srbm_mutex);
464239300115SAlex Deucher 		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
464339300115SAlex Deucher 		gfx_v8_0_mqd_init(ring);
464439300115SAlex Deucher 		vi_srbm_select(adev, 0, 0, 0, 0);
464539300115SAlex Deucher 		mutex_unlock(&adev->srbm_mutex);
464639300115SAlex Deucher 
464739300115SAlex Deucher 		if (adev->gfx.mec.mqd_backup[mqd_idx])
46486b0fa871SRex Zhu 			memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
464942cdf6f6SAlex Deucher 	} else {
465042cdf6f6SAlex Deucher 		/* restore MQD to a clean status */
465139300115SAlex Deucher 		if (adev->gfx.mec.mqd_backup[mqd_idx])
46526b0fa871SRex Zhu 			memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
4653062d2e6aSAndrey Grodzovsky 		/* reset ring buffer */
4654062d2e6aSAndrey Grodzovsky 		ring->wptr = 0;
4655062d2e6aSAndrey Grodzovsky 		amdgpu_ring_clear_ring(ring);
465639300115SAlex Deucher 	}
46574e638ae9SXiangliang Yu 	return 0;
46584e638ae9SXiangliang Yu }
46594e638ae9SXiangliang Yu 
gfx_v8_0_set_mec_doorbell_range(struct amdgpu_device * adev)46604f339b29SRex Zhu static void gfx_v8_0_set_mec_doorbell_range(struct amdgpu_device *adev)
46614f339b29SRex Zhu {
46624f339b29SRex Zhu 	if (adev->asic_type > CHIP_TONGA) {
46639564f192SOak Zeng 		WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER, adev->doorbell_index.kiq << 2);
46649564f192SOak Zeng 		WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER, adev->doorbell_index.mec_ring7 << 2);
46654f339b29SRex Zhu 	}
46666a124e67SAlex Deucher 	/* enable doorbells */
46676a124e67SAlex Deucher 	WREG32_FIELD(CP_PQ_STATUS, DOORBELL_ENABLE, 1);
46684f339b29SRex Zhu }
46694f339b29SRex Zhu 
gfx_v8_0_kiq_resume(struct amdgpu_device * adev)46704e638ae9SXiangliang Yu static int gfx_v8_0_kiq_resume(struct amdgpu_device *adev)
46714e638ae9SXiangliang Yu {
467236859cd5SRex Zhu 	struct amdgpu_ring *ring;
467336859cd5SRex Zhu 	int r;
46744e638ae9SXiangliang Yu 
4675277bd337SLe Ma 	ring = &adev->gfx.kiq[0].ring;
46766a6f380fSAlex Deucher 
46776a6f380fSAlex Deucher 	r = amdgpu_bo_reserve(ring->mqd_obj, false);
46786a6f380fSAlex Deucher 	if (unlikely(r != 0))
467936859cd5SRex Zhu 		return r;
46806a6f380fSAlex Deucher 
46816a6f380fSAlex Deucher 	r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
4682609d8300SSukrut Bellary 	if (unlikely(r != 0)) {
4683609d8300SSukrut Bellary 		amdgpu_bo_unreserve(ring->mqd_obj);
468436859cd5SRex Zhu 		return r;
4685609d8300SSukrut Bellary 	}
468636859cd5SRex Zhu 
468736859cd5SRex Zhu 	gfx_v8_0_kiq_init_queue(ring);
4688596c67d0SMonk Liu 	amdgpu_bo_kunmap(ring->mqd_obj);
46891fb37a3dSMonk Liu 	ring->mqd_ptr = NULL;
46906a6f380fSAlex Deucher 	amdgpu_bo_unreserve(ring->mqd_obj);
469136859cd5SRex Zhu 	return 0;
469236859cd5SRex Zhu }
469336859cd5SRex Zhu 
gfx_v8_0_kcq_resume(struct amdgpu_device * adev)469436859cd5SRex Zhu static int gfx_v8_0_kcq_resume(struct amdgpu_device *adev)
469536859cd5SRex Zhu {
469636859cd5SRex Zhu 	struct amdgpu_ring *ring = NULL;
469736859cd5SRex Zhu 	int r = 0, i;
469836859cd5SRex Zhu 
469936859cd5SRex Zhu 	gfx_v8_0_cp_compute_enable(adev, true);
47004e638ae9SXiangliang Yu 
4701596c67d0SMonk Liu 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4702596c67d0SMonk Liu 		ring = &adev->gfx.compute_ring[i];
47036a6f380fSAlex Deucher 
47046a6f380fSAlex Deucher 		r = amdgpu_bo_reserve(ring->mqd_obj, false);
47056a6f380fSAlex Deucher 		if (unlikely(r != 0))
47066a6f380fSAlex Deucher 			goto done;
47076a6f380fSAlex Deucher 		r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
47086a6f380fSAlex Deucher 		if (!r) {
470939300115SAlex Deucher 			r = gfx_v8_0_kcq_init_queue(ring);
4710596c67d0SMonk Liu 			amdgpu_bo_kunmap(ring->mqd_obj);
47111fb37a3dSMonk Liu 			ring->mqd_ptr = NULL;
4712596c67d0SMonk Liu 		}
47136a6f380fSAlex Deucher 		amdgpu_bo_unreserve(ring->mqd_obj);
47146a6f380fSAlex Deucher 		if (r)
47156a6f380fSAlex Deucher 			goto done;
4716c3a49ab5SAlex Deucher 	}
47174e638ae9SXiangliang Yu 
47184f339b29SRex Zhu 	gfx_v8_0_set_mec_doorbell_range(adev);
4719d17c0fafSAlex Deucher 
4720346586d5SAlex Deucher 	r = gfx_v8_0_kiq_kcq_enable(adev);
4721c3a49ab5SAlex Deucher 	if (r)
4722c3a49ab5SAlex Deucher 		goto done;
4723c3a49ab5SAlex Deucher 
47246a6f380fSAlex Deucher done:
47256a6f380fSAlex Deucher 	return r;
47264e638ae9SXiangliang Yu }
47274e638ae9SXiangliang Yu 
gfx_v8_0_cp_test_all_rings(struct amdgpu_device * adev)4728c6064de4STiecheng Zhou static int gfx_v8_0_cp_test_all_rings(struct amdgpu_device *adev)
4729c6064de4STiecheng Zhou {
4730c6064de4STiecheng Zhou 	int r, i;
4731c6064de4STiecheng Zhou 	struct amdgpu_ring *ring;
4732c6064de4STiecheng Zhou 
4733c6064de4STiecheng Zhou 	/* collect all the ring_tests here, gfx, kiq, compute */
4734c6064de4STiecheng Zhou 	ring = &adev->gfx.gfx_ring[0];
4735c6064de4STiecheng Zhou 	r = amdgpu_ring_test_helper(ring);
4736c6064de4STiecheng Zhou 	if (r)
4737c6064de4STiecheng Zhou 		return r;
4738c6064de4STiecheng Zhou 
4739277bd337SLe Ma 	ring = &adev->gfx.kiq[0].ring;
4740c6064de4STiecheng Zhou 	r = amdgpu_ring_test_helper(ring);
4741c6064de4STiecheng Zhou 	if (r)
4742c6064de4STiecheng Zhou 		return r;
4743c6064de4STiecheng Zhou 
4744c6064de4STiecheng Zhou 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4745c6064de4STiecheng Zhou 		ring = &adev->gfx.compute_ring[i];
4746c6064de4STiecheng Zhou 		amdgpu_ring_test_helper(ring);
4747c6064de4STiecheng Zhou 	}
4748c6064de4STiecheng Zhou 
4749c6064de4STiecheng Zhou 	return 0;
4750c6064de4STiecheng Zhou }
4751c6064de4STiecheng Zhou 
gfx_v8_0_cp_resume(struct amdgpu_device * adev)4752aaa36a97SAlex Deucher static int gfx_v8_0_cp_resume(struct amdgpu_device *adev)
4753aaa36a97SAlex Deucher {
4754aaa36a97SAlex Deucher 	int r;
4755aaa36a97SAlex Deucher 
4756e3c7656cSSamuel Li 	if (!(adev->flags & AMD_IS_APU))
4757aaa36a97SAlex Deucher 		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4758aaa36a97SAlex Deucher 
47594e638ae9SXiangliang Yu 	r = gfx_v8_0_kiq_resume(adev);
4760aaa36a97SAlex Deucher 	if (r)
4761aaa36a97SAlex Deucher 		return r;
4762aaa36a97SAlex Deucher 
476336859cd5SRex Zhu 	r = gfx_v8_0_cp_gfx_resume(adev);
476436859cd5SRex Zhu 	if (r)
476536859cd5SRex Zhu 		return r;
476636859cd5SRex Zhu 
476736859cd5SRex Zhu 	r = gfx_v8_0_kcq_resume(adev);
476836859cd5SRex Zhu 	if (r)
476936859cd5SRex Zhu 		return r;
4770c6064de4STiecheng Zhou 
4771c6064de4STiecheng Zhou 	r = gfx_v8_0_cp_test_all_rings(adev);
4772c6064de4STiecheng Zhou 	if (r)
4773c6064de4STiecheng Zhou 		return r;
4774c6064de4STiecheng Zhou 
4775aaa36a97SAlex Deucher 	gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4776aaa36a97SAlex Deucher 
4777aaa36a97SAlex Deucher 	return 0;
4778aaa36a97SAlex Deucher }
4779aaa36a97SAlex Deucher 
gfx_v8_0_cp_enable(struct amdgpu_device * adev,bool enable)4780aaa36a97SAlex Deucher static void gfx_v8_0_cp_enable(struct amdgpu_device *adev, bool enable)
4781aaa36a97SAlex Deucher {
4782aaa36a97SAlex Deucher 	gfx_v8_0_cp_gfx_enable(adev, enable);
4783aaa36a97SAlex Deucher 	gfx_v8_0_cp_compute_enable(adev, enable);
4784aaa36a97SAlex Deucher }
4785aaa36a97SAlex Deucher 
gfx_v8_0_hw_init(void * handle)47865fc3aeebSyanyang1 static int gfx_v8_0_hw_init(void *handle)
4787aaa36a97SAlex Deucher {
4788aaa36a97SAlex Deucher 	int r;
47895fc3aeebSyanyang1 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4790aaa36a97SAlex Deucher 
4791aaa36a97SAlex Deucher 	gfx_v8_0_init_golden_registers(adev);
4792434e6df2SRex Zhu 	gfx_v8_0_constants_init(adev);
4793aaa36a97SAlex Deucher 
4794fdb81fd7SLikun Gao 	r = adev->gfx.rlc.funcs->resume(adev);
4795aaa36a97SAlex Deucher 	if (r)
4796aaa36a97SAlex Deucher 		return r;
4797aaa36a97SAlex Deucher 
4798aaa36a97SAlex Deucher 	r = gfx_v8_0_cp_resume(adev);
4799aaa36a97SAlex Deucher 
4800aaa36a97SAlex Deucher 	return r;
4801aaa36a97SAlex Deucher }
4802aaa36a97SAlex Deucher 
gfx_v8_0_kcq_disable(struct amdgpu_device * adev)4803a62a49e5SRex Zhu static int gfx_v8_0_kcq_disable(struct amdgpu_device *adev)
480485f95ad6SMonk Liu {
4805a62a49e5SRex Zhu 	int r, i;
4806277bd337SLe Ma 	struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
480785f95ad6SMonk Liu 
4808a62a49e5SRex Zhu 	r = amdgpu_ring_alloc(kiq_ring, 6 * adev->gfx.num_compute_rings);
48096c10b5ccSRex Zhu 	if (r)
481085f95ad6SMonk Liu 		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
481185f95ad6SMonk Liu 
4812a62a49e5SRex Zhu 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4813a62a49e5SRex Zhu 		struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
4814a62a49e5SRex Zhu 
481585f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_UNMAP_QUEUES, 4));
481685f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, /* Q_sel: 0, vmid: 0, engine: 0, num_Q: 1 */
481785f95ad6SMonk Liu 						PACKET3_UNMAP_QUEUES_ACTION(1) | /* RESET_QUEUES */
481885f95ad6SMonk Liu 						PACKET3_UNMAP_QUEUES_QUEUE_SEL(0) |
481985f95ad6SMonk Liu 						PACKET3_UNMAP_QUEUES_ENGINE_SEL(0) |
482085f95ad6SMonk Liu 						PACKET3_UNMAP_QUEUES_NUM_QUEUES(1));
482185f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, PACKET3_UNMAP_QUEUES_DOORBELL_OFFSET0(ring->doorbell_index));
482285f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, 0);
482385f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, 0);
482485f95ad6SMonk Liu 		amdgpu_ring_write(kiq_ring, 0);
4825a62a49e5SRex Zhu 	}
4826c66ed765SAndrey Grodzovsky 	r = amdgpu_ring_test_helper(kiq_ring);
48276c10b5ccSRex Zhu 	if (r)
48286c10b5ccSRex Zhu 		DRM_ERROR("KCQ disable failed\n");
48296c10b5ccSRex Zhu 
483085f95ad6SMonk Liu 	return r;
483185f95ad6SMonk Liu }
483285f95ad6SMonk Liu 
gfx_v8_0_is_idle(void * handle)48335d944aaaSRex Zhu static bool gfx_v8_0_is_idle(void *handle)
48345d944aaaSRex Zhu {
48355d944aaaSRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
48365d944aaaSRex Zhu 
48375d944aaaSRex Zhu 	if (REG_GET_FIELD(RREG32(mmGRBM_STATUS), GRBM_STATUS, GUI_ACTIVE)
48385d944aaaSRex Zhu 		|| RREG32(mmGRBM_STATUS2) != 0x8)
48395d944aaaSRex Zhu 		return false;
48405d944aaaSRex Zhu 	else
48415d944aaaSRex Zhu 		return true;
48425d944aaaSRex Zhu }
48435d944aaaSRex Zhu 
gfx_v8_0_rlc_is_idle(void * handle)48445d944aaaSRex Zhu static bool gfx_v8_0_rlc_is_idle(void *handle)
48455d944aaaSRex Zhu {
48465d944aaaSRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
48475d944aaaSRex Zhu 
48485d944aaaSRex Zhu 	if (RREG32(mmGRBM_STATUS2) != 0x8)
48495d944aaaSRex Zhu 		return false;
48505d944aaaSRex Zhu 	else
48515d944aaaSRex Zhu 		return true;
48525d944aaaSRex Zhu }
48535d944aaaSRex Zhu 
gfx_v8_0_wait_for_rlc_idle(void * handle)48545d944aaaSRex Zhu static int gfx_v8_0_wait_for_rlc_idle(void *handle)
48555d944aaaSRex Zhu {
48565d944aaaSRex Zhu 	unsigned int i;
48575d944aaaSRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
48585d944aaaSRex Zhu 
48595d944aaaSRex Zhu 	for (i = 0; i < adev->usec_timeout; i++) {
48605d944aaaSRex Zhu 		if (gfx_v8_0_rlc_is_idle(handle))
48615d944aaaSRex Zhu 			return 0;
48625d944aaaSRex Zhu 
48635d944aaaSRex Zhu 		udelay(1);
48645d944aaaSRex Zhu 	}
48655d944aaaSRex Zhu 	return -ETIMEDOUT;
48665d944aaaSRex Zhu }
48675d944aaaSRex Zhu 
gfx_v8_0_wait_for_idle(void * handle)48685d944aaaSRex Zhu static int gfx_v8_0_wait_for_idle(void *handle)
48695d944aaaSRex Zhu {
48705d944aaaSRex Zhu 	unsigned int i;
48715d944aaaSRex Zhu 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
48725d944aaaSRex Zhu 
48735d944aaaSRex Zhu 	for (i = 0; i < adev->usec_timeout; i++) {
48745d944aaaSRex Zhu 		if (gfx_v8_0_is_idle(handle))
48755d944aaaSRex Zhu 			return 0;
48765d944aaaSRex Zhu 
48775d944aaaSRex Zhu 		udelay(1);
48785d944aaaSRex Zhu 	}
48795d944aaaSRex Zhu 	return -ETIMEDOUT;
48805d944aaaSRex Zhu }
48815d944aaaSRex Zhu 
gfx_v8_0_hw_fini(void * handle)48825fc3aeebSyanyang1 static int gfx_v8_0_hw_fini(void *handle)
4883aaa36a97SAlex Deucher {
48845fc3aeebSyanyang1 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
48855fc3aeebSyanyang1 
48861d22a454SAlex Deucher 	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
48871d22a454SAlex Deucher 	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
488885f95ad6SMonk Liu 
48895a2f2913SDavid Panariti 	amdgpu_irq_put(adev, &adev->gfx.cp_ecc_error_irq, 0);
48905a2f2913SDavid Panariti 
489104ad26bbSDavid Panariti 	amdgpu_irq_put(adev, &adev->gfx.sq_irq, 0);
489204ad26bbSDavid Panariti 
489385f95ad6SMonk Liu 	/* disable KCQ to avoid CPC touch memory not valid anymore */
4894a62a49e5SRex Zhu 	gfx_v8_0_kcq_disable(adev);
489585f95ad6SMonk Liu 
489684f3f05bSXiangliang Yu 	if (amdgpu_sriov_vf(adev)) {
489784f3f05bSXiangliang Yu 		pr_debug("For SRIOV client, shouldn't do anything.\n");
489884f3f05bSXiangliang Yu 		return 0;
489984f3f05bSXiangliang Yu 	}
490086b20703SLe Ma 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
49015d944aaaSRex Zhu 	if (!gfx_v8_0_wait_for_idle(adev))
4902aaa36a97SAlex Deucher 		gfx_v8_0_cp_enable(adev, false);
49035d944aaaSRex Zhu 	else
49045d944aaaSRex Zhu 		pr_err("cp is busy, skip halt cp\n");
49055d944aaaSRex Zhu 	if (!gfx_v8_0_wait_for_rlc_idle(adev))
4906fdb81fd7SLikun Gao 		adev->gfx.rlc.funcs->stop(adev);
49075d944aaaSRex Zhu 	else
49085d944aaaSRex Zhu 		pr_err("rlc is busy, skip halt rlc\n");
490986b20703SLe Ma 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
49101f288afcSLikun Gao 
4911aaa36a97SAlex Deucher 	return 0;
4912aaa36a97SAlex Deucher }
4913aaa36a97SAlex Deucher 
gfx_v8_0_suspend(void * handle)49145fc3aeebSyanyang1 static int gfx_v8_0_suspend(void *handle)
4915aaa36a97SAlex Deucher {
491644779b43SRex Zhu 	return gfx_v8_0_hw_fini(handle);
4917aaa36a97SAlex Deucher }
4918aaa36a97SAlex Deucher 
gfx_v8_0_resume(void * handle)49195fc3aeebSyanyang1 static int gfx_v8_0_resume(void *handle)
4920aaa36a97SAlex Deucher {
492144779b43SRex Zhu 	return gfx_v8_0_hw_init(handle);
4922aaa36a97SAlex Deucher }
4923aaa36a97SAlex Deucher 
gfx_v8_0_check_soft_reset(void * handle)4924da146d3bSAlex Deucher static bool gfx_v8_0_check_soft_reset(void *handle)
4925aaa36a97SAlex Deucher {
49263d7c6384SChunming Zhou 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4927aaa36a97SAlex Deucher 	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
4928aaa36a97SAlex Deucher 	u32 tmp;
4929aaa36a97SAlex Deucher 
4930aaa36a97SAlex Deucher 	/* GRBM_STATUS */
4931aaa36a97SAlex Deucher 	tmp = RREG32(mmGRBM_STATUS);
4932aaa36a97SAlex Deucher 	if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
4933aaa36a97SAlex Deucher 		   GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
4934aaa36a97SAlex Deucher 		   GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
4935aaa36a97SAlex Deucher 		   GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
4936aaa36a97SAlex Deucher 		   GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
49373d7c6384SChunming Zhou 		   GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK |
49383d7c6384SChunming Zhou 		   GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
4939aaa36a97SAlex Deucher 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4940aaa36a97SAlex Deucher 						GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
4941aaa36a97SAlex Deucher 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4942aaa36a97SAlex Deucher 						GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
4943aaa36a97SAlex Deucher 		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
4944aaa36a97SAlex Deucher 						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
4945aaa36a97SAlex Deucher 	}
4946aaa36a97SAlex Deucher 
4947aaa36a97SAlex Deucher 	/* GRBM_STATUS2 */
4948aaa36a97SAlex Deucher 	tmp = RREG32(mmGRBM_STATUS2);
4949aaa36a97SAlex Deucher 	if (REG_GET_FIELD(tmp, GRBM_STATUS2, RLC_BUSY))
4950aaa36a97SAlex Deucher 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4951aaa36a97SAlex Deucher 						GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
4952aaa36a97SAlex Deucher 
49533d7c6384SChunming Zhou 	if (REG_GET_FIELD(tmp, GRBM_STATUS2, CPF_BUSY) ||
49543d7c6384SChunming Zhou 	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPC_BUSY) ||
49553d7c6384SChunming Zhou 	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPG_BUSY)) {
49563d7c6384SChunming Zhou 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
49573d7c6384SChunming Zhou 						SOFT_RESET_CPF, 1);
49583d7c6384SChunming Zhou 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
49593d7c6384SChunming Zhou 						SOFT_RESET_CPC, 1);
49603d7c6384SChunming Zhou 		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
49613d7c6384SChunming Zhou 						SOFT_RESET_CPG, 1);
49623d7c6384SChunming Zhou 		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
49633d7c6384SChunming Zhou 						SOFT_RESET_GRBM, 1);
49643d7c6384SChunming Zhou 	}
49653d7c6384SChunming Zhou 
4966aaa36a97SAlex Deucher 	/* SRBM_STATUS */
4967aaa36a97SAlex Deucher 	tmp = RREG32(mmSRBM_STATUS);
4968aaa36a97SAlex Deucher 	if (REG_GET_FIELD(tmp, SRBM_STATUS, GRBM_RQ_PENDING))
4969aaa36a97SAlex Deucher 		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
4970aaa36a97SAlex Deucher 						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
49713d7c6384SChunming Zhou 	if (REG_GET_FIELD(tmp, SRBM_STATUS, SEM_BUSY))
49723d7c6384SChunming Zhou 		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
49733d7c6384SChunming Zhou 						SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
4974aaa36a97SAlex Deucher 
4975aaa36a97SAlex Deucher 	if (grbm_soft_reset || srbm_soft_reset) {
49763d7c6384SChunming Zhou 		adev->gfx.grbm_soft_reset = grbm_soft_reset;
49773d7c6384SChunming Zhou 		adev->gfx.srbm_soft_reset = srbm_soft_reset;
4978da146d3bSAlex Deucher 		return true;
49793d7c6384SChunming Zhou 	} else {
49803d7c6384SChunming Zhou 		adev->gfx.grbm_soft_reset = 0;
49813d7c6384SChunming Zhou 		adev->gfx.srbm_soft_reset = 0;
4982da146d3bSAlex Deucher 		return false;
49833d7c6384SChunming Zhou 	}
49843d7c6384SChunming Zhou }
4985aaa36a97SAlex Deucher 
gfx_v8_0_pre_soft_reset(void * handle)49861057f20cSChunming Zhou static int gfx_v8_0_pre_soft_reset(void *handle)
49871057f20cSChunming Zhou {
49881057f20cSChunming Zhou 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
49892e431a17SYueHaibing 	u32 grbm_soft_reset = 0;
49901057f20cSChunming Zhou 
4991da146d3bSAlex Deucher 	if ((!adev->gfx.grbm_soft_reset) &&
4992da146d3bSAlex Deucher 	    (!adev->gfx.srbm_soft_reset))
49931057f20cSChunming Zhou 		return 0;
49941057f20cSChunming Zhou 
49951057f20cSChunming Zhou 	grbm_soft_reset = adev->gfx.grbm_soft_reset;
49961057f20cSChunming Zhou 
4997aaa36a97SAlex Deucher 	/* stop the rlc */
4998fdb81fd7SLikun Gao 	adev->gfx.rlc.funcs->stop(adev);
4999aaa36a97SAlex Deucher 
50001057f20cSChunming Zhou 	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
50011057f20cSChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
5002aaa36a97SAlex Deucher 		/* Disable GFX parsing/prefetching */
5003aaa36a97SAlex Deucher 		gfx_v8_0_cp_gfx_enable(adev, false);
5004aaa36a97SAlex Deucher 
50051057f20cSChunming Zhou 	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
50061057f20cSChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
50071057f20cSChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
50081057f20cSChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
50091057f20cSChunming Zhou 		int i;
50101057f20cSChunming Zhou 
50111057f20cSChunming Zhou 		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
50121057f20cSChunming Zhou 			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
50131057f20cSChunming Zhou 
5014a99f249dSAlex Deucher 			mutex_lock(&adev->srbm_mutex);
5015a99f249dSAlex Deucher 			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5016a99f249dSAlex Deucher 			gfx_v8_0_deactivate_hqd(adev, 2);
5017a99f249dSAlex Deucher 			vi_srbm_select(adev, 0, 0, 0, 0);
5018a99f249dSAlex Deucher 			mutex_unlock(&adev->srbm_mutex);
50191057f20cSChunming Zhou 		}
5020aaa36a97SAlex Deucher 		/* Disable MEC parsing/prefetching */
50217776a693SAlex Deucher 		gfx_v8_0_cp_compute_enable(adev, false);
50221057f20cSChunming Zhou 	}
50231057f20cSChunming Zhou 
50241057f20cSChunming Zhou 	return 0;
50251057f20cSChunming Zhou }
50261057f20cSChunming Zhou 
gfx_v8_0_soft_reset(void * handle)50273d7c6384SChunming Zhou static int gfx_v8_0_soft_reset(void *handle)
50283d7c6384SChunming Zhou {
50293d7c6384SChunming Zhou 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
50303d7c6384SChunming Zhou 	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
50313d7c6384SChunming Zhou 	u32 tmp;
50323d7c6384SChunming Zhou 
5033da146d3bSAlex Deucher 	if ((!adev->gfx.grbm_soft_reset) &&
5034da146d3bSAlex Deucher 	    (!adev->gfx.srbm_soft_reset))
50353d7c6384SChunming Zhou 		return 0;
50363d7c6384SChunming Zhou 
50373d7c6384SChunming Zhou 	grbm_soft_reset = adev->gfx.grbm_soft_reset;
50383d7c6384SChunming Zhou 	srbm_soft_reset = adev->gfx.srbm_soft_reset;
50397776a693SAlex Deucher 
50407776a693SAlex Deucher 	if (grbm_soft_reset || srbm_soft_reset) {
50417776a693SAlex Deucher 		tmp = RREG32(mmGMCON_DEBUG);
50423d7c6384SChunming Zhou 		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 1);
50433d7c6384SChunming Zhou 		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 1);
50447776a693SAlex Deucher 		WREG32(mmGMCON_DEBUG, tmp);
50457776a693SAlex Deucher 		udelay(50);
50467776a693SAlex Deucher 	}
5047aaa36a97SAlex Deucher 
5048aaa36a97SAlex Deucher 	if (grbm_soft_reset) {
5049aaa36a97SAlex Deucher 		tmp = RREG32(mmGRBM_SOFT_RESET);
5050aaa36a97SAlex Deucher 		tmp |= grbm_soft_reset;
5051aaa36a97SAlex Deucher 		dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5052aaa36a97SAlex Deucher 		WREG32(mmGRBM_SOFT_RESET, tmp);
5053aaa36a97SAlex Deucher 		tmp = RREG32(mmGRBM_SOFT_RESET);
5054aaa36a97SAlex Deucher 
5055aaa36a97SAlex Deucher 		udelay(50);
5056aaa36a97SAlex Deucher 
5057aaa36a97SAlex Deucher 		tmp &= ~grbm_soft_reset;
5058aaa36a97SAlex Deucher 		WREG32(mmGRBM_SOFT_RESET, tmp);
5059aaa36a97SAlex Deucher 		tmp = RREG32(mmGRBM_SOFT_RESET);
5060aaa36a97SAlex Deucher 	}
5061aaa36a97SAlex Deucher 
5062aaa36a97SAlex Deucher 	if (srbm_soft_reset) {
5063aaa36a97SAlex Deucher 		tmp = RREG32(mmSRBM_SOFT_RESET);
5064aaa36a97SAlex Deucher 		tmp |= srbm_soft_reset;
5065aaa36a97SAlex Deucher 		dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5066aaa36a97SAlex Deucher 		WREG32(mmSRBM_SOFT_RESET, tmp);
5067aaa36a97SAlex Deucher 		tmp = RREG32(mmSRBM_SOFT_RESET);
5068aaa36a97SAlex Deucher 
5069aaa36a97SAlex Deucher 		udelay(50);
5070aaa36a97SAlex Deucher 
5071aaa36a97SAlex Deucher 		tmp &= ~srbm_soft_reset;
5072aaa36a97SAlex Deucher 		WREG32(mmSRBM_SOFT_RESET, tmp);
5073aaa36a97SAlex Deucher 		tmp = RREG32(mmSRBM_SOFT_RESET);
5074aaa36a97SAlex Deucher 	}
50757776a693SAlex Deucher 
50767776a693SAlex Deucher 	if (grbm_soft_reset || srbm_soft_reset) {
50777776a693SAlex Deucher 		tmp = RREG32(mmGMCON_DEBUG);
50783d7c6384SChunming Zhou 		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 0);
50793d7c6384SChunming Zhou 		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 0);
50807776a693SAlex Deucher 		WREG32(mmGMCON_DEBUG, tmp);
50817776a693SAlex Deucher 	}
50827776a693SAlex Deucher 
5083aaa36a97SAlex Deucher 	/* Wait a little for things to settle down */
5084aaa36a97SAlex Deucher 	udelay(50);
50853d7c6384SChunming Zhou 
5086aaa36a97SAlex Deucher 	return 0;
5087aaa36a97SAlex Deucher }
5088aaa36a97SAlex Deucher 
gfx_v8_0_post_soft_reset(void * handle)5089e4ae0fc3SChunming Zhou static int gfx_v8_0_post_soft_reset(void *handle)
5090e4ae0fc3SChunming Zhou {
5091e4ae0fc3SChunming Zhou 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
50922e431a17SYueHaibing 	u32 grbm_soft_reset = 0;
5093e4ae0fc3SChunming Zhou 
5094da146d3bSAlex Deucher 	if ((!adev->gfx.grbm_soft_reset) &&
5095da146d3bSAlex Deucher 	    (!adev->gfx.srbm_soft_reset))
5096e4ae0fc3SChunming Zhou 		return 0;
5097e4ae0fc3SChunming Zhou 
5098e4ae0fc3SChunming Zhou 	grbm_soft_reset = adev->gfx.grbm_soft_reset;
5099e4ae0fc3SChunming Zhou 
5100e4ae0fc3SChunming Zhou 	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5101e4ae0fc3SChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
5102e4ae0fc3SChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
5103e4ae0fc3SChunming Zhou 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
5104e4ae0fc3SChunming Zhou 		int i;
5105e4ae0fc3SChunming Zhou 
5106e4ae0fc3SChunming Zhou 		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
5107e4ae0fc3SChunming Zhou 			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
5108e4ae0fc3SChunming Zhou 
5109a99f249dSAlex Deucher 			mutex_lock(&adev->srbm_mutex);
5110a99f249dSAlex Deucher 			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5111a99f249dSAlex Deucher 			gfx_v8_0_deactivate_hqd(adev, 2);
5112a99f249dSAlex Deucher 			vi_srbm_select(adev, 0, 0, 0, 0);
5113a99f249dSAlex Deucher 			mutex_unlock(&adev->srbm_mutex);
5114e4ae0fc3SChunming Zhou 		}
5115b4e40676SDavid Panariti 		gfx_v8_0_kiq_resume(adev);
511636859cd5SRex Zhu 		gfx_v8_0_kcq_resume(adev);
5117e4ae0fc3SChunming Zhou 	}
511836859cd5SRex Zhu 
511936859cd5SRex Zhu 	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
512036859cd5SRex Zhu 	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
512136859cd5SRex Zhu 		gfx_v8_0_cp_gfx_resume(adev);
512236859cd5SRex Zhu 
5123c6064de4STiecheng Zhou 	gfx_v8_0_cp_test_all_rings(adev);
5124c6064de4STiecheng Zhou 
5125fdb81fd7SLikun Gao 	adev->gfx.rlc.funcs->start(adev);
5126e4ae0fc3SChunming Zhou 
5127aaa36a97SAlex Deucher 	return 0;
5128aaa36a97SAlex Deucher }
5129aaa36a97SAlex Deucher 
5130aaa36a97SAlex Deucher /**
5131aaa36a97SAlex Deucher  * gfx_v8_0_get_gpu_clock_counter - return GPU clock counter snapshot
5132aaa36a97SAlex Deucher  *
5133aaa36a97SAlex Deucher  * @adev: amdgpu_device pointer
5134aaa36a97SAlex Deucher  *
5135aaa36a97SAlex Deucher  * Fetches a GPU clock counter snapshot.
5136aaa36a97SAlex Deucher  * Returns the 64 bit clock counter snapshot.
5137aaa36a97SAlex Deucher  */
gfx_v8_0_get_gpu_clock_counter(struct amdgpu_device * adev)5138b95e31fdSAlex Deucher static uint64_t gfx_v8_0_get_gpu_clock_counter(struct amdgpu_device *adev)
5139aaa36a97SAlex Deucher {
5140aaa36a97SAlex Deucher 	uint64_t clock;
5141aaa36a97SAlex Deucher 
5142aaa36a97SAlex Deucher 	mutex_lock(&adev->gfx.gpu_clock_mutex);
5143aaa36a97SAlex Deucher 	WREG32(mmRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
5144aaa36a97SAlex Deucher 	clock = (uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_LSB) |
5145aaa36a97SAlex Deucher 		((uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
5146aaa36a97SAlex Deucher 	mutex_unlock(&adev->gfx.gpu_clock_mutex);
5147aaa36a97SAlex Deucher 	return clock;
5148aaa36a97SAlex Deucher }
5149aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring * ring,uint32_t vmid,uint32_t gds_base,uint32_t gds_size,uint32_t gws_base,uint32_t gws_size,uint32_t oa_base,uint32_t oa_size)5150aaa36a97SAlex Deucher static void gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring *ring,
5151aaa36a97SAlex Deucher 					  uint32_t vmid,
5152aaa36a97SAlex Deucher 					  uint32_t gds_base, uint32_t gds_size,
5153aaa36a97SAlex Deucher 					  uint32_t gws_base, uint32_t gws_size,
5154aaa36a97SAlex Deucher 					  uint32_t oa_base, uint32_t oa_size)
5155aaa36a97SAlex Deucher {
5156aaa36a97SAlex Deucher 	/* GDS Base */
5157aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5158aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5159aaa36a97SAlex Deucher 				WRITE_DATA_DST_SEL(0)));
5160aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_base);
5161aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
5162aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, gds_base);
5163aaa36a97SAlex Deucher 
5164aaa36a97SAlex Deucher 	/* GDS Size */
5165aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5166aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5167aaa36a97SAlex Deucher 				WRITE_DATA_DST_SEL(0)));
5168aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_size);
5169aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
5170aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, gds_size);
5171aaa36a97SAlex Deucher 
5172aaa36a97SAlex Deucher 	/* GWS */
5173aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5174aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5175aaa36a97SAlex Deucher 				WRITE_DATA_DST_SEL(0)));
5176aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].gws);
5177aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
5178aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, gws_size << GDS_GWS_VMID0__SIZE__SHIFT | gws_base);
5179aaa36a97SAlex Deucher 
5180aaa36a97SAlex Deucher 	/* OA */
5181aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5182aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5183aaa36a97SAlex Deucher 				WRITE_DATA_DST_SEL(0)));
5184aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].oa);
5185aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
5186aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (1 << (oa_size + oa_base)) - (1 << oa_base));
5187aaa36a97SAlex Deucher }
5188aaa36a97SAlex Deucher 
wave_read_ind(struct amdgpu_device * adev,uint32_t simd,uint32_t wave,uint32_t address)5189472259f0STom St Denis static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t address)
5190472259f0STom St Denis {
5191bc24fbe9STom St Denis 	WREG32(mmSQ_IND_INDEX,
5192bc24fbe9STom St Denis 		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5193bc24fbe9STom St Denis 		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5194bc24fbe9STom St Denis 		(address << SQ_IND_INDEX__INDEX__SHIFT) |
5195bc24fbe9STom St Denis 		(SQ_IND_INDEX__FORCE_READ_MASK));
5196472259f0STom St Denis 	return RREG32(mmSQ_IND_DATA);
5197472259f0STom St Denis }
5198472259f0STom St Denis 
wave_read_regs(struct amdgpu_device * adev,uint32_t simd,uint32_t wave,uint32_t thread,uint32_t regno,uint32_t num,uint32_t * out)5199c5a60ce8STom St Denis static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,
5200c5a60ce8STom St Denis 			   uint32_t wave, uint32_t thread,
5201c5a60ce8STom St Denis 			   uint32_t regno, uint32_t num, uint32_t *out)
5202c5a60ce8STom St Denis {
5203c5a60ce8STom St Denis 	WREG32(mmSQ_IND_INDEX,
5204c5a60ce8STom St Denis 		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5205c5a60ce8STom St Denis 		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5206c5a60ce8STom St Denis 		(regno << SQ_IND_INDEX__INDEX__SHIFT) |
5207c5a60ce8STom St Denis 		(thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |
5208c5a60ce8STom St Denis 		(SQ_IND_INDEX__FORCE_READ_MASK) |
5209c5a60ce8STom St Denis 		(SQ_IND_INDEX__AUTO_INCR_MASK));
5210c5a60ce8STom St Denis 	while (num--)
5211c5a60ce8STom St Denis 		*(out++) = RREG32(mmSQ_IND_DATA);
5212c5a60ce8STom St Denis }
5213c5a60ce8STom St Denis 
gfx_v8_0_read_wave_data(struct amdgpu_device * adev,uint32_t xcc_id,uint32_t simd,uint32_t wave,uint32_t * dst,int * no_fields)5214553f973aSTom St Denis static void gfx_v8_0_read_wave_data(struct amdgpu_device *adev, uint32_t xcc_id, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields)
5215472259f0STom St Denis {
5216472259f0STom St Denis 	/* type 0 wave data */
5217472259f0STom St Denis 	dst[(*no_fields)++] = 0;
5218472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_STATUS);
5219472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_LO);
5220472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_HI);
5221472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_LO);
5222472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_HI);
5223472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_HW_ID);
5224472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW0);
5225472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW1);
5226472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_GPR_ALLOC);
5227472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_LDS_ALLOC);
5228472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TRAPSTS);
5229472259f0STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_STS);
523074f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_LO);
523174f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_HI);
523274f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_LO);
523374f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_HI);
523474f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_DBG0);
523574f3ce31STom St Denis 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);
5236685967b3SJoseph Greathouse 	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_MODE);
5237472259f0STom St Denis }
5238472259f0STom St Denis 
gfx_v8_0_read_wave_sgprs(struct amdgpu_device * adev,uint32_t xcc_id,uint32_t simd,uint32_t wave,uint32_t start,uint32_t size,uint32_t * dst)5239553f973aSTom St Denis static void gfx_v8_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t xcc_id, uint32_t simd,
5240c5a60ce8STom St Denis 				     uint32_t wave, uint32_t start,
5241c5a60ce8STom St Denis 				     uint32_t size, uint32_t *dst)
5242c5a60ce8STom St Denis {
5243c5a60ce8STom St Denis 	wave_read_regs(
5244c5a60ce8STom St Denis 		adev, simd, wave, 0,
5245c5a60ce8STom St Denis 		start + SQIND_WAVE_SGPRS_OFFSET, size, dst);
5246c5a60ce8STom St Denis }
5247c5a60ce8STom St Denis 
5248472259f0STom St Denis 
5249b95e31fdSAlex Deucher static const struct amdgpu_gfx_funcs gfx_v8_0_gfx_funcs = {
5250b95e31fdSAlex Deucher 	.get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
525105fb7291SAlex Deucher 	.select_se_sh = &gfx_v8_0_select_se_sh,
5252472259f0STom St Denis 	.read_wave_data = &gfx_v8_0_read_wave_data,
5253c5a60ce8STom St Denis 	.read_wave_sgprs = &gfx_v8_0_read_wave_sgprs,
5254f7a9ee81SAndrey Grodzovsky 	.select_me_pipe_q = &gfx_v8_0_select_me_pipe_q
5255b95e31fdSAlex Deucher };
5256b95e31fdSAlex Deucher 
gfx_v8_0_early_init(void * handle)52575fc3aeebSyanyang1 static int gfx_v8_0_early_init(void *handle)
5258aaa36a97SAlex Deucher {
52595fc3aeebSyanyang1 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5260aaa36a97SAlex Deucher 
5261c6a64ad9SLijo Lazar 	adev->gfx.xcc_mask = 1;
5262aaa36a97SAlex Deucher 	adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
5263a3bab325SAlex Deucher 	adev->gfx.num_compute_rings = min(amdgpu_gfx_get_num_kcq(adev),
5264a3bab325SAlex Deucher 					  AMDGPU_MAX_COMPUTE_RINGS);
5265b95e31fdSAlex Deucher 	adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
5266aaa36a97SAlex Deucher 	gfx_v8_0_set_ring_funcs(adev);
5267aaa36a97SAlex Deucher 	gfx_v8_0_set_irq_funcs(adev);
5268aaa36a97SAlex Deucher 	gfx_v8_0_set_gds_init(adev);
5269dbff57bcSAlex Deucher 	gfx_v8_0_set_rlc_funcs(adev);
5270aaa36a97SAlex Deucher 
5271aaa36a97SAlex Deucher 	return 0;
5272aaa36a97SAlex Deucher }
5273aaa36a97SAlex Deucher 
gfx_v8_0_late_init(void * handle)5274ccba7691SAlex Deucher static int gfx_v8_0_late_init(void *handle)
5275ccba7691SAlex Deucher {
5276ccba7691SAlex Deucher 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5277ccba7691SAlex Deucher 	int r;
5278ccba7691SAlex Deucher 
52791d22a454SAlex Deucher 	r = amdgpu_irq_get(adev, &adev->gfx.priv_reg_irq, 0);
52801d22a454SAlex Deucher 	if (r)
52811d22a454SAlex Deucher 		return r;
52821d22a454SAlex Deucher 
52831d22a454SAlex Deucher 	r = amdgpu_irq_get(adev, &adev->gfx.priv_inst_irq, 0);
52841d22a454SAlex Deucher 	if (r)
52851d22a454SAlex Deucher 		return r;
52861d22a454SAlex Deucher 
5287ccba7691SAlex Deucher 	/* requires IBs so do in late init after IB pool is initialized */
5288ccba7691SAlex Deucher 	r = gfx_v8_0_do_edc_gpr_workarounds(adev);
5289ccba7691SAlex Deucher 	if (r)
5290ccba7691SAlex Deucher 		return r;
5291ccba7691SAlex Deucher 
52925a2f2913SDavid Panariti 	r = amdgpu_irq_get(adev, &adev->gfx.cp_ecc_error_irq, 0);
52935a2f2913SDavid Panariti 	if (r) {
52945a2f2913SDavid Panariti 		DRM_ERROR("amdgpu_irq_get() failed to get IRQ for EDC, r: %d.\n", r);
52955a2f2913SDavid Panariti 		return r;
52965a2f2913SDavid Panariti 	}
52975a2f2913SDavid Panariti 
529804ad26bbSDavid Panariti 	r = amdgpu_irq_get(adev, &adev->gfx.sq_irq, 0);
529904ad26bbSDavid Panariti 	if (r) {
530004ad26bbSDavid Panariti 		DRM_ERROR(
530104ad26bbSDavid Panariti 			"amdgpu_irq_get() failed to get IRQ for SQ, r: %d.\n",
530204ad26bbSDavid Panariti 			r);
530304ad26bbSDavid Panariti 		return r;
530404ad26bbSDavid Panariti 	}
530504ad26bbSDavid Panariti 
5306ccba7691SAlex Deucher 	return 0;
5307ccba7691SAlex Deucher }
5308ccba7691SAlex Deucher 
gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device * adev,bool enable)5309c2546f55SAlex Deucher static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
531062a86fc2SEric Huang 						       bool enable)
531162a86fc2SEric Huang {
531270bdb6edSEvan Quan 	if ((adev->asic_type == CHIP_POLARIS11) ||
531371765469SLeo Liu 	    (adev->asic_type == CHIP_POLARIS12) ||
531470bdb6edSEvan Quan 	    (adev->asic_type == CHIP_VEGAM))
531562a86fc2SEric Huang 		/* Send msg to SMU via Powerplay */
531685f80cb3SRex Zhu 		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, enable);
531762a86fc2SEric Huang 
531861cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, STATIC_PER_CU_PG_ENABLE, enable ? 1 : 0);
531962a86fc2SEric Huang }
532062a86fc2SEric Huang 
gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device * adev,bool enable)5321c2546f55SAlex Deucher static void gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
532262a86fc2SEric Huang 							bool enable)
532362a86fc2SEric Huang {
532461cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, DYN_PER_CU_PG_ENABLE, enable ? 1 : 0);
532562a86fc2SEric Huang }
532662a86fc2SEric Huang 
polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device * adev,bool enable)53272cc0c0b5SFlora Cui static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
532862a86fc2SEric Huang 		bool enable)
532962a86fc2SEric Huang {
533061cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, QUICK_PG_ENABLE, enable ? 1 : 0);
533162a86fc2SEric Huang }
533262a86fc2SEric Huang 
cz_enable_gfx_cg_power_gating(struct amdgpu_device * adev,bool enable)53332c547165SAlex Deucher static void cz_enable_gfx_cg_power_gating(struct amdgpu_device *adev,
53342c547165SAlex Deucher 					  bool enable)
53352c547165SAlex Deucher {
533661cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, GFX_POWER_GATING_ENABLE, enable ? 1 : 0);
53372c547165SAlex Deucher }
53382c547165SAlex Deucher 
cz_enable_gfx_pipeline_power_gating(struct amdgpu_device * adev,bool enable)53392c547165SAlex Deucher static void cz_enable_gfx_pipeline_power_gating(struct amdgpu_device *adev,
53402c547165SAlex Deucher 						bool enable)
53412c547165SAlex Deucher {
534261cb8cefSTom St Denis 	WREG32_FIELD(RLC_PG_CNTL, GFX_PIPELINE_PG_ENABLE, enable ? 1 : 0);
53432c547165SAlex Deucher 
53442c547165SAlex Deucher 	/* Read any GFX register to wake up GFX. */
53452c547165SAlex Deucher 	if (!enable)
534661cb8cefSTom St Denis 		RREG32(mmDB_RENDER_CONTROL);
53472c547165SAlex Deucher }
53482c547165SAlex Deucher 
cz_update_gfx_cg_power_gating(struct amdgpu_device * adev,bool enable)53492c547165SAlex Deucher static void cz_update_gfx_cg_power_gating(struct amdgpu_device *adev,
53502c547165SAlex Deucher 					  bool enable)
53512c547165SAlex Deucher {
53522c547165SAlex Deucher 	if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) && enable) {
53532c547165SAlex Deucher 		cz_enable_gfx_cg_power_gating(adev, true);
53542c547165SAlex Deucher 		if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PIPELINE)
53552c547165SAlex Deucher 			cz_enable_gfx_pipeline_power_gating(adev, true);
53562c547165SAlex Deucher 	} else {
53572c547165SAlex Deucher 		cz_enable_gfx_cg_power_gating(adev, false);
53582c547165SAlex Deucher 		cz_enable_gfx_pipeline_power_gating(adev, false);
53592c547165SAlex Deucher 	}
53602c547165SAlex Deucher }
53612c547165SAlex Deucher 
gfx_v8_0_set_powergating_state(void * handle,enum amd_powergating_state state)53625fc3aeebSyanyang1 static int gfx_v8_0_set_powergating_state(void *handle,
53635fc3aeebSyanyang1 					  enum amd_powergating_state state)
5364aaa36a97SAlex Deucher {
536562a86fc2SEric Huang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
53667e913664SAndrew F. Davis 	bool enable = (state == AMD_PG_STATE_GATE);
536762a86fc2SEric Huang 
5368ce137c04SMonk Liu 	if (amdgpu_sriov_vf(adev))
5369ce137c04SMonk Liu 		return 0;
5370ce137c04SMonk Liu 
53711f06dee8SRex Zhu 	if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
53721f06dee8SRex Zhu 				AMD_PG_SUPPORT_RLC_SMU_HS |
53731f06dee8SRex Zhu 				AMD_PG_SUPPORT_CP |
53741f06dee8SRex Zhu 				AMD_PG_SUPPORT_GFX_DMG))
537586b20703SLe Ma 		amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
537662a86fc2SEric Huang 	switch (adev->asic_type) {
53772c547165SAlex Deucher 	case CHIP_CARRIZO:
53782c547165SAlex Deucher 	case CHIP_STONEY:
5379ad1830d5SRex Zhu 
53805c964221SRex Zhu 		if (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS) {
53815c964221SRex Zhu 			cz_enable_sck_slow_down_on_power_up(adev, true);
53825c964221SRex Zhu 			cz_enable_sck_slow_down_on_power_down(adev, true);
53835c964221SRex Zhu 		} else {
53845c964221SRex Zhu 			cz_enable_sck_slow_down_on_power_up(adev, false);
53855c964221SRex Zhu 			cz_enable_sck_slow_down_on_power_down(adev, false);
53865c964221SRex Zhu 		}
53875c964221SRex Zhu 		if (adev->pg_flags & AMD_PG_SUPPORT_CP)
53885c964221SRex Zhu 			cz_enable_cp_power_gating(adev, true);
53895c964221SRex Zhu 		else
53905c964221SRex Zhu 			cz_enable_cp_power_gating(adev, false);
53915c964221SRex Zhu 
53922c547165SAlex Deucher 		cz_update_gfx_cg_power_gating(adev, enable);
53932c547165SAlex Deucher 
53942c547165SAlex Deucher 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
53952c547165SAlex Deucher 			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
53962c547165SAlex Deucher 		else
53972c547165SAlex Deucher 			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
53982c547165SAlex Deucher 
53992c547165SAlex Deucher 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
54002c547165SAlex Deucher 			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
54012c547165SAlex Deucher 		else
54022c547165SAlex Deucher 			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
54032c547165SAlex Deucher 		break;
54042cc0c0b5SFlora Cui 	case CHIP_POLARIS11:
5405c4642a47SJunwei Zhang 	case CHIP_POLARIS12:
540671765469SLeo Liu 	case CHIP_VEGAM:
54077ba0eb6dSAlex Deucher 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
54087ba0eb6dSAlex Deucher 			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
540962a86fc2SEric Huang 		else
54107ba0eb6dSAlex Deucher 			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
54117ba0eb6dSAlex Deucher 
54127ba0eb6dSAlex Deucher 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
54137ba0eb6dSAlex Deucher 			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
54147ba0eb6dSAlex Deucher 		else
54157ba0eb6dSAlex Deucher 			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
54167ba0eb6dSAlex Deucher 
54177ba0eb6dSAlex Deucher 		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_QUICK_MG) && enable)
54187ba0eb6dSAlex Deucher 			polaris11_enable_gfx_quick_mg_power_gating(adev, true);
54197ba0eb6dSAlex Deucher 		else
54207ba0eb6dSAlex Deucher 			polaris11_enable_gfx_quick_mg_power_gating(adev, false);
542162a86fc2SEric Huang 		break;
542262a86fc2SEric Huang 	default:
542362a86fc2SEric Huang 		break;
542462a86fc2SEric Huang 	}
54251f06dee8SRex Zhu 	if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
54261f06dee8SRex Zhu 				AMD_PG_SUPPORT_RLC_SMU_HS |
54271f06dee8SRex Zhu 				AMD_PG_SUPPORT_CP |
54281f06dee8SRex Zhu 				AMD_PG_SUPPORT_GFX_DMG))
542986b20703SLe Ma 		amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
5430aaa36a97SAlex Deucher 	return 0;
5431aaa36a97SAlex Deucher }
5432aaa36a97SAlex Deucher 
gfx_v8_0_get_clockgating_state(void * handle,u64 * flags)543325faeddcSEvan Quan static void gfx_v8_0_get_clockgating_state(void *handle, u64 *flags)
5434ebd843d6SHuang Rui {
5435ebd843d6SHuang Rui 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5436ebd843d6SHuang Rui 	int data;
5437ebd843d6SHuang Rui 
5438ce137c04SMonk Liu 	if (amdgpu_sriov_vf(adev))
5439ce137c04SMonk Liu 		*flags = 0;
5440ce137c04SMonk Liu 
5441ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_MGCG */
5442ebd843d6SHuang Rui 	data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5443ebd843d6SHuang Rui 	if (!(data & RLC_CGTT_MGCG_OVERRIDE__CPF_MASK))
5444ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_MGCG;
5445ebd843d6SHuang Rui 
5446ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_CGLG */
5447ebd843d6SHuang Rui 	data = RREG32(mmRLC_CGCG_CGLS_CTRL);
5448ebd843d6SHuang Rui 	if (data & RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK)
5449ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_CGCG;
5450ebd843d6SHuang Rui 
5451ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_CGLS */
5452ebd843d6SHuang Rui 	if (data & RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK)
5453ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_CGLS;
5454ebd843d6SHuang Rui 
5455ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_CGTS */
5456ebd843d6SHuang Rui 	data = RREG32(mmCGTS_SM_CTRL_REG);
5457ebd843d6SHuang Rui 	if (!(data & CGTS_SM_CTRL_REG__OVERRIDE_MASK))
5458ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_CGTS;
5459ebd843d6SHuang Rui 
5460ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_CGTS_LS */
5461ebd843d6SHuang Rui 	if (!(data & CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK))
5462ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_CGTS_LS;
5463ebd843d6SHuang Rui 
5464ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_RLC_LS */
5465ebd843d6SHuang Rui 	data = RREG32(mmRLC_MEM_SLP_CNTL);
5466ebd843d6SHuang Rui 	if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK)
5467ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_RLC_LS | AMD_CG_SUPPORT_GFX_MGLS;
5468ebd843d6SHuang Rui 
5469ebd843d6SHuang Rui 	/* AMD_CG_SUPPORT_GFX_CP_LS */
5470ebd843d6SHuang Rui 	data = RREG32(mmCP_MEM_SLP_CNTL);
5471ebd843d6SHuang Rui 	if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK)
5472ebd843d6SHuang Rui 		*flags |= AMD_CG_SUPPORT_GFX_CP_LS | AMD_CG_SUPPORT_GFX_MGLS;
5473ebd843d6SHuang Rui }
5474ebd843d6SHuang Rui 
gfx_v8_0_send_serdes_cmd(struct amdgpu_device * adev,uint32_t reg_addr,uint32_t cmd)547579deaaf4SAlex Deucher static void gfx_v8_0_send_serdes_cmd(struct amdgpu_device *adev,
54766e378858SEric Huang 				     uint32_t reg_addr, uint32_t cmd)
54776e378858SEric Huang {
54786e378858SEric Huang 	uint32_t data;
54796e378858SEric Huang 
5480d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
54816e378858SEric Huang 
54826e378858SEric Huang 	WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
54836e378858SEric Huang 	WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
54846e378858SEric Huang 
54856e378858SEric Huang 	data = RREG32(mmRLC_SERDES_WR_CTRL);
5486146f256fSAlex Deucher 	if (adev->asic_type == CHIP_STONEY)
5487146f256fSAlex Deucher 		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5488146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5489146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5490146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5491146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5492146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5493146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5494146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5495146f256fSAlex Deucher 			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5496146f256fSAlex Deucher 	else
54976e378858SEric Huang 		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
54986e378858SEric Huang 			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
54996e378858SEric Huang 			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
55006e378858SEric Huang 			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
55016e378858SEric Huang 			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
55026e378858SEric Huang 			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
55036e378858SEric Huang 			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
55046e378858SEric Huang 			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
55056e378858SEric Huang 			  RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
55066e378858SEric Huang 			  RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
55076e378858SEric Huang 			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
55086e378858SEric Huang 	data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK |
55096e378858SEric Huang 		 (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) |
55106e378858SEric Huang 		 (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) |
55116e378858SEric Huang 		 (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT));
55126e378858SEric Huang 
55136e378858SEric Huang 	WREG32(mmRLC_SERDES_WR_CTRL, data);
55146e378858SEric Huang }
55156e378858SEric Huang 
5516dbff57bcSAlex Deucher #define MSG_ENTER_RLC_SAFE_MODE     1
5517dbff57bcSAlex Deucher #define MSG_EXIT_RLC_SAFE_MODE      0
5518dbff57bcSAlex Deucher #define RLC_GPR_REG2__REQ_MASK 0x00000001
551961cb8cefSTom St Denis #define RLC_GPR_REG2__REQ__SHIFT 0
5520dbff57bcSAlex Deucher #define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
5521dbff57bcSAlex Deucher #define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
5522dbff57bcSAlex Deucher 
gfx_v8_0_is_rlc_enabled(struct amdgpu_device * adev)5523106c7d61SLikun Gao static bool gfx_v8_0_is_rlc_enabled(struct amdgpu_device *adev)
5524dbff57bcSAlex Deucher {
5525106c7d61SLikun Gao 	uint32_t rlc_setting;
5526106c7d61SLikun Gao 
5527106c7d61SLikun Gao 	rlc_setting = RREG32(mmRLC_CNTL);
5528106c7d61SLikun Gao 	if (!(rlc_setting & RLC_CNTL__RLC_ENABLE_F32_MASK))
5529106c7d61SLikun Gao 		return false;
5530106c7d61SLikun Gao 
5531106c7d61SLikun Gao 	return true;
5532106c7d61SLikun Gao }
5533106c7d61SLikun Gao 
gfx_v8_0_set_safe_mode(struct amdgpu_device * adev,int xcc_id)553486b20703SLe Ma static void gfx_v8_0_set_safe_mode(struct amdgpu_device *adev, int xcc_id)
5535106c7d61SLikun Gao {
5536106c7d61SLikun Gao 	uint32_t data;
5537dbff57bcSAlex Deucher 	unsigned i;
5538dbff57bcSAlex Deucher 	data = RREG32(mmRLC_CNTL);
5539dbff57bcSAlex Deucher 	data |= RLC_SAFE_MODE__CMD_MASK;
5540dbff57bcSAlex Deucher 	data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5541dbff57bcSAlex Deucher 	data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
5542dbff57bcSAlex Deucher 	WREG32(mmRLC_SAFE_MODE, data);
5543dbff57bcSAlex Deucher 
5544106c7d61SLikun Gao 	/* wait for RLC_SAFE_MODE */
5545dbff57bcSAlex Deucher 	for (i = 0; i < adev->usec_timeout; i++) {
5546dbff57bcSAlex Deucher 		if ((RREG32(mmRLC_GPM_STAT) &
5547dbff57bcSAlex Deucher 		     (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5548dbff57bcSAlex Deucher 		      RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
5549dbff57bcSAlex Deucher 		    (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5550dbff57bcSAlex Deucher 		     RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
5551dbff57bcSAlex Deucher 			break;
5552dbff57bcSAlex Deucher 		udelay(1);
5553dbff57bcSAlex Deucher 	}
5554dbff57bcSAlex Deucher 	for (i = 0; i < adev->usec_timeout; i++) {
555561cb8cefSTom St Denis 		if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5556dbff57bcSAlex Deucher 			break;
5557dbff57bcSAlex Deucher 		udelay(1);
5558dbff57bcSAlex Deucher 	}
5559dbff57bcSAlex Deucher }
5560dbff57bcSAlex Deucher 
gfx_v8_0_unset_safe_mode(struct amdgpu_device * adev,int xcc_id)556186b20703SLe Ma static void gfx_v8_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id)
5562dbff57bcSAlex Deucher {
5563106c7d61SLikun Gao 	uint32_t data;
5564dbff57bcSAlex Deucher 	unsigned i;
5565dbff57bcSAlex Deucher 
5566dbff57bcSAlex Deucher 	data = RREG32(mmRLC_CNTL);
5567dbff57bcSAlex Deucher 	data |= RLC_SAFE_MODE__CMD_MASK;
5568dbff57bcSAlex Deucher 	data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5569dbff57bcSAlex Deucher 	WREG32(mmRLC_SAFE_MODE, data);
5570dbff57bcSAlex Deucher 
5571dbff57bcSAlex Deucher 	for (i = 0; i < adev->usec_timeout; i++) {
557261cb8cefSTom St Denis 		if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5573dbff57bcSAlex Deucher 			break;
5574dbff57bcSAlex Deucher 		udelay(1);
5575dbff57bcSAlex Deucher 	}
5576dbff57bcSAlex Deucher }
5577dbff57bcSAlex Deucher 
gfx_v8_0_update_spm_vmid(struct amdgpu_device * adev,struct amdgpu_ring * ring,unsigned vmid)5578b5387349SYuanShang static void gfx_v8_0_update_spm_vmid(struct amdgpu_device *adev, struct amdgpu_ring *ring, unsigned vmid)
5579460c484fSJacob He {
5580460c484fSJacob He 	u32 data;
5581460c484fSJacob He 
5582e6ef9b39SEvan Quan 	amdgpu_gfx_off_ctrl(adev, false);
5583e6ef9b39SEvan Quan 
5584e09d40bdSChristian König 	if (amdgpu_sriov_is_pp_one_vf(adev))
5585e09d40bdSChristian König 		data = RREG32_NO_KIQ(mmRLC_SPM_VMID);
5586e09d40bdSChristian König 	else
5587460c484fSJacob He 		data = RREG32(mmRLC_SPM_VMID);
5588460c484fSJacob He 
5589460c484fSJacob He 	data &= ~RLC_SPM_VMID__RLC_SPM_VMID_MASK;
5590460c484fSJacob He 	data |= (vmid & RLC_SPM_VMID__RLC_SPM_VMID_MASK) << RLC_SPM_VMID__RLC_SPM_VMID__SHIFT;
5591460c484fSJacob He 
5592e09d40bdSChristian König 	if (amdgpu_sriov_is_pp_one_vf(adev))
5593e09d40bdSChristian König 		WREG32_NO_KIQ(mmRLC_SPM_VMID, data);
5594e09d40bdSChristian König 	else
5595460c484fSJacob He 		WREG32(mmRLC_SPM_VMID, data);
5596e6ef9b39SEvan Quan 
5597e6ef9b39SEvan Quan 	amdgpu_gfx_off_ctrl(adev, true);
5598460c484fSJacob He }
5599460c484fSJacob He 
5600dbff57bcSAlex Deucher static const struct amdgpu_rlc_funcs iceland_rlc_funcs = {
5601106c7d61SLikun Gao 	.is_rlc_enabled = gfx_v8_0_is_rlc_enabled,
5602106c7d61SLikun Gao 	.set_safe_mode = gfx_v8_0_set_safe_mode,
5603106c7d61SLikun Gao 	.unset_safe_mode = gfx_v8_0_unset_safe_mode,
5604fdb81fd7SLikun Gao 	.init = gfx_v8_0_rlc_init,
5605106c7d61SLikun Gao 	.get_csb_size = gfx_v8_0_get_csb_size,
5606106c7d61SLikun Gao 	.get_csb_buffer = gfx_v8_0_get_csb_buffer,
5607106c7d61SLikun Gao 	.get_cp_table_num = gfx_v8_0_cp_jump_table_num,
5608fdb81fd7SLikun Gao 	.resume = gfx_v8_0_rlc_resume,
5609fdb81fd7SLikun Gao 	.stop = gfx_v8_0_rlc_stop,
5610fdb81fd7SLikun Gao 	.reset = gfx_v8_0_rlc_reset,
5611460c484fSJacob He 	.start = gfx_v8_0_rlc_start,
5612460c484fSJacob He 	.update_spm_vmid = gfx_v8_0_update_spm_vmid
5613dbff57bcSAlex Deucher };
5614dbff57bcSAlex Deucher 
gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)5615dbff57bcSAlex Deucher static void gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
56166e378858SEric Huang 						      bool enable)
56176e378858SEric Huang {
56186e378858SEric Huang 	uint32_t temp, data;
56196e378858SEric Huang 
562086b20703SLe Ma 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
5621dbff57bcSAlex Deucher 
56226e378858SEric Huang 	/* It is disabled by HW by default */
562314698b6cSAlex Deucher 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
562414698b6cSAlex Deucher 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
562561cb8cefSTom St Denis 			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS)
56266e378858SEric Huang 				/* 1 - RLC memory Light sleep */
562761cb8cefSTom St Denis 				WREG32_FIELD(RLC_MEM_SLP_CNTL, RLC_MEM_LS_EN, 1);
56286e378858SEric Huang 
562961cb8cefSTom St Denis 			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS)
563061cb8cefSTom St Denis 				WREG32_FIELD(CP_MEM_SLP_CNTL, CP_MEM_LS_EN, 1);
563114698b6cSAlex Deucher 		}
56326e378858SEric Huang 
56336e378858SEric Huang 		/* 3 - RLC_CGTT_MGCG_OVERRIDE */
56346e378858SEric Huang 		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5635dbff57bcSAlex Deucher 		if (adev->flags & AMD_IS_APU)
5636dbff57bcSAlex Deucher 			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5637dbff57bcSAlex Deucher 				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5638dbff57bcSAlex Deucher 				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK);
5639dbff57bcSAlex Deucher 		else
56406e378858SEric Huang 			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
56416e378858SEric Huang 				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
56426e378858SEric Huang 				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
56436e378858SEric Huang 				  RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
56446e378858SEric Huang 
56456e378858SEric Huang 		if (temp != data)
56466e378858SEric Huang 			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
56476e378858SEric Huang 
56486e378858SEric Huang 		/* 4 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
56496e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
56506e378858SEric Huang 
56516e378858SEric Huang 		/* 5 - clear mgcg override */
565279deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
56536e378858SEric Huang 
565414698b6cSAlex Deucher 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
56556e378858SEric Huang 			/* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */
56566e378858SEric Huang 			temp = data = RREG32(mmCGTS_SM_CTRL_REG);
56576e378858SEric Huang 			data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK);
56586e378858SEric Huang 			data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
56596e378858SEric Huang 			data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
56606e378858SEric Huang 			data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
566114698b6cSAlex Deucher 			if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
566214698b6cSAlex Deucher 			    (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
56636e378858SEric Huang 				data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
56646e378858SEric Huang 			data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
56656e378858SEric Huang 			data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
56666e378858SEric Huang 			if (temp != data)
56676e378858SEric Huang 				WREG32(mmCGTS_SM_CTRL_REG, data);
566814698b6cSAlex Deucher 		}
56696e378858SEric Huang 		udelay(50);
56706e378858SEric Huang 
56716e378858SEric Huang 		/* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
56726e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
56736e378858SEric Huang 	} else {
56746e378858SEric Huang 		/* 1 - MGCG_OVERRIDE[0] for CP and MGCG_OVERRIDE[1] for RLC */
56756e378858SEric Huang 		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
56766e378858SEric Huang 		data |= (RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
56776e378858SEric Huang 				RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
56786e378858SEric Huang 				RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
56796e378858SEric Huang 				RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
56806e378858SEric Huang 		if (temp != data)
56816e378858SEric Huang 			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
56826e378858SEric Huang 
56836e378858SEric Huang 		/* 2 - disable MGLS in RLC */
56846e378858SEric Huang 		data = RREG32(mmRLC_MEM_SLP_CNTL);
56856e378858SEric Huang 		if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK) {
56866e378858SEric Huang 			data &= ~RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
56876e378858SEric Huang 			WREG32(mmRLC_MEM_SLP_CNTL, data);
56886e378858SEric Huang 		}
56896e378858SEric Huang 
56906e378858SEric Huang 		/* 3 - disable MGLS in CP */
56916e378858SEric Huang 		data = RREG32(mmCP_MEM_SLP_CNTL);
56926e378858SEric Huang 		if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK) {
56936e378858SEric Huang 			data &= ~CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
56946e378858SEric Huang 			WREG32(mmCP_MEM_SLP_CNTL, data);
56956e378858SEric Huang 		}
56966e378858SEric Huang 
56976e378858SEric Huang 		/* 4 - Disable CGTS(Tree Shade) MGCG and MGLS */
56986e378858SEric Huang 		temp = data = RREG32(mmCGTS_SM_CTRL_REG);
56996e378858SEric Huang 		data |= (CGTS_SM_CTRL_REG__OVERRIDE_MASK |
57006e378858SEric Huang 				CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK);
57016e378858SEric Huang 		if (temp != data)
57026e378858SEric Huang 			WREG32(mmCGTS_SM_CTRL_REG, data);
57036e378858SEric Huang 
57046e378858SEric Huang 		/* 5 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57056e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57066e378858SEric Huang 
57076e378858SEric Huang 		/* 6 - set mgcg override */
570879deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD);
57096e378858SEric Huang 
57106e378858SEric Huang 		udelay(50);
57116e378858SEric Huang 
57126e378858SEric Huang 		/* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57136e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57146e378858SEric Huang 	}
5715dbff57bcSAlex Deucher 
571686b20703SLe Ma 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
57176e378858SEric Huang }
57186e378858SEric Huang 
gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device * adev,bool enable)5719dbff57bcSAlex Deucher static void gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
57206e378858SEric Huang 						      bool enable)
57216e378858SEric Huang {
57226e378858SEric Huang 	uint32_t temp, temp1, data, data1;
57236e378858SEric Huang 
57246e378858SEric Huang 	temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
57256e378858SEric Huang 
572686b20703SLe Ma 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
5727dbff57bcSAlex Deucher 
572814698b6cSAlex Deucher 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
57296e378858SEric Huang 		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
57306e378858SEric Huang 		data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK;
57316e378858SEric Huang 		if (temp1 != data1)
57326e378858SEric Huang 			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
57336e378858SEric Huang 
5734dd31ae9aSArindam Nath 		/* : wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57356e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57366e378858SEric Huang 
5737dd31ae9aSArindam Nath 		/* 2 - clear cgcg override */
573879deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
57396e378858SEric Huang 
57406e378858SEric Huang 		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57416e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57426e378858SEric Huang 
5743dd31ae9aSArindam Nath 		/* 3 - write cmd to set CGLS */
574479deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD);
57456e378858SEric Huang 
5746dd31ae9aSArindam Nath 		/* 4 - enable cgcg */
57476e378858SEric Huang 		data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK;
57486e378858SEric Huang 
574914698b6cSAlex Deucher 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
57506e378858SEric Huang 			/* enable cgls*/
57516e378858SEric Huang 			data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
57526e378858SEric Huang 
57536e378858SEric Huang 			temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
57546e378858SEric Huang 			data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK;
57556e378858SEric Huang 
57566e378858SEric Huang 			if (temp1 != data1)
57576e378858SEric Huang 				WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
575814698b6cSAlex Deucher 		} else {
575914698b6cSAlex Deucher 			data &= ~RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
576014698b6cSAlex Deucher 		}
57616e378858SEric Huang 
57626e378858SEric Huang 		if (temp != data)
57636e378858SEric Huang 			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5764dd31ae9aSArindam Nath 
5765dd31ae9aSArindam Nath 		/* 5 enable cntx_empty_int_enable/cntx_busy_int_enable/
5766dd31ae9aSArindam Nath 		 * Cmp_busy/GFX_Idle interrupts
5767dd31ae9aSArindam Nath 		 */
5768dd31ae9aSArindam Nath 		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
57696e378858SEric Huang 	} else {
57706e378858SEric Huang 		/* disable cntx_empty_int_enable & GFX Idle interrupt */
57716e378858SEric Huang 		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
57726e378858SEric Huang 
57736e378858SEric Huang 		/* TEST CGCG */
57746e378858SEric Huang 		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
57756e378858SEric Huang 		data1 |= (RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK |
57766e378858SEric Huang 				RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK);
57776e378858SEric Huang 		if (temp1 != data1)
57786e378858SEric Huang 			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
57796e378858SEric Huang 
57806e378858SEric Huang 		/* read gfx register to wake up cgcg */
57816e378858SEric Huang 		RREG32(mmCB_CGTT_SCLK_CTRL);
57826e378858SEric Huang 		RREG32(mmCB_CGTT_SCLK_CTRL);
57836e378858SEric Huang 		RREG32(mmCB_CGTT_SCLK_CTRL);
57846e378858SEric Huang 		RREG32(mmCB_CGTT_SCLK_CTRL);
57856e378858SEric Huang 
57866e378858SEric Huang 		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57876e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57886e378858SEric Huang 
5789ab5a7fb6SJulia Lawall 		/* write cmd to Set CGCG Override */
579079deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD);
57916e378858SEric Huang 
57926e378858SEric Huang 		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
57936e378858SEric Huang 		gfx_v8_0_wait_for_rlc_serdes(adev);
57946e378858SEric Huang 
57956e378858SEric Huang 		/* write cmd to Clear CGLS */
579679deaaf4SAlex Deucher 		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD);
57976e378858SEric Huang 
57986e378858SEric Huang 		/* disable cgcg, cgls should be disabled too. */
57996e378858SEric Huang 		data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
58006e378858SEric Huang 			  RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
58016e378858SEric Huang 		if (temp != data)
58026e378858SEric Huang 			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5803d5dc36a4SAlex Deucher 		/* enable interrupts again for PG */
5804d5dc36a4SAlex Deucher 		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
58056e378858SEric Huang 	}
5806dbff57bcSAlex Deucher 
58077894745aSTom St Denis 	gfx_v8_0_wait_for_rlc_serdes(adev);
58087894745aSTom St Denis 
580986b20703SLe Ma 	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
58106e378858SEric Huang }
gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device * adev,bool enable)5811dbff57bcSAlex Deucher static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev,
58126e378858SEric Huang 					    bool enable)
58136e378858SEric Huang {
58146e378858SEric Huang 	if (enable) {
58156e378858SEric Huang 		/* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS)
58166e378858SEric Huang 		 * ===  MGCG + MGLS + TS(CG/LS) ===
58176e378858SEric Huang 		 */
5818dbff57bcSAlex Deucher 		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
5819dbff57bcSAlex Deucher 		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
58206e378858SEric Huang 	} else {
58216e378858SEric Huang 		/* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS)
58226e378858SEric Huang 		 * ===  CGCG + CGLS ===
58236e378858SEric Huang 		 */
5824dbff57bcSAlex Deucher 		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
5825dbff57bcSAlex Deucher 		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
58266e378858SEric Huang 	}
58276e378858SEric Huang 	return 0;
58286e378858SEric Huang }
58296e378858SEric Huang 
gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device * adev,enum amd_clockgating_state state)5830a8ca3413SRex Zhu static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,
5831a8ca3413SRex Zhu 					  enum amd_clockgating_state state)
5832a8ca3413SRex Zhu {
58338a19e7faSRex Zhu 	uint32_t msg_id, pp_state = 0;
58348a19e7faSRex Zhu 	uint32_t pp_support_state = 0;
5835a8ca3413SRex Zhu 
58368a19e7faSRex Zhu 	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
58378a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
58388a19e7faSRex Zhu 			pp_support_state = PP_STATE_SUPPORT_LS;
58398a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
58408a19e7faSRex Zhu 		}
58418a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
58428a19e7faSRex Zhu 			pp_support_state |= PP_STATE_SUPPORT_CG;
58438a19e7faSRex Zhu 			pp_state |= PP_STATE_CG;
58448a19e7faSRex Zhu 		}
5845a8ca3413SRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
5846a8ca3413SRex Zhu 			pp_state = 0;
5847a8ca3413SRex Zhu 
5848a8ca3413SRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5849a8ca3413SRex Zhu 				PP_BLOCK_GFX_CG,
58508a19e7faSRex Zhu 				pp_support_state,
5851a8ca3413SRex Zhu 				pp_state);
58523811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
58538a19e7faSRex Zhu 	}
58548a19e7faSRex Zhu 
58558a19e7faSRex Zhu 	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
58568a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
58578a19e7faSRex Zhu 			pp_support_state = PP_STATE_SUPPORT_LS;
58588a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
58598a19e7faSRex Zhu 		}
58608a19e7faSRex Zhu 
58618a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
58628a19e7faSRex Zhu 			pp_support_state |= PP_STATE_SUPPORT_CG;
58638a19e7faSRex Zhu 			pp_state |= PP_STATE_CG;
58648a19e7faSRex Zhu 		}
58658a19e7faSRex Zhu 
58668a19e7faSRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
58678a19e7faSRex Zhu 			pp_state = 0;
5868a8ca3413SRex Zhu 
5869a8ca3413SRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5870a8ca3413SRex Zhu 				PP_BLOCK_GFX_MG,
58718a19e7faSRex Zhu 				pp_support_state,
5872a8ca3413SRex Zhu 				pp_state);
58733811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
58748a19e7faSRex Zhu 	}
5875a8ca3413SRex Zhu 
5876a8ca3413SRex Zhu 	return 0;
5877a8ca3413SRex Zhu }
5878a8ca3413SRex Zhu 
gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device * adev,enum amd_clockgating_state state)5879a8ca3413SRex Zhu static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,
5880a8ca3413SRex Zhu 					  enum amd_clockgating_state state)
5881a8ca3413SRex Zhu {
58828a19e7faSRex Zhu 
58838a19e7faSRex Zhu 	uint32_t msg_id, pp_state = 0;
58848a19e7faSRex Zhu 	uint32_t pp_support_state = 0;
5885a8ca3413SRex Zhu 
58868a19e7faSRex Zhu 	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
58878a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
58888a19e7faSRex Zhu 			pp_support_state = PP_STATE_SUPPORT_LS;
58898a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
58908a19e7faSRex Zhu 		}
58918a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
58928a19e7faSRex Zhu 			pp_support_state |= PP_STATE_SUPPORT_CG;
58938a19e7faSRex Zhu 			pp_state |= PP_STATE_CG;
58948a19e7faSRex Zhu 		}
58958a19e7faSRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
58968a19e7faSRex Zhu 			pp_state = 0;
58978a19e7faSRex Zhu 
58988a19e7faSRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
58998a19e7faSRex Zhu 				PP_BLOCK_GFX_CG,
59008a19e7faSRex Zhu 				pp_support_state,
59018a19e7faSRex Zhu 				pp_state);
59023811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
59038a19e7faSRex Zhu 	}
59048a19e7faSRex Zhu 
59058a19e7faSRex Zhu 	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_3D_CGCG | AMD_CG_SUPPORT_GFX_3D_CGLS)) {
59068a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGLS) {
59078a19e7faSRex Zhu 			pp_support_state = PP_STATE_SUPPORT_LS;
59088a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
59098a19e7faSRex Zhu 		}
59108a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGCG) {
59118a19e7faSRex Zhu 			pp_support_state |= PP_STATE_SUPPORT_CG;
59128a19e7faSRex Zhu 			pp_state |= PP_STATE_CG;
59138a19e7faSRex Zhu 		}
59148a19e7faSRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
59158a19e7faSRex Zhu 			pp_state = 0;
59168a19e7faSRex Zhu 
59178a19e7faSRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
59188a19e7faSRex Zhu 				PP_BLOCK_GFX_3D,
59198a19e7faSRex Zhu 				pp_support_state,
59208a19e7faSRex Zhu 				pp_state);
59213811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
59228a19e7faSRex Zhu 	}
59238a19e7faSRex Zhu 
59248a19e7faSRex Zhu 	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
59258a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
59268a19e7faSRex Zhu 			pp_support_state = PP_STATE_SUPPORT_LS;
59278a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
59288a19e7faSRex Zhu 		}
59298a19e7faSRex Zhu 
59308a19e7faSRex Zhu 		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
59318a19e7faSRex Zhu 			pp_support_state |= PP_STATE_SUPPORT_CG;
59328a19e7faSRex Zhu 			pp_state |= PP_STATE_CG;
59338a19e7faSRex Zhu 		}
59348a19e7faSRex Zhu 
59358a19e7faSRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
59368a19e7faSRex Zhu 			pp_state = 0;
59378a19e7faSRex Zhu 
59388a19e7faSRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
59398a19e7faSRex Zhu 				PP_BLOCK_GFX_MG,
59408a19e7faSRex Zhu 				pp_support_state,
59418a19e7faSRex Zhu 				pp_state);
59423811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
59438a19e7faSRex Zhu 	}
59448a19e7faSRex Zhu 
59458a19e7faSRex Zhu 	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
59468a19e7faSRex Zhu 		pp_support_state = PP_STATE_SUPPORT_LS;
59478a19e7faSRex Zhu 
5948a8ca3413SRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
5949a8ca3413SRex Zhu 			pp_state = 0;
5950a8ca3413SRex Zhu 		else
59518a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
5952a8ca3413SRex Zhu 
5953a8ca3413SRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5954a8ca3413SRex Zhu 				PP_BLOCK_GFX_RLC,
59558a19e7faSRex Zhu 				pp_support_state,
5956a8ca3413SRex Zhu 				pp_state);
59573811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
59588a19e7faSRex Zhu 	}
5959a8ca3413SRex Zhu 
59608a19e7faSRex Zhu 	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
59618a19e7faSRex Zhu 		pp_support_state = PP_STATE_SUPPORT_LS;
59628a19e7faSRex Zhu 
59638a19e7faSRex Zhu 		if (state == AMD_CG_STATE_UNGATE)
59648a19e7faSRex Zhu 			pp_state = 0;
59658a19e7faSRex Zhu 		else
59668a19e7faSRex Zhu 			pp_state = PP_STATE_LS;
5967a8ca3413SRex Zhu 		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5968a8ca3413SRex Zhu 			PP_BLOCK_GFX_CP,
59698a19e7faSRex Zhu 			pp_support_state,
5970a8ca3413SRex Zhu 			pp_state);
59713811f8f0SRex Zhu 		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
59728a19e7faSRex Zhu 	}
5973a8ca3413SRex Zhu 
5974a8ca3413SRex Zhu 	return 0;
5975a8ca3413SRex Zhu }
5976a8ca3413SRex Zhu 
gfx_v8_0_set_clockgating_state(void * handle,enum amd_clockgating_state state)59775fc3aeebSyanyang1 static int gfx_v8_0_set_clockgating_state(void *handle,
59785fc3aeebSyanyang1 					  enum amd_clockgating_state state)
5979aaa36a97SAlex Deucher {
59806e378858SEric Huang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
59816e378858SEric Huang 
5982ce137c04SMonk Liu 	if (amdgpu_sriov_vf(adev))
5983ce137c04SMonk Liu 		return 0;
5984ce137c04SMonk Liu 
59856e378858SEric Huang 	switch (adev->asic_type) {
59866e378858SEric Huang 	case CHIP_FIJI:
5987dbff57bcSAlex Deucher 	case CHIP_CARRIZO:
5988dbff57bcSAlex Deucher 	case CHIP_STONEY:
5989dbff57bcSAlex Deucher 		gfx_v8_0_update_gfx_clock_gating(adev,
59907e913664SAndrew F. Davis 						 state == AMD_CG_STATE_GATE);
59916e378858SEric Huang 		break;
5992a8ca3413SRex Zhu 	case CHIP_TONGA:
5993a8ca3413SRex Zhu 		gfx_v8_0_tonga_update_gfx_clock_gating(adev, state);
5994a8ca3413SRex Zhu 		break;
5995a8ca3413SRex Zhu 	case CHIP_POLARIS10:
5996a8ca3413SRex Zhu 	case CHIP_POLARIS11:
5997739e9fffSRex Zhu 	case CHIP_POLARIS12:
599871765469SLeo Liu 	case CHIP_VEGAM:
5999a8ca3413SRex Zhu 		gfx_v8_0_polaris_update_gfx_clock_gating(adev, state);
6000a8ca3413SRex Zhu 		break;
60016e378858SEric Huang 	default:
60026e378858SEric Huang 		break;
60036e378858SEric Huang 	}
6004aaa36a97SAlex Deucher 	return 0;
6005aaa36a97SAlex Deucher }
6006aaa36a97SAlex Deucher 
gfx_v8_0_ring_get_rptr(struct amdgpu_ring * ring)6007536fbf94SKen Wang static u64 gfx_v8_0_ring_get_rptr(struct amdgpu_ring *ring)
6008aaa36a97SAlex Deucher {
60093748424bSJack Xiao 	return *ring->rptr_cpu_addr;
6010aaa36a97SAlex Deucher }
6011aaa36a97SAlex Deucher 
gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring * ring)6012536fbf94SKen Wang static u64 gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
6013aaa36a97SAlex Deucher {
6014aaa36a97SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
6015aaa36a97SAlex Deucher 
6016aaa36a97SAlex Deucher 	if (ring->use_doorbell)
6017aaa36a97SAlex Deucher 		/* XXX check if swapping is necessary on BE */
60183748424bSJack Xiao 		return *ring->wptr_cpu_addr;
6019aaa36a97SAlex Deucher 	else
60205003f278STom St Denis 		return RREG32(mmCP_RB0_WPTR);
6021aaa36a97SAlex Deucher }
6022aaa36a97SAlex Deucher 
gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring * ring)6023aaa36a97SAlex Deucher static void gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
6024aaa36a97SAlex Deucher {
6025aaa36a97SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
6026aaa36a97SAlex Deucher 
6027aaa36a97SAlex Deucher 	if (ring->use_doorbell) {
6028aaa36a97SAlex Deucher 		/* XXX check if swapping is necessary on BE */
60293748424bSJack Xiao 		*ring->wptr_cpu_addr = lower_32_bits(ring->wptr);
6030536fbf94SKen Wang 		WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6031aaa36a97SAlex Deucher 	} else {
6032536fbf94SKen Wang 		WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
6033aaa36a97SAlex Deucher 		(void)RREG32(mmCP_RB0_WPTR);
6034aaa36a97SAlex Deucher 	}
6035aaa36a97SAlex Deucher }
6036aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring * ring)6037d2edb07bSChristian König static void gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
6038aaa36a97SAlex Deucher {
6039aaa36a97SAlex Deucher 	u32 ref_and_mask, reg_mem_engine;
6040aaa36a97SAlex Deucher 
60414e638ae9SXiangliang Yu 	if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) ||
60424e638ae9SXiangliang Yu 	    (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)) {
6043aaa36a97SAlex Deucher 		switch (ring->me) {
6044aaa36a97SAlex Deucher 		case 1:
6045aaa36a97SAlex Deucher 			ref_and_mask = GPU_HDP_FLUSH_DONE__CP2_MASK << ring->pipe;
6046aaa36a97SAlex Deucher 			break;
6047aaa36a97SAlex Deucher 		case 2:
6048aaa36a97SAlex Deucher 			ref_and_mask = GPU_HDP_FLUSH_DONE__CP6_MASK << ring->pipe;
6049aaa36a97SAlex Deucher 			break;
6050aaa36a97SAlex Deucher 		default:
6051aaa36a97SAlex Deucher 			return;
6052aaa36a97SAlex Deucher 		}
6053aaa36a97SAlex Deucher 		reg_mem_engine = 0;
6054aaa36a97SAlex Deucher 	} else {
6055aaa36a97SAlex Deucher 		ref_and_mask = GPU_HDP_FLUSH_DONE__CP0_MASK;
6056aaa36a97SAlex Deucher 		reg_mem_engine = WAIT_REG_MEM_ENGINE(1); /* pfp */
6057aaa36a97SAlex Deucher 	}
6058aaa36a97SAlex Deucher 
6059aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6060aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
6061aaa36a97SAlex Deucher 				 WAIT_REG_MEM_FUNCTION(3) |  /* == */
6062aaa36a97SAlex Deucher 				 reg_mem_engine));
6063aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ);
6064aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE);
6065aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, ref_and_mask);
6066aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, ref_and_mask);
6067aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x20); /* poll interval */
6068aaa36a97SAlex Deucher }
6069aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring * ring)607045682886SMonk Liu static void gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)
607145682886SMonk Liu {
607245682886SMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
607345682886SMonk Liu 	amdgpu_ring_write(ring, EVENT_TYPE(VS_PARTIAL_FLUSH) |
607445682886SMonk Liu 		EVENT_INDEX(4));
607545682886SMonk Liu 
607645682886SMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
607745682886SMonk Liu 	amdgpu_ring_write(ring, EVENT_TYPE(VGT_FLUSH) |
607845682886SMonk Liu 		EVENT_INDEX(0));
607945682886SMonk Liu }
608045682886SMonk Liu 
gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring * ring,struct amdgpu_job * job,struct amdgpu_ib * ib,uint32_t flags)608193323131Smonk.liu static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
608234955e03SRex Zhu 					struct amdgpu_job *job,
6083d88bf583SChristian König 					struct amdgpu_ib *ib,
6084c4c905ecSJack Xiao 					uint32_t flags)
6085aaa36a97SAlex Deucher {
608634955e03SRex Zhu 	unsigned vmid = AMDGPU_JOB_GET_VMID(job);
6087aaa36a97SAlex Deucher 	u32 header, control = 0;
6088aaa36a97SAlex Deucher 
6089de807f81SJammy Zhou 	if (ib->flags & AMDGPU_IB_FLAG_CE)
6090aaa36a97SAlex Deucher 		header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
6091aaa36a97SAlex Deucher 	else
6092aaa36a97SAlex Deucher 		header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
6093aaa36a97SAlex Deucher 
6094c4f46f22SChristian König 	control |= ib->length_dw | (vmid << 24);
6095aaa36a97SAlex Deucher 
6096635e7132SMonk Liu 	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
60972e2e3c7fSMonk Liu 		control |= INDIRECT_BUFFER_PRE_ENB(1);
60982e2e3c7fSMonk Liu 
6099752c683dSMonk Liu 		if (!(ib->flags & AMDGPU_IB_FLAG_CE) && vmid)
6100635e7132SMonk Liu 			gfx_v8_0_ring_emit_de_meta(ring);
6101635e7132SMonk Liu 	}
6102635e7132SMonk Liu 
6103aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, header);
6104aaa36a97SAlex Deucher 	amdgpu_ring_write(ring,
6105aaa36a97SAlex Deucher #ifdef __BIG_ENDIAN
6106aaa36a97SAlex Deucher 			  (2 << 0) |
6107aaa36a97SAlex Deucher #endif
6108aaa36a97SAlex Deucher 			  (ib->gpu_addr & 0xFFFFFFFC));
6109aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
6110aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, control);
6111aaa36a97SAlex Deucher }
6112aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring * ring,struct amdgpu_job * job,struct amdgpu_ib * ib,uint32_t flags)611393323131Smonk.liu static void gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
611434955e03SRex Zhu 					  struct amdgpu_job *job,
6115d88bf583SChristian König 					  struct amdgpu_ib *ib,
6116c4c905ecSJack Xiao 					  uint32_t flags)
611793323131Smonk.liu {
611834955e03SRex Zhu 	unsigned vmid = AMDGPU_JOB_GET_VMID(job);
6119c4f46f22SChristian König 	u32 control = INDIRECT_BUFFER_VALID | ib->length_dw | (vmid << 24);
612093323131Smonk.liu 
612141cca166SMarek Olšák 	/* Currently, there is a high possibility to get wave ID mismatch
612241cca166SMarek Olšák 	 * between ME and GDS, leading to a hw deadlock, because ME generates
612341cca166SMarek Olšák 	 * different wave IDs than the GDS expects. This situation happens
612441cca166SMarek Olšák 	 * randomly when at least 5 compute pipes use GDS ordered append.
612541cca166SMarek Olšák 	 * The wave IDs generated by ME are also wrong after suspend/resume.
612641cca166SMarek Olšák 	 * Those are probably bugs somewhere else in the kernel driver.
612741cca166SMarek Olšák 	 *
612841cca166SMarek Olšák 	 * Writing GDS_COMPUTE_MAX_WAVE_ID resets wave ID counters in ME and
612941cca166SMarek Olšák 	 * GDS to 0 for this ring (me/pipe).
613041cca166SMarek Olšák 	 */
613141cca166SMarek Olšák 	if (ib->flags & AMDGPU_IB_FLAG_RESET_GDS_MAX_WAVE_ID) {
613241cca166SMarek Olšák 		amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
613341cca166SMarek Olšák 		amdgpu_ring_write(ring, mmGDS_COMPUTE_MAX_WAVE_ID - PACKET3_SET_CONFIG_REG_START);
613441cca166SMarek Olšák 		amdgpu_ring_write(ring, ring->adev->gds.gds_compute_max_wave_id);
613541cca166SMarek Olšák 	}
613641cca166SMarek Olšák 
613733b7ed01SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
613893323131Smonk.liu 	amdgpu_ring_write(ring,
613993323131Smonk.liu #ifdef __BIG_ENDIAN
614093323131Smonk.liu 				(2 << 0) |
614193323131Smonk.liu #endif
614293323131Smonk.liu 				(ib->gpu_addr & 0xFFFFFFFC));
614393323131Smonk.liu 	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
614493323131Smonk.liu 	amdgpu_ring_write(ring, control);
614593323131Smonk.liu }
614693323131Smonk.liu 
gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring * ring,u64 addr,u64 seq,unsigned flags)6147aaa36a97SAlex Deucher static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr,
6148890ee23fSChunming Zhou 					 u64 seq, unsigned flags)
6149aaa36a97SAlex Deucher {
6150890ee23fSChunming Zhou 	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6151890ee23fSChunming Zhou 	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
6152*4af8071bSAlex Deucher 	bool exec = flags & AMDGPU_FENCE_FLAG_EXEC;
6153890ee23fSChunming Zhou 
6154b456c932SPierre-Eric Pelloux-Prayer 	/* Workaround for cache flush problems. First send a dummy EOP
6155b456c932SPierre-Eric Pelloux-Prayer 	 * event down the pipe with seq one below.
6156b456c932SPierre-Eric Pelloux-Prayer 	 */
6157b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
6158b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6159b456c932SPierre-Eric Pelloux-Prayer 				 EOP_TC_ACTION_EN |
6160b456c932SPierre-Eric Pelloux-Prayer 				 EOP_TC_WB_ACTION_EN |
6161b456c932SPierre-Eric Pelloux-Prayer 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6162b456c932SPierre-Eric Pelloux-Prayer 				 EVENT_INDEX(5)));
6163b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, addr & 0xfffffffc);
6164b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
6165b456c932SPierre-Eric Pelloux-Prayer 				DATA_SEL(1) | INT_SEL(0));
6166b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, lower_32_bits(seq - 1));
6167b456c932SPierre-Eric Pelloux-Prayer 	amdgpu_ring_write(ring, upper_32_bits(seq - 1));
6168b456c932SPierre-Eric Pelloux-Prayer 
6169b456c932SPierre-Eric Pelloux-Prayer 	/* Then send the real EOP event down the pipe:
6170b456c932SPierre-Eric Pelloux-Prayer 	 * EVENT_WRITE_EOP - flush caches, send int */
6171aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
6172aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6173aaa36a97SAlex Deucher 				 EOP_TC_ACTION_EN |
6174f84e63f2SMarek Olšák 				 EOP_TC_WB_ACTION_EN |
6175aaa36a97SAlex Deucher 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6176*4af8071bSAlex Deucher 				 EVENT_INDEX(5) |
6177*4af8071bSAlex Deucher 				 (exec ? EOP_EXEC : 0)));
6178aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, addr & 0xfffffffc);
6179aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
6180890ee23fSChunming Zhou 			  DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6181aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, lower_32_bits(seq));
6182aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, upper_32_bits(seq));
618322c01cc4SAnatoli Antonovitch 
6184aaa36a97SAlex Deucher }
6185aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring * ring)6186b8c7b39eSChristian König static void gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
6187aaa36a97SAlex Deucher {
618821cd942eSChristian König 	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
61895907a0d8SChristian König 	uint32_t seq = ring->fence_drv.sync_seq;
619022c01cc4SAnatoli Antonovitch 	uint64_t addr = ring->fence_drv.gpu_addr;
619122c01cc4SAnatoli Antonovitch 
619222c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
619322c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
61949cac5373SChunming Zhou 				 WAIT_REG_MEM_FUNCTION(3) | /* equal */
61959cac5373SChunming Zhou 				 WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
619622c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, addr & 0xfffffffc);
619722c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
619822c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, seq);
619922c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, 0xffffffff);
620022c01cc4SAnatoli Antonovitch 	amdgpu_ring_write(ring, 4); /* poll interval */
6201b8c7b39eSChristian König }
6202b8c7b39eSChristian König 
gfx_v8_0_ring_emit_vm_flush(struct amdgpu_ring * ring,unsigned vmid,uint64_t pd_addr)6203b8c7b39eSChristian König static void gfx_v8_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
6204c633c00bSChristian König 					unsigned vmid, uint64_t pd_addr)
6205b8c7b39eSChristian König {
620621cd942eSChristian König 	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
62075c3422b0Smonk.liu 
6208c633c00bSChristian König 	amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
6209aaa36a97SAlex Deucher 
6210aaa36a97SAlex Deucher 	/* wait for the invalidate to complete */
6211aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6212aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
6213aaa36a97SAlex Deucher 				 WAIT_REG_MEM_FUNCTION(0) |  /* always */
6214aaa36a97SAlex Deucher 				 WAIT_REG_MEM_ENGINE(0))); /* me */
6215aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
6216aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0);
6217aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0); /* ref */
6218aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0); /* mask */
6219aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, 0x20); /* poll interval */
6220aaa36a97SAlex Deucher 
6221aaa36a97SAlex Deucher 	/* compute doesn't have PFP */
6222aaa36a97SAlex Deucher 	if (usepfp) {
6223aaa36a97SAlex Deucher 		/* sync PFP to ME, otherwise we might get invalid PFP reads */
6224aaa36a97SAlex Deucher 		amdgpu_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
6225aaa36a97SAlex Deucher 		amdgpu_ring_write(ring, 0x0);
6226aaa36a97SAlex Deucher 	}
6227aaa36a97SAlex Deucher }
6228aaa36a97SAlex Deucher 
gfx_v8_0_ring_get_wptr_compute(struct amdgpu_ring * ring)6229536fbf94SKen Wang static u64 gfx_v8_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
6230aaa36a97SAlex Deucher {
62313748424bSJack Xiao 	return *ring->wptr_cpu_addr;
6232aaa36a97SAlex Deucher }
6233aaa36a97SAlex Deucher 
gfx_v8_0_ring_set_wptr_compute(struct amdgpu_ring * ring)6234aaa36a97SAlex Deucher static void gfx_v8_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
6235aaa36a97SAlex Deucher {
6236aaa36a97SAlex Deucher 	struct amdgpu_device *adev = ring->adev;
6237aaa36a97SAlex Deucher 
6238aaa36a97SAlex Deucher 	/* XXX check if swapping is necessary on BE */
62393748424bSJack Xiao 	*ring->wptr_cpu_addr = lower_32_bits(ring->wptr);
6240536fbf94SKen Wang 	WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6241aaa36a97SAlex Deucher }
6242aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_fence_compute(struct amdgpu_ring * ring,u64 addr,u64 seq,unsigned flags)6243aaa36a97SAlex Deucher static void gfx_v8_0_ring_emit_fence_compute(struct amdgpu_ring *ring,
6244aaa36a97SAlex Deucher 					     u64 addr, u64 seq,
6245890ee23fSChunming Zhou 					     unsigned flags)
6246aaa36a97SAlex Deucher {
6247890ee23fSChunming Zhou 	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6248890ee23fSChunming Zhou 	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
6249890ee23fSChunming Zhou 
6250aaa36a97SAlex Deucher 	/* RELEASE_MEM - flush caches, send int */
6251aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
6252aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6253aaa36a97SAlex Deucher 				 EOP_TC_ACTION_EN |
6254a3d5aaa8SAlex Deucher 				 EOP_TC_WB_ACTION_EN |
6255aaa36a97SAlex Deucher 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6256aaa36a97SAlex Deucher 				 EVENT_INDEX(5)));
6257890ee23fSChunming Zhou 	amdgpu_ring_write(ring, DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6258aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, addr & 0xfffffffc);
6259aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, upper_32_bits(addr));
6260aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, lower_32_bits(seq));
6261aaa36a97SAlex Deucher 	amdgpu_ring_write(ring, upper_32_bits(seq));
6262aaa36a97SAlex Deucher }
6263aaa36a97SAlex Deucher 
gfx_v8_0_ring_emit_fence_kiq(struct amdgpu_ring * ring,u64 addr,u64 seq,unsigned int flags)62644e638ae9SXiangliang Yu static void gfx_v8_0_ring_emit_fence_kiq(struct amdgpu_ring *ring, u64 addr,
62654e638ae9SXiangliang Yu 					 u64 seq, unsigned int flags)
62664e638ae9SXiangliang Yu {
62674e638ae9SXiangliang Yu 	/* we only allocate 32bit for each seq wb address */
6268f10b478dSJulia Lawall 	BUG_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
62694e638ae9SXiangliang Yu 
62704e638ae9SXiangliang Yu 	/* write fence seq to the "addr" */
62714e638ae9SXiangliang Yu 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
62724e638ae9SXiangliang Yu 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
62734e638ae9SXiangliang Yu 				 WRITE_DATA_DST_SEL(5) | WR_CONFIRM));
62744e638ae9SXiangliang Yu 	amdgpu_ring_write(ring, lower_32_bits(addr));
62754e638ae9SXiangliang Yu 	amdgpu_ring_write(ring, upper_32_bits(addr));
62764e638ae9SXiangliang Yu 	amdgpu_ring_write(ring, lower_32_bits(seq));
62774e638ae9SXiangliang Yu 
62784e638ae9SXiangliang Yu 	if (flags & AMDGPU_FENCE_FLAG_INT) {
62794e638ae9SXiangliang Yu 		/* set register to trigger INT */
62804e638ae9SXiangliang Yu 		amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
62814e638ae9SXiangliang Yu 		amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
62824e638ae9SXiangliang Yu 					 WRITE_DATA_DST_SEL(0) | WR_CONFIRM));
62834e638ae9SXiangliang Yu 		amdgpu_ring_write(ring, mmCPC_INT_STATUS);
62844e638ae9SXiangliang Yu 		amdgpu_ring_write(ring, 0);
62854e638ae9SXiangliang Yu 		amdgpu_ring_write(ring, 0x20000000); /* src_id is 178 */
62864e638ae9SXiangliang Yu 	}
62874e638ae9SXiangliang Yu }
62884e638ae9SXiangliang Yu 
gfx_v8_ring_emit_sb(struct amdgpu_ring * ring)6289c2167a65SMonk Liu static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
6290c2167a65SMonk Liu {
6291c2167a65SMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
6292c2167a65SMonk Liu 	amdgpu_ring_write(ring, 0);
6293c2167a65SMonk Liu }
6294c2167a65SMonk Liu 
gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring * ring,uint32_t flags)6295753ad49cSMonk Liu static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
6296753ad49cSMonk Liu {
6297753ad49cSMonk Liu 	uint32_t dw2 = 0;
6298753ad49cSMonk Liu 
6299c2ce92fcSMonk Liu 	if (amdgpu_sriov_vf(ring->adev))
630095243543SMonk Liu 		gfx_v8_0_ring_emit_ce_meta(ring);
6301c2ce92fcSMonk Liu 
6302753ad49cSMonk Liu 	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
6303753ad49cSMonk Liu 	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
630445682886SMonk Liu 		gfx_v8_0_ring_emit_vgt_flush(ring);
6305753ad49cSMonk Liu 		/* set load_global_config & load_global_uconfig */
6306753ad49cSMonk Liu 		dw2 |= 0x8001;
6307753ad49cSMonk Liu 		/* set load_cs_sh_regs */
6308753ad49cSMonk Liu 		dw2 |= 0x01000000;
6309753ad49cSMonk Liu 		/* set load_per_context_state & load_gfx_sh_regs for GFX */
6310753ad49cSMonk Liu 		dw2 |= 0x10002;
6311753ad49cSMonk Liu 
6312753ad49cSMonk Liu 		/* set load_ce_ram if preamble presented */
6313753ad49cSMonk Liu 		if (AMDGPU_PREAMBLE_IB_PRESENT & flags)
6314753ad49cSMonk Liu 			dw2 |= 0x10000000;
6315753ad49cSMonk Liu 	} else {
6316753ad49cSMonk Liu 		/* still load_ce_ram if this is the first time preamble presented
6317753ad49cSMonk Liu 		 * although there is no context switch happens.
6318753ad49cSMonk Liu 		 */
6319753ad49cSMonk Liu 		if (AMDGPU_PREAMBLE_IB_PRESENT_FIRST & flags)
6320753ad49cSMonk Liu 			dw2 |= 0x10000000;
6321753ad49cSMonk Liu 	}
6322753ad49cSMonk Liu 
6323753ad49cSMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
6324753ad49cSMonk Liu 	amdgpu_ring_write(ring, dw2);
6325753ad49cSMonk Liu 	amdgpu_ring_write(ring, 0);
6326753ad49cSMonk Liu }
6327753ad49cSMonk Liu 
gfx_v8_0_ring_emit_init_cond_exec(struct amdgpu_ring * ring,uint64_t addr)6328c68cbbfdSChristian König static unsigned gfx_v8_0_ring_emit_init_cond_exec(struct amdgpu_ring *ring,
6329c68cbbfdSChristian König 						  uint64_t addr)
6330806ba2d4SMonk Liu {
6331806ba2d4SMonk Liu 	unsigned ret;
6332806ba2d4SMonk Liu 
6333806ba2d4SMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_COND_EXEC, 3));
6334c68cbbfdSChristian König 	amdgpu_ring_write(ring, lower_32_bits(addr));
6335c68cbbfdSChristian König 	amdgpu_ring_write(ring, upper_32_bits(addr));
6336c68cbbfdSChristian König 	/* discard following DWs if *cond_exec_gpu_addr==0 */
6337c68cbbfdSChristian König 	amdgpu_ring_write(ring, 0);
6338806ba2d4SMonk Liu 	ret = ring->wptr & ring->buf_mask;
6339c68cbbfdSChristian König 	/* patch dummy value later */
6340c68cbbfdSChristian König 	amdgpu_ring_write(ring, 0);
6341806ba2d4SMonk Liu 	return ret;
6342806ba2d4SMonk Liu }
6343806ba2d4SMonk Liu 
gfx_v8_0_ring_emit_rreg(struct amdgpu_ring * ring,uint32_t reg,uint32_t reg_val_offs)634454208194SYintian Tao static void gfx_v8_0_ring_emit_rreg(struct amdgpu_ring *ring, uint32_t reg,
634554208194SYintian Tao 				    uint32_t reg_val_offs)
6346880e87e3SXiangliang Yu {
6347880e87e3SXiangliang Yu 	struct amdgpu_device *adev = ring->adev;
6348880e87e3SXiangliang Yu 
6349880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, PACKET3(PACKET3_COPY_DATA, 4));
6350880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, 0 |	/* src: register*/
6351880e87e3SXiangliang Yu 				(5 << 8) |	/* dst: memory */
6352880e87e3SXiangliang Yu 				(1 << 20));	/* write confirm */
6353880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, reg);
6354880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, 0);
6355880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, lower_32_bits(adev->wb.gpu_addr +
635654208194SYintian Tao 				reg_val_offs * 4));
6357880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, upper_32_bits(adev->wb.gpu_addr +
635854208194SYintian Tao 				reg_val_offs * 4));
6359880e87e3SXiangliang Yu }
6360880e87e3SXiangliang Yu 
gfx_v8_0_ring_emit_wreg(struct amdgpu_ring * ring,uint32_t reg,uint32_t val)6361880e87e3SXiangliang Yu static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
6362880e87e3SXiangliang Yu 				  uint32_t val)
6363880e87e3SXiangliang Yu {
63649ed88047SChristian König 	uint32_t cmd;
63659ed88047SChristian König 
63669ed88047SChristian König 	switch (ring->funcs->type) {
63679ed88047SChristian König 	case AMDGPU_RING_TYPE_GFX:
63689ed88047SChristian König 		cmd = WRITE_DATA_ENGINE_SEL(1) | WR_CONFIRM;
63699ed88047SChristian König 		break;
63709ed88047SChristian König 	case AMDGPU_RING_TYPE_KIQ:
63719ed88047SChristian König 		cmd = 1 << 16; /* no inc addr */
63729ed88047SChristian König 		break;
63739ed88047SChristian König 	default:
63749ed88047SChristian König 		cmd = WR_CONFIRM;
63759ed88047SChristian König 		break;
63769ed88047SChristian König 	}
63779ed88047SChristian König 
6378880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
63799ed88047SChristian König 	amdgpu_ring_write(ring, cmd);
6380880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, reg);
6381880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, 0);
6382880e87e3SXiangliang Yu 	amdgpu_ring_write(ring, val);
6383880e87e3SXiangliang Yu }
6384880e87e3SXiangliang Yu 
gfx_v8_0_wait_reg_mem(struct amdgpu_ring * ring,int eng_sel,int mem_space,int opt,uint32_t addr0,uint32_t addr1,uint32_t ref,uint32_t mask,uint32_t inv)6385*4af8071bSAlex Deucher static void gfx_v8_0_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel,
6386*4af8071bSAlex Deucher 				  int mem_space, int opt, uint32_t addr0,
6387*4af8071bSAlex Deucher 				  uint32_t addr1, uint32_t ref, uint32_t mask,
6388*4af8071bSAlex Deucher 				  uint32_t inv)
6389*4af8071bSAlex Deucher {
6390*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6391*4af8071bSAlex Deucher 	amdgpu_ring_write(ring,
6392*4af8071bSAlex Deucher 			  /* memory (1) or register (0) */
6393*4af8071bSAlex Deucher 			  (WAIT_REG_MEM_MEM_SPACE(mem_space) |
6394*4af8071bSAlex Deucher 			   WAIT_REG_MEM_OPERATION(opt) | /* wait */
6395*4af8071bSAlex Deucher 			   WAIT_REG_MEM_FUNCTION(3) |  /* equal */
6396*4af8071bSAlex Deucher 			   WAIT_REG_MEM_ENGINE(eng_sel)));
6397*4af8071bSAlex Deucher 
6398*4af8071bSAlex Deucher 	if (mem_space)
6399*4af8071bSAlex Deucher 		BUG_ON(addr0 & 0x3); /* Dword align */
6400*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, addr0);
6401*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, addr1);
6402*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, ref);
6403*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, mask);
6404*4af8071bSAlex Deucher 	amdgpu_ring_write(ring, inv); /* poll interval */
6405*4af8071bSAlex Deucher }
6406*4af8071bSAlex Deucher 
gfx_v8_0_ring_emit_reg_wait(struct amdgpu_ring * ring,uint32_t reg,uint32_t val,uint32_t mask)6407*4af8071bSAlex Deucher static void gfx_v8_0_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
6408*4af8071bSAlex Deucher 					uint32_t val, uint32_t mask)
6409*4af8071bSAlex Deucher {
6410*4af8071bSAlex Deucher 	gfx_v8_0_wait_reg_mem(ring, 0, 0, 0, reg, 0, val, mask, 0x20);
6411*4af8071bSAlex Deucher }
6412*4af8071bSAlex Deucher 
gfx_v8_0_ring_soft_recovery(struct amdgpu_ring * ring,unsigned vmid)6413f5d85033SChristian König static void gfx_v8_0_ring_soft_recovery(struct amdgpu_ring *ring, unsigned vmid)
6414f5d85033SChristian König {
6415f5d85033SChristian König 	struct amdgpu_device *adev = ring->adev;
6416f5d85033SChristian König 	uint32_t value = 0;
6417f5d85033SChristian König 
6418f5d85033SChristian König 	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
6419f5d85033SChristian König 	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
6420f5d85033SChristian König 	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
6421f5d85033SChristian König 	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
6422f5d85033SChristian König 	WREG32(mmSQ_CMD, value);
6423f5d85033SChristian König }
6424f5d85033SChristian König 
gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device * adev,enum amdgpu_interrupt_state state)6425aaa36a97SAlex Deucher static void gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
6426aaa36a97SAlex Deucher 						 enum amdgpu_interrupt_state state)
6427aaa36a97SAlex Deucher {
642861cb8cefSTom St Denis 	WREG32_FIELD(CP_INT_CNTL_RING0, TIME_STAMP_INT_ENABLE,
642961cb8cefSTom St Denis 		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6430aaa36a97SAlex Deucher }
6431aaa36a97SAlex Deucher 
gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device * adev,int me,int pipe,enum amdgpu_interrupt_state state)6432aaa36a97SAlex Deucher static void gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
6433aaa36a97SAlex Deucher 						     int me, int pipe,
6434aaa36a97SAlex Deucher 						     enum amdgpu_interrupt_state state)
6435aaa36a97SAlex Deucher {
6436d0c55cdfSAlex Deucher 	u32 mec_int_cntl, mec_int_cntl_reg;
6437d0c55cdfSAlex Deucher 
6438aaa36a97SAlex Deucher 	/*
6439d0c55cdfSAlex Deucher 	 * amdgpu controls only the first MEC. That's why this function only
6440d0c55cdfSAlex Deucher 	 * handles the setting of interrupts for this specific MEC. All other
6441aaa36a97SAlex Deucher 	 * pipes' interrupts are set by amdkfd.
6442aaa36a97SAlex Deucher 	 */
6443aaa36a97SAlex Deucher 
6444aaa36a97SAlex Deucher 	if (me == 1) {
6445aaa36a97SAlex Deucher 		switch (pipe) {
6446aaa36a97SAlex Deucher 		case 0:
6447d0c55cdfSAlex Deucher 			mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
6448d0c55cdfSAlex Deucher 			break;
6449d0c55cdfSAlex Deucher 		case 1:
6450d0c55cdfSAlex Deucher 			mec_int_cntl_reg = mmCP_ME1_PIPE1_INT_CNTL;
6451d0c55cdfSAlex Deucher 			break;
6452d0c55cdfSAlex Deucher 		case 2:
6453d0c55cdfSAlex Deucher 			mec_int_cntl_reg = mmCP_ME1_PIPE2_INT_CNTL;
6454d0c55cdfSAlex Deucher 			break;
6455d0c55cdfSAlex Deucher 		case 3:
6456d0c55cdfSAlex Deucher 			mec_int_cntl_reg = mmCP_ME1_PIPE3_INT_CNTL;
6457aaa36a97SAlex Deucher 			break;
6458aaa36a97SAlex Deucher 		default:
6459aaa36a97SAlex Deucher 			DRM_DEBUG("invalid pipe %d\n", pipe);
6460aaa36a97SAlex Deucher 			return;
6461aaa36a97SAlex Deucher 		}
6462aaa36a97SAlex Deucher 	} else {
6463aaa36a97SAlex Deucher 		DRM_DEBUG("invalid me %d\n", me);
6464aaa36a97SAlex Deucher 		return;
6465aaa36a97SAlex Deucher 	}
6466aaa36a97SAlex Deucher 
6467d0c55cdfSAlex Deucher 	switch (state) {
6468d0c55cdfSAlex Deucher 	case AMDGPU_IRQ_STATE_DISABLE:
6469d0c55cdfSAlex Deucher 		mec_int_cntl = RREG32(mec_int_cntl_reg);
6470d0c55cdfSAlex Deucher 		mec_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6471d0c55cdfSAlex Deucher 		WREG32(mec_int_cntl_reg, mec_int_cntl);
6472d0c55cdfSAlex Deucher 		break;
6473d0c55cdfSAlex Deucher 	case AMDGPU_IRQ_STATE_ENABLE:
6474d0c55cdfSAlex Deucher 		mec_int_cntl = RREG32(mec_int_cntl_reg);
6475d0c55cdfSAlex Deucher 		mec_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6476d0c55cdfSAlex Deucher 		WREG32(mec_int_cntl_reg, mec_int_cntl);
6477d0c55cdfSAlex Deucher 		break;
6478d0c55cdfSAlex Deucher 	default:
6479d0c55cdfSAlex Deucher 		break;
6480763a47b8SAndres Rodriguez 	}
6481aaa36a97SAlex Deucher }
6482aaa36a97SAlex Deucher 
gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned type,enum amdgpu_interrupt_state state)6483aaa36a97SAlex Deucher static int gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
6484aaa36a97SAlex Deucher 					     struct amdgpu_irq_src *source,
6485aaa36a97SAlex Deucher 					     unsigned type,
6486aaa36a97SAlex Deucher 					     enum amdgpu_interrupt_state state)
6487aaa36a97SAlex Deucher {
648861cb8cefSTom St Denis 	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_REG_INT_ENABLE,
648961cb8cefSTom St Denis 		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6490aaa36a97SAlex Deucher 
6491aaa36a97SAlex Deucher 	return 0;
6492aaa36a97SAlex Deucher }
6493aaa36a97SAlex Deucher 
gfx_v8_0_set_priv_inst_fault_state(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned type,enum amdgpu_interrupt_state state)6494aaa36a97SAlex Deucher static int gfx_v8_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
6495aaa36a97SAlex Deucher 					      struct amdgpu_irq_src *source,
6496aaa36a97SAlex Deucher 					      unsigned type,
6497aaa36a97SAlex Deucher 					      enum amdgpu_interrupt_state state)
6498aaa36a97SAlex Deucher {
649961cb8cefSTom St Denis 	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_INSTR_INT_ENABLE,
650061cb8cefSTom St Denis 		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6501aaa36a97SAlex Deucher 
6502aaa36a97SAlex Deucher 	return 0;
6503aaa36a97SAlex Deucher }
6504aaa36a97SAlex Deucher 
gfx_v8_0_set_eop_interrupt_state(struct amdgpu_device * adev,struct amdgpu_irq_src * src,unsigned type,enum amdgpu_interrupt_state state)6505aaa36a97SAlex Deucher static int gfx_v8_0_set_eop_interrupt_state(struct amdgpu_device *adev,
6506aaa36a97SAlex Deucher 					    struct amdgpu_irq_src *src,
6507aaa36a97SAlex Deucher 					    unsigned type,
6508aaa36a97SAlex Deucher 					    enum amdgpu_interrupt_state state)
6509aaa36a97SAlex Deucher {
6510aaa36a97SAlex Deucher 	switch (type) {
651153b2fe41SHawking Zhang 	case AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP:
6512aaa36a97SAlex Deucher 		gfx_v8_0_set_gfx_eop_interrupt_state(adev, state);
6513aaa36a97SAlex Deucher 		break;
6514aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP:
6515aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 0, state);
6516aaa36a97SAlex Deucher 		break;
6517aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP:
6518aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 1, state);
6519aaa36a97SAlex Deucher 		break;
6520aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP:
6521aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 2, state);
6522aaa36a97SAlex Deucher 		break;
6523aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP:
6524aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 3, state);
6525aaa36a97SAlex Deucher 		break;
6526aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP:
6527aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 0, state);
6528aaa36a97SAlex Deucher 		break;
6529aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP:
6530aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 1, state);
6531aaa36a97SAlex Deucher 		break;
6532aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP:
6533aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 2, state);
6534aaa36a97SAlex Deucher 		break;
6535aaa36a97SAlex Deucher 	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP:
6536aaa36a97SAlex Deucher 		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 3, state);
6537aaa36a97SAlex Deucher 		break;
6538aaa36a97SAlex Deucher 	default:
6539aaa36a97SAlex Deucher 		break;
6540aaa36a97SAlex Deucher 	}
6541aaa36a97SAlex Deucher 	return 0;
6542aaa36a97SAlex Deucher }
6543aaa36a97SAlex Deucher 
gfx_v8_0_set_cp_ecc_int_state(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned int type,enum amdgpu_interrupt_state state)65445a2f2913SDavid Panariti static int gfx_v8_0_set_cp_ecc_int_state(struct amdgpu_device *adev,
65455a2f2913SDavid Panariti 					 struct amdgpu_irq_src *source,
65465a2f2913SDavid Panariti 					 unsigned int type,
65475a2f2913SDavid Panariti 					 enum amdgpu_interrupt_state state)
65485a2f2913SDavid Panariti {
65495a2f2913SDavid Panariti 	int enable_flag;
65505a2f2913SDavid Panariti 
65515a2f2913SDavid Panariti 	switch (state) {
65525a2f2913SDavid Panariti 	case AMDGPU_IRQ_STATE_DISABLE:
65535a2f2913SDavid Panariti 		enable_flag = 0;
65545a2f2913SDavid Panariti 		break;
65555a2f2913SDavid Panariti 
65565a2f2913SDavid Panariti 	case AMDGPU_IRQ_STATE_ENABLE:
65575a2f2913SDavid Panariti 		enable_flag = 1;
65585a2f2913SDavid Panariti 		break;
65595a2f2913SDavid Panariti 
65605a2f2913SDavid Panariti 	default:
65615a2f2913SDavid Panariti 		return -EINVAL;
65625a2f2913SDavid Panariti 	}
65635a2f2913SDavid Panariti 
65645a2f2913SDavid Panariti 	WREG32_FIELD(CP_INT_CNTL, CP_ECC_ERROR_INT_ENABLE, enable_flag);
65655a2f2913SDavid Panariti 	WREG32_FIELD(CP_INT_CNTL_RING0, CP_ECC_ERROR_INT_ENABLE, enable_flag);
65665a2f2913SDavid Panariti 	WREG32_FIELD(CP_INT_CNTL_RING1, CP_ECC_ERROR_INT_ENABLE, enable_flag);
65675a2f2913SDavid Panariti 	WREG32_FIELD(CP_INT_CNTL_RING2, CP_ECC_ERROR_INT_ENABLE, enable_flag);
65685a2f2913SDavid Panariti 	WREG32_FIELD(CPC_INT_CNTL, CP_ECC_ERROR_INT_ENABLE, enable_flag);
65695a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME1_PIPE0_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65705a2f2913SDavid Panariti 		     enable_flag);
65715a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME1_PIPE1_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65725a2f2913SDavid Panariti 		     enable_flag);
65735a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME1_PIPE2_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65745a2f2913SDavid Panariti 		     enable_flag);
65755a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME1_PIPE3_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65765a2f2913SDavid Panariti 		     enable_flag);
65775a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME2_PIPE0_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65785a2f2913SDavid Panariti 		     enable_flag);
65795a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME2_PIPE1_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65805a2f2913SDavid Panariti 		     enable_flag);
65815a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME2_PIPE2_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65825a2f2913SDavid Panariti 		     enable_flag);
65835a2f2913SDavid Panariti 	WREG32_FIELD(CP_ME2_PIPE3_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
65845a2f2913SDavid Panariti 		     enable_flag);
65855a2f2913SDavid Panariti 
65865a2f2913SDavid Panariti 	return 0;
65875a2f2913SDavid Panariti }
65885a2f2913SDavid Panariti 
gfx_v8_0_set_sq_int_state(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned int type,enum amdgpu_interrupt_state state)658904ad26bbSDavid Panariti static int gfx_v8_0_set_sq_int_state(struct amdgpu_device *adev,
659004ad26bbSDavid Panariti 				     struct amdgpu_irq_src *source,
659104ad26bbSDavid Panariti 				     unsigned int type,
659204ad26bbSDavid Panariti 				     enum amdgpu_interrupt_state state)
659304ad26bbSDavid Panariti {
659404ad26bbSDavid Panariti 	int enable_flag;
659504ad26bbSDavid Panariti 
659604ad26bbSDavid Panariti 	switch (state) {
659704ad26bbSDavid Panariti 	case AMDGPU_IRQ_STATE_DISABLE:
659804ad26bbSDavid Panariti 		enable_flag = 1;
659904ad26bbSDavid Panariti 		break;
660004ad26bbSDavid Panariti 
660104ad26bbSDavid Panariti 	case AMDGPU_IRQ_STATE_ENABLE:
660204ad26bbSDavid Panariti 		enable_flag = 0;
660304ad26bbSDavid Panariti 		break;
660404ad26bbSDavid Panariti 
660504ad26bbSDavid Panariti 	default:
660604ad26bbSDavid Panariti 		return -EINVAL;
660704ad26bbSDavid Panariti 	}
660804ad26bbSDavid Panariti 
660904ad26bbSDavid Panariti 	WREG32_FIELD(SQ_INTERRUPT_MSG_CTRL, STALL,
661004ad26bbSDavid Panariti 		     enable_flag);
661104ad26bbSDavid Panariti 
661204ad26bbSDavid Panariti 	return 0;
661304ad26bbSDavid Panariti }
661404ad26bbSDavid Panariti 
gfx_v8_0_eop_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)6615aaa36a97SAlex Deucher static int gfx_v8_0_eop_irq(struct amdgpu_device *adev,
6616aaa36a97SAlex Deucher 			    struct amdgpu_irq_src *source,
6617aaa36a97SAlex Deucher 			    struct amdgpu_iv_entry *entry)
6618aaa36a97SAlex Deucher {
6619aaa36a97SAlex Deucher 	int i;
6620aaa36a97SAlex Deucher 	u8 me_id, pipe_id, queue_id;
6621aaa36a97SAlex Deucher 	struct amdgpu_ring *ring;
6622aaa36a97SAlex Deucher 
6623aaa36a97SAlex Deucher 	DRM_DEBUG("IH: CP EOP\n");
6624aaa36a97SAlex Deucher 	me_id = (entry->ring_id & 0x0c) >> 2;
6625aaa36a97SAlex Deucher 	pipe_id = (entry->ring_id & 0x03) >> 0;
6626aaa36a97SAlex Deucher 	queue_id = (entry->ring_id & 0x70) >> 4;
6627aaa36a97SAlex Deucher 
6628aaa36a97SAlex Deucher 	switch (me_id) {
6629aaa36a97SAlex Deucher 	case 0:
6630aaa36a97SAlex Deucher 		amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
6631aaa36a97SAlex Deucher 		break;
6632aaa36a97SAlex Deucher 	case 1:
6633aaa36a97SAlex Deucher 	case 2:
6634aaa36a97SAlex Deucher 		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
6635aaa36a97SAlex Deucher 			ring = &adev->gfx.compute_ring[i];
6636aaa36a97SAlex Deucher 			/* Per-queue interrupt is supported for MEC starting from VI.
6637aaa36a97SAlex Deucher 			  * The interrupt can only be enabled/disabled per pipe instead of per queue.
6638aaa36a97SAlex Deucher 			  */
6639aaa36a97SAlex Deucher 			if ((ring->me == me_id) && (ring->pipe == pipe_id) && (ring->queue == queue_id))
6640aaa36a97SAlex Deucher 				amdgpu_fence_process(ring);
6641aaa36a97SAlex Deucher 		}
6642aaa36a97SAlex Deucher 		break;
6643aaa36a97SAlex Deucher 	}
6644aaa36a97SAlex Deucher 	return 0;
6645aaa36a97SAlex Deucher }
6646aaa36a97SAlex Deucher 
gfx_v8_0_fault(struct amdgpu_device * adev,struct amdgpu_iv_entry * entry)6647898c2cb5SChristian König static void gfx_v8_0_fault(struct amdgpu_device *adev,
6648898c2cb5SChristian König 			   struct amdgpu_iv_entry *entry)
6649898c2cb5SChristian König {
6650898c2cb5SChristian König 	u8 me_id, pipe_id, queue_id;
6651898c2cb5SChristian König 	struct amdgpu_ring *ring;
6652898c2cb5SChristian König 	int i;
6653898c2cb5SChristian König 
6654898c2cb5SChristian König 	me_id = (entry->ring_id & 0x0c) >> 2;
6655898c2cb5SChristian König 	pipe_id = (entry->ring_id & 0x03) >> 0;
6656898c2cb5SChristian König 	queue_id = (entry->ring_id & 0x70) >> 4;
6657898c2cb5SChristian König 
6658898c2cb5SChristian König 	switch (me_id) {
6659898c2cb5SChristian König 	case 0:
6660898c2cb5SChristian König 		drm_sched_fault(&adev->gfx.gfx_ring[0].sched);
6661898c2cb5SChristian König 		break;
6662898c2cb5SChristian König 	case 1:
6663898c2cb5SChristian König 	case 2:
6664898c2cb5SChristian König 		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
6665898c2cb5SChristian König 			ring = &adev->gfx.compute_ring[i];
6666898c2cb5SChristian König 			if (ring->me == me_id && ring->pipe == pipe_id &&
6667898c2cb5SChristian König 			    ring->queue == queue_id)
6668898c2cb5SChristian König 				drm_sched_fault(&ring->sched);
6669898c2cb5SChristian König 		}
6670898c2cb5SChristian König 		break;
6671898c2cb5SChristian König 	}
6672898c2cb5SChristian König }
6673898c2cb5SChristian König 
gfx_v8_0_priv_reg_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)6674aaa36a97SAlex Deucher static int gfx_v8_0_priv_reg_irq(struct amdgpu_device *adev,
6675aaa36a97SAlex Deucher 				 struct amdgpu_irq_src *source,
6676aaa36a97SAlex Deucher 				 struct amdgpu_iv_entry *entry)
6677aaa36a97SAlex Deucher {
6678aaa36a97SAlex Deucher 	DRM_ERROR("Illegal register access in command stream\n");
6679898c2cb5SChristian König 	gfx_v8_0_fault(adev, entry);
6680aaa36a97SAlex Deucher 	return 0;
6681aaa36a97SAlex Deucher }
6682aaa36a97SAlex Deucher 
gfx_v8_0_priv_inst_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)6683aaa36a97SAlex Deucher static int gfx_v8_0_priv_inst_irq(struct amdgpu_device *adev,
6684aaa36a97SAlex Deucher 				  struct amdgpu_irq_src *source,
6685aaa36a97SAlex Deucher 				  struct amdgpu_iv_entry *entry)
6686aaa36a97SAlex Deucher {
6687aaa36a97SAlex Deucher 	DRM_ERROR("Illegal instruction in command stream\n");
6688898c2cb5SChristian König 	gfx_v8_0_fault(adev, entry);
6689aaa36a97SAlex Deucher 	return 0;
6690aaa36a97SAlex Deucher }
6691aaa36a97SAlex Deucher 
gfx_v8_0_cp_ecc_error_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)66925a2f2913SDavid Panariti static int gfx_v8_0_cp_ecc_error_irq(struct amdgpu_device *adev,
66935a2f2913SDavid Panariti 				     struct amdgpu_irq_src *source,
66945a2f2913SDavid Panariti 				     struct amdgpu_iv_entry *entry)
66955a2f2913SDavid Panariti {
669604ad26bbSDavid Panariti 	DRM_ERROR("CP EDC/ECC error detected.");
669704ad26bbSDavid Panariti 	return 0;
669804ad26bbSDavid Panariti }
669904ad26bbSDavid Panariti 
gfx_v8_0_parse_sq_irq(struct amdgpu_device * adev,unsigned ih_data,bool from_wq)67008b75c9b4SSebastian Andrzej Siewior static void gfx_v8_0_parse_sq_irq(struct amdgpu_device *adev, unsigned ih_data,
67018b75c9b4SSebastian Andrzej Siewior 				  bool from_wq)
670204ad26bbSDavid Panariti {
67039bdc2092SAndrey Grodzovsky 	u32 enc, se_id, sh_id, cu_id;
670404ad26bbSDavid Panariti 	char type[20];
67059bdc2092SAndrey Grodzovsky 	int sq_edc_source = -1;
6706d9e222b4SAndrey Grodzovsky 
6707d9e222b4SAndrey Grodzovsky 	enc = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_CMN, ENCODING);
6708d9e222b4SAndrey Grodzovsky 	se_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_CMN, SE_ID);
670904ad26bbSDavid Panariti 
671004ad26bbSDavid Panariti 	switch (enc) {
671104ad26bbSDavid Panariti 		case 0:
671204ad26bbSDavid Panariti 			DRM_INFO("SQ general purpose intr detected:"
671304ad26bbSDavid Panariti 					"se_id %d, immed_overflow %d, host_reg_overflow %d,"
671404ad26bbSDavid Panariti 					"host_cmd_overflow %d, cmd_timestamp %d,"
671504ad26bbSDavid Panariti 					"reg_timestamp %d, thread_trace_buff_full %d,"
671604ad26bbSDavid Panariti 					"wlt %d, thread_trace %d.\n",
671704ad26bbSDavid Panariti 					se_id,
6718d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, IMMED_OVERFLOW),
6719d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, HOST_REG_OVERFLOW),
6720d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, HOST_CMD_OVERFLOW),
6721d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, CMD_TIMESTAMP),
6722d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, REG_TIMESTAMP),
6723d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, THREAD_TRACE_BUF_FULL),
6724d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, WLT),
6725d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, THREAD_TRACE)
672604ad26bbSDavid Panariti 					);
672704ad26bbSDavid Panariti 			break;
672804ad26bbSDavid Panariti 		case 1:
672904ad26bbSDavid Panariti 		case 2:
673004ad26bbSDavid Panariti 
67319bdc2092SAndrey Grodzovsky 			cu_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, CU_ID);
67329bdc2092SAndrey Grodzovsky 			sh_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, SH_ID);
67339bdc2092SAndrey Grodzovsky 
67349bdc2092SAndrey Grodzovsky 			/*
67359bdc2092SAndrey Grodzovsky 			 * This function can be called either directly from ISR
67369bdc2092SAndrey Grodzovsky 			 * or from BH in which case we can access SQ_EDC_INFO
67379bdc2092SAndrey Grodzovsky 			 * instance
67389bdc2092SAndrey Grodzovsky 			 */
67398b75c9b4SSebastian Andrzej Siewior 			if (from_wq) {
67409bdc2092SAndrey Grodzovsky 				mutex_lock(&adev->grbm_idx_mutex);
6741d51ac6d0SLe Ma 				gfx_v8_0_select_se_sh(adev, se_id, sh_id, cu_id, 0);
67429bdc2092SAndrey Grodzovsky 
67439bdc2092SAndrey Grodzovsky 				sq_edc_source = REG_GET_FIELD(RREG32(mmSQ_EDC_INFO), SQ_EDC_INFO, SOURCE);
67449bdc2092SAndrey Grodzovsky 
6745d51ac6d0SLe Ma 				gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
67469bdc2092SAndrey Grodzovsky 				mutex_unlock(&adev->grbm_idx_mutex);
67479bdc2092SAndrey Grodzovsky 			}
67489bdc2092SAndrey Grodzovsky 
674904ad26bbSDavid Panariti 			if (enc == 1)
675004ad26bbSDavid Panariti 				sprintf(type, "instruction intr");
675104ad26bbSDavid Panariti 			else
675204ad26bbSDavid Panariti 				sprintf(type, "EDC/ECC error");
675304ad26bbSDavid Panariti 
675404ad26bbSDavid Panariti 			DRM_INFO(
675504ad26bbSDavid Panariti 				"SQ %s detected: "
67569bdc2092SAndrey Grodzovsky 					"se_id %d, sh_id %d, cu_id %d, simd_id %d, wave_id %d, vm_id %d "
67579bdc2092SAndrey Grodzovsky 					"trap %s, sq_ed_info.source %s.\n",
67589bdc2092SAndrey Grodzovsky 					type, se_id, sh_id, cu_id,
6759d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, SIMD_ID),
6760d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, WAVE_ID),
6761d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, VM_ID),
6762d9e222b4SAndrey Grodzovsky 					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, PRIV) ? "true" : "false",
67639bdc2092SAndrey Grodzovsky 					(sq_edc_source != -1) ? sq_edc_source_names[sq_edc_source] : "unavailable"
676404ad26bbSDavid Panariti 				);
676504ad26bbSDavid Panariti 			break;
676604ad26bbSDavid Panariti 		default:
676704ad26bbSDavid Panariti 			DRM_ERROR("SQ invalid encoding type\n.");
67689bdc2092SAndrey Grodzovsky 	}
67699bdc2092SAndrey Grodzovsky }
67709bdc2092SAndrey Grodzovsky 
gfx_v8_0_sq_irq_work_func(struct work_struct * work)67719bdc2092SAndrey Grodzovsky static void gfx_v8_0_sq_irq_work_func(struct work_struct *work)
67729bdc2092SAndrey Grodzovsky {
67739bdc2092SAndrey Grodzovsky 
67749bdc2092SAndrey Grodzovsky 	struct amdgpu_device *adev = container_of(work, struct amdgpu_device, gfx.sq_work.work);
67759bdc2092SAndrey Grodzovsky 	struct sq_work *sq_work = container_of(work, struct sq_work, work);
67769bdc2092SAndrey Grodzovsky 
67778b75c9b4SSebastian Andrzej Siewior 	gfx_v8_0_parse_sq_irq(adev, sq_work->ih_data, true);
67789bdc2092SAndrey Grodzovsky }
67799bdc2092SAndrey Grodzovsky 
gfx_v8_0_sq_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)67809bdc2092SAndrey Grodzovsky static int gfx_v8_0_sq_irq(struct amdgpu_device *adev,
67819bdc2092SAndrey Grodzovsky 			   struct amdgpu_irq_src *source,
67829bdc2092SAndrey Grodzovsky 			   struct amdgpu_iv_entry *entry)
67839bdc2092SAndrey Grodzovsky {
67849bdc2092SAndrey Grodzovsky 	unsigned ih_data = entry->src_data[0];
67859bdc2092SAndrey Grodzovsky 
67869bdc2092SAndrey Grodzovsky 	/*
67879bdc2092SAndrey Grodzovsky 	 * Try to submit work so SQ_EDC_INFO can be accessed from
67889bdc2092SAndrey Grodzovsky 	 * BH. If previous work submission hasn't finished yet
67899bdc2092SAndrey Grodzovsky 	 * just print whatever info is possible directly from the ISR.
67909bdc2092SAndrey Grodzovsky 	 */
67919bdc2092SAndrey Grodzovsky 	if (work_pending(&adev->gfx.sq_work.work)) {
67928b75c9b4SSebastian Andrzej Siewior 		gfx_v8_0_parse_sq_irq(adev, ih_data, false);
67939bdc2092SAndrey Grodzovsky 	} else {
67949bdc2092SAndrey Grodzovsky 		adev->gfx.sq_work.ih_data = ih_data;
67959bdc2092SAndrey Grodzovsky 		schedule_work(&adev->gfx.sq_work.work);
679604ad26bbSDavid Panariti 	}
679704ad26bbSDavid Panariti 
67985a2f2913SDavid Panariti 	return 0;
67995a2f2913SDavid Panariti }
68005a2f2913SDavid Panariti 
gfx_v8_0_emit_mem_sync(struct amdgpu_ring * ring)68012f9ce2a3SAndrey Grodzovsky static void gfx_v8_0_emit_mem_sync(struct amdgpu_ring *ring)
68022f9ce2a3SAndrey Grodzovsky {
68032f9ce2a3SAndrey Grodzovsky 	amdgpu_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
68042f9ce2a3SAndrey Grodzovsky 	amdgpu_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
68052f9ce2a3SAndrey Grodzovsky 			  PACKET3_TC_ACTION_ENA |
68062f9ce2a3SAndrey Grodzovsky 			  PACKET3_SH_KCACHE_ACTION_ENA |
68072f9ce2a3SAndrey Grodzovsky 			  PACKET3_SH_ICACHE_ACTION_ENA |
68082f9ce2a3SAndrey Grodzovsky 			  PACKET3_TC_WB_ACTION_ENA);  /* CP_COHER_CNTL */
68092f9ce2a3SAndrey Grodzovsky 	amdgpu_ring_write(ring, 0xffffffff);  /* CP_COHER_SIZE */
68102f9ce2a3SAndrey Grodzovsky 	amdgpu_ring_write(ring, 0);  /* CP_COHER_BASE */
68112f9ce2a3SAndrey Grodzovsky 	amdgpu_ring_write(ring, 0x0000000A); /* poll interval */
68122f9ce2a3SAndrey Grodzovsky }
68132f9ce2a3SAndrey Grodzovsky 
gfx_v8_0_emit_mem_sync_compute(struct amdgpu_ring * ring)6814d35745bbSMarek Olšák static void gfx_v8_0_emit_mem_sync_compute(struct amdgpu_ring *ring)
6815d35745bbSMarek Olšák {
6816d35745bbSMarek Olšák 	amdgpu_ring_write(ring, PACKET3(PACKET3_ACQUIRE_MEM, 5));
6817d35745bbSMarek Olšák 	amdgpu_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
6818d35745bbSMarek Olšák 			  PACKET3_TC_ACTION_ENA |
6819d35745bbSMarek Olšák 			  PACKET3_SH_KCACHE_ACTION_ENA |
6820d35745bbSMarek Olšák 			  PACKET3_SH_ICACHE_ACTION_ENA |
6821d35745bbSMarek Olšák 			  PACKET3_TC_WB_ACTION_ENA);  /* CP_COHER_CNTL */
6822d35745bbSMarek Olšák 	amdgpu_ring_write(ring, 0xffffffff);	/* CP_COHER_SIZE */
6823d35745bbSMarek Olšák 	amdgpu_ring_write(ring, 0xff);		/* CP_COHER_SIZE_HI */
6824d35745bbSMarek Olšák 	amdgpu_ring_write(ring, 0);		/* CP_COHER_BASE */
6825d35745bbSMarek Olšák 	amdgpu_ring_write(ring, 0);		/* CP_COHER_BASE_HI */
6826d35745bbSMarek Olšák 	amdgpu_ring_write(ring, 0x0000000A);	/* poll interval */
6827d35745bbSMarek Olšák }
6828d35745bbSMarek Olšák 
6829f8bf6450SNirmoy Das 
6830f8bf6450SNirmoy Das /* mmSPI_WCL_PIPE_PERCENT_CS[0-7]_DEFAULT values are same */
6831f8bf6450SNirmoy Das #define mmSPI_WCL_PIPE_PERCENT_CS_DEFAULT	0x0000007f
gfx_v8_0_emit_wave_limit_cs(struct amdgpu_ring * ring,uint32_t pipe,bool enable)6832f8bf6450SNirmoy Das static void gfx_v8_0_emit_wave_limit_cs(struct amdgpu_ring *ring,
6833f8bf6450SNirmoy Das 					uint32_t pipe, bool enable)
6834f8bf6450SNirmoy Das {
6835f8bf6450SNirmoy Das 	uint32_t val;
6836f8bf6450SNirmoy Das 	uint32_t wcl_cs_reg;
6837f8bf6450SNirmoy Das 
6838f8bf6450SNirmoy Das 	val = enable ? 0x1 : mmSPI_WCL_PIPE_PERCENT_CS_DEFAULT;
6839f8bf6450SNirmoy Das 
6840f8bf6450SNirmoy Das 	switch (pipe) {
6841f8bf6450SNirmoy Das 	case 0:
6842f8bf6450SNirmoy Das 		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS0;
6843f8bf6450SNirmoy Das 		break;
6844f8bf6450SNirmoy Das 	case 1:
6845f8bf6450SNirmoy Das 		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS1;
6846f8bf6450SNirmoy Das 		break;
6847f8bf6450SNirmoy Das 	case 2:
6848f8bf6450SNirmoy Das 		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS2;
6849f8bf6450SNirmoy Das 		break;
6850f8bf6450SNirmoy Das 	case 3:
6851f8bf6450SNirmoy Das 		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS3;
6852f8bf6450SNirmoy Das 		break;
6853f8bf6450SNirmoy Das 	default:
6854f8bf6450SNirmoy Das 		DRM_DEBUG("invalid pipe %d\n", pipe);
6855f8bf6450SNirmoy Das 		return;
6856f8bf6450SNirmoy Das 	}
6857f8bf6450SNirmoy Das 
6858f8bf6450SNirmoy Das 	amdgpu_ring_emit_wreg(ring, wcl_cs_reg, val);
6859f8bf6450SNirmoy Das 
6860f8bf6450SNirmoy Das }
6861f8bf6450SNirmoy Das 
68620a52a6caSNirmoy Das #define mmSPI_WCL_PIPE_PERCENT_GFX_DEFAULT	0x07ffffff
gfx_v8_0_emit_wave_limit(struct amdgpu_ring * ring,bool enable)68630a52a6caSNirmoy Das static void gfx_v8_0_emit_wave_limit(struct amdgpu_ring *ring, bool enable)
68640a52a6caSNirmoy Das {
6865f8bf6450SNirmoy Das 	struct amdgpu_device *adev = ring->adev;
68660a52a6caSNirmoy Das 	uint32_t val;
6867f8bf6450SNirmoy Das 	int i;
68680a52a6caSNirmoy Das 
68690a52a6caSNirmoy Das 	/* mmSPI_WCL_PIPE_PERCENT_GFX is 7 bit multiplier register to limit
68700a52a6caSNirmoy Das 	 * number of gfx waves. Setting 5 bit will make sure gfx only gets
68710a52a6caSNirmoy Das 	 * around 25% of gpu resources.
68720a52a6caSNirmoy Das 	 */
68730a52a6caSNirmoy Das 	val = enable ? 0x1f : mmSPI_WCL_PIPE_PERCENT_GFX_DEFAULT;
68740a52a6caSNirmoy Das 	amdgpu_ring_emit_wreg(ring, mmSPI_WCL_PIPE_PERCENT_GFX, val);
6875f8bf6450SNirmoy Das 
6876f8bf6450SNirmoy Das 	/* Restrict waves for normal/low priority compute queues as well
6877f8bf6450SNirmoy Das 	 * to get best QoS for high priority compute jobs.
6878f8bf6450SNirmoy Das 	 *
6879f8bf6450SNirmoy Das 	 * amdgpu controls only 1st ME(0-3 CS pipes).
6880f8bf6450SNirmoy Das 	 */
6881f8bf6450SNirmoy Das 	for (i = 0; i < adev->gfx.mec.num_pipe_per_mec; i++) {
6882f8bf6450SNirmoy Das 		if (i != ring->pipe)
6883f8bf6450SNirmoy Das 			gfx_v8_0_emit_wave_limit_cs(ring, i, enable);
6884f8bf6450SNirmoy Das 
6885f8bf6450SNirmoy Das 	}
6886f8bf6450SNirmoy Das 
68870a52a6caSNirmoy Das }
68880a52a6caSNirmoy Das 
gfx_v8_0_reset_kgq(struct amdgpu_ring * ring,unsigned int vmid)6889*4af8071bSAlex Deucher static int gfx_v8_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)
6890*4af8071bSAlex Deucher {
6891*4af8071bSAlex Deucher 	struct amdgpu_device *adev = ring->adev;
6892*4af8071bSAlex Deucher 	struct amdgpu_kiq *kiq = &adev->gfx.kiq[0];
6893*4af8071bSAlex Deucher 	struct amdgpu_ring *kiq_ring = &kiq->ring;
6894*4af8071bSAlex Deucher 	unsigned long flags;
6895*4af8071bSAlex Deucher 	u32 tmp;
6896*4af8071bSAlex Deucher 	int r;
6897*4af8071bSAlex Deucher 
6898*4af8071bSAlex Deucher 	if (amdgpu_sriov_vf(adev))
6899*4af8071bSAlex Deucher 		return -EINVAL;
6900*4af8071bSAlex Deucher 
6901*4af8071bSAlex Deucher 	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
6902*4af8071bSAlex Deucher 		return -EINVAL;
6903*4af8071bSAlex Deucher 
6904*4af8071bSAlex Deucher 	spin_lock_irqsave(&kiq->ring_lock, flags);
6905*4af8071bSAlex Deucher 
6906*4af8071bSAlex Deucher 	if (amdgpu_ring_alloc(kiq_ring, 5)) {
6907*4af8071bSAlex Deucher 		spin_unlock_irqrestore(&kiq->ring_lock, flags);
6908*4af8071bSAlex Deucher 		return -ENOMEM;
6909*4af8071bSAlex Deucher 	}
6910*4af8071bSAlex Deucher 
6911*4af8071bSAlex Deucher 	tmp = REG_SET_FIELD(0, CP_VMID_RESET, RESET_REQUEST, 1 << vmid);
6912*4af8071bSAlex Deucher 	gfx_v8_0_ring_emit_wreg(kiq_ring, mmCP_VMID_RESET, tmp);
6913*4af8071bSAlex Deucher 	amdgpu_ring_commit(kiq_ring);
6914*4af8071bSAlex Deucher 
6915*4af8071bSAlex Deucher 	spin_unlock_irqrestore(&kiq->ring_lock, flags);
6916*4af8071bSAlex Deucher 
6917*4af8071bSAlex Deucher 	r = amdgpu_ring_test_ring(kiq_ring);
6918*4af8071bSAlex Deucher 	if (r)
6919*4af8071bSAlex Deucher 		return r;
6920*4af8071bSAlex Deucher 
6921*4af8071bSAlex Deucher 	if (amdgpu_ring_alloc(ring, 7 + 12 + 5))
6922*4af8071bSAlex Deucher 		return -ENOMEM;
6923*4af8071bSAlex Deucher 	gfx_v8_0_ring_emit_fence_gfx(ring, ring->fence_drv.gpu_addr,
6924*4af8071bSAlex Deucher 				     ring->fence_drv.sync_seq, AMDGPU_FENCE_FLAG_EXEC);
6925*4af8071bSAlex Deucher 	gfx_v8_0_ring_emit_reg_wait(ring, mmCP_VMID_RESET, 0, 0xffff);
6926*4af8071bSAlex Deucher 	gfx_v8_0_ring_emit_wreg(ring, mmCP_VMID_RESET, 0);
6927*4af8071bSAlex Deucher 
6928*4af8071bSAlex Deucher 	return amdgpu_ring_test_ring(ring);
6929*4af8071bSAlex Deucher }
6930*4af8071bSAlex Deucher 
6931a1255107SAlex Deucher static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
693288a907d6STom St Denis 	.name = "gfx_v8_0",
6933aaa36a97SAlex Deucher 	.early_init = gfx_v8_0_early_init,
6934ccba7691SAlex Deucher 	.late_init = gfx_v8_0_late_init,
6935aaa36a97SAlex Deucher 	.sw_init = gfx_v8_0_sw_init,
6936aaa36a97SAlex Deucher 	.sw_fini = gfx_v8_0_sw_fini,
6937aaa36a97SAlex Deucher 	.hw_init = gfx_v8_0_hw_init,
6938aaa36a97SAlex Deucher 	.hw_fini = gfx_v8_0_hw_fini,
6939aaa36a97SAlex Deucher 	.suspend = gfx_v8_0_suspend,
6940aaa36a97SAlex Deucher 	.resume = gfx_v8_0_resume,
6941aaa36a97SAlex Deucher 	.is_idle = gfx_v8_0_is_idle,
6942aaa36a97SAlex Deucher 	.wait_for_idle = gfx_v8_0_wait_for_idle,
69433d7c6384SChunming Zhou 	.check_soft_reset = gfx_v8_0_check_soft_reset,
69441057f20cSChunming Zhou 	.pre_soft_reset = gfx_v8_0_pre_soft_reset,
6945aaa36a97SAlex Deucher 	.soft_reset = gfx_v8_0_soft_reset,
6946e4ae0fc3SChunming Zhou 	.post_soft_reset = gfx_v8_0_post_soft_reset,
6947aaa36a97SAlex Deucher 	.set_clockgating_state = gfx_v8_0_set_clockgating_state,
6948aaa36a97SAlex Deucher 	.set_powergating_state = gfx_v8_0_set_powergating_state,
6949ebd843d6SHuang Rui 	.get_clockgating_state = gfx_v8_0_get_clockgating_state,
6950e21d253bSSunil Khatri 	.dump_ip_state = NULL,
695140356542SSunil Khatri 	.print_ip_state = NULL,
6952aaa36a97SAlex Deucher };
6953aaa36a97SAlex Deucher 
6954aaa36a97SAlex Deucher static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = {
695521cd942eSChristian König 	.type = AMDGPU_RING_TYPE_GFX,
695679887142SChristian König 	.align_mask = 0xff,
695779887142SChristian König 	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
6958536fbf94SKen Wang 	.support_64bit_ptrs = false,
6959e7706b42STom St Denis 	.get_rptr = gfx_v8_0_ring_get_rptr,
6960aaa36a97SAlex Deucher 	.get_wptr = gfx_v8_0_ring_get_wptr_gfx,
6961aaa36a97SAlex Deucher 	.set_wptr = gfx_v8_0_ring_set_wptr_gfx,
6962e9d672b2SMonk Liu 	.emit_frame_size = /* maximum 215dw if count 16 IBs in */
6963e9d672b2SMonk Liu 		5 +  /* COND_EXEC */
6964e9d672b2SMonk Liu 		7 +  /* PIPELINE_SYNC */
69655518625dSChristian König 		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 9 + /* VM_FLUSH */
6966b456c932SPierre-Eric Pelloux-Prayer 		12 +  /* FENCE for VM_FLUSH */
6967e9d672b2SMonk Liu 		20 + /* GDS switch */
6968e9d672b2SMonk Liu 		4 + /* double SWITCH_BUFFER,
6969e9d672b2SMonk Liu 		       the first COND_EXEC jump to the place just
6970e9d672b2SMonk Liu 			   prior to this double SWITCH_BUFFER  */
6971e9d672b2SMonk Liu 		5 + /* COND_EXEC */
6972e9d672b2SMonk Liu 		7 +	 /*	HDP_flush */
6973e9d672b2SMonk Liu 		4 +	 /*	VGT_flush */
6974e9d672b2SMonk Liu 		14 + /*	CE_META */
6975e9d672b2SMonk Liu 		31 + /*	DE_META */
6976e9d672b2SMonk Liu 		3 + /* CNTX_CTRL */
6977e9d672b2SMonk Liu 		5 + /* HDP_INVL */
6978b456c932SPierre-Eric Pelloux-Prayer 		12 + 12 + /* FENCE x2 */
69792f9ce2a3SAndrey Grodzovsky 		2 + /* SWITCH_BUFFER */
69802f9ce2a3SAndrey Grodzovsky 		5, /* SURFACE_SYNC */
6981e12f3d7aSChristian König 	.emit_ib_size =	4, /* gfx_v8_0_ring_emit_ib_gfx */
698293323131Smonk.liu 	.emit_ib = gfx_v8_0_ring_emit_ib_gfx,
6983aaa36a97SAlex Deucher 	.emit_fence = gfx_v8_0_ring_emit_fence_gfx,
6984b8c7b39eSChristian König 	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
6985aaa36a97SAlex Deucher 	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
6986aaa36a97SAlex Deucher 	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
6987d2edb07bSChristian König 	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
6988aaa36a97SAlex Deucher 	.test_ring = gfx_v8_0_ring_test_ring,
6989aaa36a97SAlex Deucher 	.test_ib = gfx_v8_0_ring_test_ib,
6990edff0e28SJammy Zhou 	.insert_nop = amdgpu_ring_insert_nop,
69919e5d5309SChristian König 	.pad_ib = amdgpu_ring_generic_pad_ib,
6992c2167a65SMonk Liu 	.emit_switch_buffer = gfx_v8_ring_emit_sb,
6993753ad49cSMonk Liu 	.emit_cntxcntl = gfx_v8_ring_emit_cntxcntl,
6994806ba2d4SMonk Liu 	.init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec,
69959ed88047SChristian König 	.emit_wreg = gfx_v8_0_ring_emit_wreg,
6996f5d85033SChristian König 	.soft_recovery = gfx_v8_0_ring_soft_recovery,
69972f9ce2a3SAndrey Grodzovsky 	.emit_mem_sync = gfx_v8_0_emit_mem_sync,
6998*4af8071bSAlex Deucher 	.reset = gfx_v8_0_reset_kgq,
6999aaa36a97SAlex Deucher };
7000aaa36a97SAlex Deucher 
7001aaa36a97SAlex Deucher static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = {
700221cd942eSChristian König 	.type = AMDGPU_RING_TYPE_COMPUTE,
700379887142SChristian König 	.align_mask = 0xff,
700479887142SChristian König 	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
7005536fbf94SKen Wang 	.support_64bit_ptrs = false,
7006e7706b42STom St Denis 	.get_rptr = gfx_v8_0_ring_get_rptr,
7007aaa36a97SAlex Deucher 	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
7008aaa36a97SAlex Deucher 	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
7009e12f3d7aSChristian König 	.emit_frame_size =
7010e12f3d7aSChristian König 		20 + /* gfx_v8_0_ring_emit_gds_switch */
7011e12f3d7aSChristian König 		7 + /* gfx_v8_0_ring_emit_hdp_flush */
70122ee150cdSChristian König 		5 + /* hdp_invalidate */
7013e12f3d7aSChristian König 		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
70145518625dSChristian König 		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 7 + /* gfx_v8_0_ring_emit_vm_flush */
7015d35745bbSMarek Olšák 		7 + 7 + 7 + /* gfx_v8_0_ring_emit_fence_compute x3 for user fence, vm fence */
70160a52a6caSNirmoy Das 		7 + /* gfx_v8_0_emit_mem_sync_compute */
7017f8bf6450SNirmoy Das 		5 + /* gfx_v8_0_emit_wave_limit for updating mmSPI_WCL_PIPE_PERCENT_GFX register */
7018f8bf6450SNirmoy Das 		15, /* for updating 3 mmSPI_WCL_PIPE_PERCENT_CS registers */
701941cca166SMarek Olšák 	.emit_ib_size =	7, /* gfx_v8_0_ring_emit_ib_compute */
702093323131Smonk.liu 	.emit_ib = gfx_v8_0_ring_emit_ib_compute,
7021aaa36a97SAlex Deucher 	.emit_fence = gfx_v8_0_ring_emit_fence_compute,
7022b8c7b39eSChristian König 	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
7023aaa36a97SAlex Deucher 	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
7024aaa36a97SAlex Deucher 	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
702535074d2dSmonk.liu 	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
7026aaa36a97SAlex Deucher 	.test_ring = gfx_v8_0_ring_test_ring,
7027aaa36a97SAlex Deucher 	.test_ib = gfx_v8_0_ring_test_ib,
7028edff0e28SJammy Zhou 	.insert_nop = amdgpu_ring_insert_nop,
70299e5d5309SChristian König 	.pad_ib = amdgpu_ring_generic_pad_ib,
70309ed88047SChristian König 	.emit_wreg = gfx_v8_0_ring_emit_wreg,
70317e60ecc2SAlex Deucher 	.soft_recovery = gfx_v8_0_ring_soft_recovery,
7032d35745bbSMarek Olšák 	.emit_mem_sync = gfx_v8_0_emit_mem_sync_compute,
70330a52a6caSNirmoy Das 	.emit_wave_limit = gfx_v8_0_emit_wave_limit,
7034aaa36a97SAlex Deucher };
7035aaa36a97SAlex Deucher 
70364e638ae9SXiangliang Yu static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_kiq = {
70374e638ae9SXiangliang Yu 	.type = AMDGPU_RING_TYPE_KIQ,
70384e638ae9SXiangliang Yu 	.align_mask = 0xff,
70394e638ae9SXiangliang Yu 	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
7040536fbf94SKen Wang 	.support_64bit_ptrs = false,
70414e638ae9SXiangliang Yu 	.get_rptr = gfx_v8_0_ring_get_rptr,
70424e638ae9SXiangliang Yu 	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
70434e638ae9SXiangliang Yu 	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
70444e638ae9SXiangliang Yu 	.emit_frame_size =
70454e638ae9SXiangliang Yu 		20 + /* gfx_v8_0_ring_emit_gds_switch */
70464e638ae9SXiangliang Yu 		7 + /* gfx_v8_0_ring_emit_hdp_flush */
70472ee150cdSChristian König 		5 + /* hdp_invalidate */
70484e638ae9SXiangliang Yu 		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
70494e638ae9SXiangliang Yu 		17 + /* gfx_v8_0_ring_emit_vm_flush */
70504e638ae9SXiangliang Yu 		7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_kiq x3 for user fence, vm fence */
705141cca166SMarek Olšák 	.emit_ib_size =	7, /* gfx_v8_0_ring_emit_ib_compute */
70524e638ae9SXiangliang Yu 	.emit_fence = gfx_v8_0_ring_emit_fence_kiq,
70534e638ae9SXiangliang Yu 	.test_ring = gfx_v8_0_ring_test_ring,
70544e638ae9SXiangliang Yu 	.insert_nop = amdgpu_ring_insert_nop,
70554e638ae9SXiangliang Yu 	.pad_ib = amdgpu_ring_generic_pad_ib,
7056880e87e3SXiangliang Yu 	.emit_rreg = gfx_v8_0_ring_emit_rreg,
7057880e87e3SXiangliang Yu 	.emit_wreg = gfx_v8_0_ring_emit_wreg,
70584e638ae9SXiangliang Yu };
70594e638ae9SXiangliang Yu 
gfx_v8_0_set_ring_funcs(struct amdgpu_device * adev)7060aaa36a97SAlex Deucher static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev)
7061aaa36a97SAlex Deucher {
7062aaa36a97SAlex Deucher 	int i;
7063aaa36a97SAlex Deucher 
7064277bd337SLe Ma 	adev->gfx.kiq[0].ring.funcs = &gfx_v8_0_ring_funcs_kiq;
70654e638ae9SXiangliang Yu 
7066aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
7067aaa36a97SAlex Deucher 		adev->gfx.gfx_ring[i].funcs = &gfx_v8_0_ring_funcs_gfx;
7068aaa36a97SAlex Deucher 
7069aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.num_compute_rings; i++)
7070aaa36a97SAlex Deucher 		adev->gfx.compute_ring[i].funcs = &gfx_v8_0_ring_funcs_compute;
7071aaa36a97SAlex Deucher }
7072aaa36a97SAlex Deucher 
7073aaa36a97SAlex Deucher static const struct amdgpu_irq_src_funcs gfx_v8_0_eop_irq_funcs = {
7074aaa36a97SAlex Deucher 	.set = gfx_v8_0_set_eop_interrupt_state,
7075aaa36a97SAlex Deucher 	.process = gfx_v8_0_eop_irq,
7076aaa36a97SAlex Deucher };
7077aaa36a97SAlex Deucher 
7078aaa36a97SAlex Deucher static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_reg_irq_funcs = {
7079aaa36a97SAlex Deucher 	.set = gfx_v8_0_set_priv_reg_fault_state,
7080aaa36a97SAlex Deucher 	.process = gfx_v8_0_priv_reg_irq,
7081aaa36a97SAlex Deucher };
7082aaa36a97SAlex Deucher 
7083aaa36a97SAlex Deucher static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_inst_irq_funcs = {
7084aaa36a97SAlex Deucher 	.set = gfx_v8_0_set_priv_inst_fault_state,
7085aaa36a97SAlex Deucher 	.process = gfx_v8_0_priv_inst_irq,
7086aaa36a97SAlex Deucher };
7087aaa36a97SAlex Deucher 
70885a2f2913SDavid Panariti static const struct amdgpu_irq_src_funcs gfx_v8_0_cp_ecc_error_irq_funcs = {
70895a2f2913SDavid Panariti 	.set = gfx_v8_0_set_cp_ecc_int_state,
70905a2f2913SDavid Panariti 	.process = gfx_v8_0_cp_ecc_error_irq,
70915a2f2913SDavid Panariti };
70925a2f2913SDavid Panariti 
709304ad26bbSDavid Panariti static const struct amdgpu_irq_src_funcs gfx_v8_0_sq_irq_funcs = {
709404ad26bbSDavid Panariti 	.set = gfx_v8_0_set_sq_int_state,
709504ad26bbSDavid Panariti 	.process = gfx_v8_0_sq_irq,
709604ad26bbSDavid Panariti };
709704ad26bbSDavid Panariti 
gfx_v8_0_set_irq_funcs(struct amdgpu_device * adev)7098aaa36a97SAlex Deucher static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev)
7099aaa36a97SAlex Deucher {
7100aaa36a97SAlex Deucher 	adev->gfx.eop_irq.num_types = AMDGPU_CP_IRQ_LAST;
7101aaa36a97SAlex Deucher 	adev->gfx.eop_irq.funcs = &gfx_v8_0_eop_irq_funcs;
7102aaa36a97SAlex Deucher 
7103aaa36a97SAlex Deucher 	adev->gfx.priv_reg_irq.num_types = 1;
7104aaa36a97SAlex Deucher 	adev->gfx.priv_reg_irq.funcs = &gfx_v8_0_priv_reg_irq_funcs;
7105aaa36a97SAlex Deucher 
7106aaa36a97SAlex Deucher 	adev->gfx.priv_inst_irq.num_types = 1;
7107aaa36a97SAlex Deucher 	adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs;
71084e638ae9SXiangliang Yu 
71095a2f2913SDavid Panariti 	adev->gfx.cp_ecc_error_irq.num_types = 1;
71105a2f2913SDavid Panariti 	adev->gfx.cp_ecc_error_irq.funcs = &gfx_v8_0_cp_ecc_error_irq_funcs;
711104ad26bbSDavid Panariti 
711204ad26bbSDavid Panariti 	adev->gfx.sq_irq.num_types = 1;
711304ad26bbSDavid Panariti 	adev->gfx.sq_irq.funcs = &gfx_v8_0_sq_irq_funcs;
7114aaa36a97SAlex Deucher }
7115aaa36a97SAlex Deucher 
gfx_v8_0_set_rlc_funcs(struct amdgpu_device * adev)7116dbff57bcSAlex Deucher static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev)
7117dbff57bcSAlex Deucher {
7118dbff57bcSAlex Deucher 	adev->gfx.rlc.funcs = &iceland_rlc_funcs;
7119dbff57bcSAlex Deucher }
7120dbff57bcSAlex Deucher 
gfx_v8_0_set_gds_init(struct amdgpu_device * adev)7121aaa36a97SAlex Deucher static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev)
7122aaa36a97SAlex Deucher {
7123aaa36a97SAlex Deucher 	/* init asci gds info */
7124dca29491SChristian König 	adev->gds.gds_size = RREG32(mmGDS_VMID0_SIZE);
7125dca29491SChristian König 	adev->gds.gws_size = 64;
7126dca29491SChristian König 	adev->gds.oa_size = 16;
712741cca166SMarek Olšák 	adev->gds.gds_compute_max_wave_id = RREG32(mmGDS_COMPUTE_MAX_WAVE_ID);
7128aaa36a97SAlex Deucher }
7129aaa36a97SAlex Deucher 
gfx_v8_0_set_user_cu_inactive_bitmap(struct amdgpu_device * adev,u32 bitmap)71309de06de8SNicolai Hähnle static void gfx_v8_0_set_user_cu_inactive_bitmap(struct amdgpu_device *adev,
71319de06de8SNicolai Hähnle 						 u32 bitmap)
71329de06de8SNicolai Hähnle {
71339de06de8SNicolai Hähnle 	u32 data;
71349de06de8SNicolai Hähnle 
71359de06de8SNicolai Hähnle 	if (!bitmap)
71369de06de8SNicolai Hähnle 		return;
71379de06de8SNicolai Hähnle 
71389de06de8SNicolai Hähnle 	data = bitmap << GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
71399de06de8SNicolai Hähnle 	data &= GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
71409de06de8SNicolai Hähnle 
71419de06de8SNicolai Hähnle 	WREG32(mmGC_USER_SHADER_ARRAY_CONFIG, data);
71429de06de8SNicolai Hähnle }
71439de06de8SNicolai Hähnle 
gfx_v8_0_get_cu_active_bitmap(struct amdgpu_device * adev)71448f8e00c1SAlex Deucher static u32 gfx_v8_0_get_cu_active_bitmap(struct amdgpu_device *adev)
7145aaa36a97SAlex Deucher {
71468f8e00c1SAlex Deucher 	u32 data, mask;
7147aaa36a97SAlex Deucher 
71485003f278STom St Denis 	data =  RREG32(mmCC_GC_SHADER_ARRAY_CONFIG) |
71495003f278STom St Denis 		RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
7150aaa36a97SAlex Deucher 
7151378506a7SAlex Deucher 	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_cu_per_sh);
7152aaa36a97SAlex Deucher 
71535003f278STom St Denis 	return ~REG_GET_FIELD(data, CC_GC_SHADER_ARRAY_CONFIG, INACTIVE_CUS) & mask;
7154aaa36a97SAlex Deucher }
7155aaa36a97SAlex Deucher 
gfx_v8_0_get_cu_info(struct amdgpu_device * adev)71567dae69a2SAlex Deucher static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
7157aaa36a97SAlex Deucher {
7158aaa36a97SAlex Deucher 	int i, j, k, counter, active_cu_number = 0;
7159aaa36a97SAlex Deucher 	u32 mask, bitmap, ao_bitmap, ao_cu_mask = 0;
71607dae69a2SAlex Deucher 	struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info;
71619de06de8SNicolai Hähnle 	unsigned disable_masks[4 * 2];
7162fe723cd3SRex Zhu 	u32 ao_cu_num;
7163aaa36a97SAlex Deucher 
71646157bd7aSFlora Cui 	memset(cu_info, 0, sizeof(*cu_info));
71656157bd7aSFlora Cui 
7166fe723cd3SRex Zhu 	if (adev->flags & AMD_IS_APU)
7167fe723cd3SRex Zhu 		ao_cu_num = 2;
7168fe723cd3SRex Zhu 	else
7169fe723cd3SRex Zhu 		ao_cu_num = adev->gfx.config.max_cu_per_sh;
7170fe723cd3SRex Zhu 
71719de06de8SNicolai Hähnle 	amdgpu_gfx_parse_disable_cu(disable_masks, 4, 2);
71729de06de8SNicolai Hähnle 
7173aaa36a97SAlex Deucher 	mutex_lock(&adev->grbm_idx_mutex);
7174aaa36a97SAlex Deucher 	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
7175aaa36a97SAlex Deucher 		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
7176aaa36a97SAlex Deucher 			mask = 1;
7177aaa36a97SAlex Deucher 			ao_bitmap = 0;
7178aaa36a97SAlex Deucher 			counter = 0;
7179d51ac6d0SLe Ma 			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
71809de06de8SNicolai Hähnle 			if (i < 4 && j < 2)
71819de06de8SNicolai Hähnle 				gfx_v8_0_set_user_cu_inactive_bitmap(
71829de06de8SNicolai Hähnle 					adev, disable_masks[i * 2 + j]);
71838f8e00c1SAlex Deucher 			bitmap = gfx_v8_0_get_cu_active_bitmap(adev);
718497e3c6a8SMukul Joshi 			cu_info->bitmap[0][i][j] = bitmap;
7185aaa36a97SAlex Deucher 
7186fe723cd3SRex Zhu 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
7187aaa36a97SAlex Deucher 				if (bitmap & mask) {
7188fe723cd3SRex Zhu 					if (counter < ao_cu_num)
7189aaa36a97SAlex Deucher 						ao_bitmap |= mask;
7190aaa36a97SAlex Deucher 					counter ++;
7191aaa36a97SAlex Deucher 				}
7192aaa36a97SAlex Deucher 				mask <<= 1;
7193aaa36a97SAlex Deucher 			}
7194aaa36a97SAlex Deucher 			active_cu_number += counter;
7195dbfe85eaSFlora Cui 			if (i < 2 && j < 2)
7196aaa36a97SAlex Deucher 				ao_cu_mask |= (ao_bitmap << (i * 16 + j * 8));
7197dbfe85eaSFlora Cui 			cu_info->ao_cu_bitmap[i][j] = ao_bitmap;
7198aaa36a97SAlex Deucher 		}
7199aaa36a97SAlex Deucher 	}
7200d51ac6d0SLe Ma 	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
72018f8e00c1SAlex Deucher 	mutex_unlock(&adev->grbm_idx_mutex);
7202aaa36a97SAlex Deucher 
7203aaa36a97SAlex Deucher 	cu_info->number = active_cu_number;
7204aaa36a97SAlex Deucher 	cu_info->ao_cu_mask = ao_cu_mask;
7205ebdebf42SFlora Cui 	cu_info->simd_per_cu = NUM_SIMD_PER_CU;
7206ebdebf42SFlora Cui 	cu_info->max_waves_per_simd = 10;
7207ebdebf42SFlora Cui 	cu_info->max_scratch_slots_per_cu = 32;
7208ebdebf42SFlora Cui 	cu_info->wave_front_size = 64;
7209ebdebf42SFlora Cui 	cu_info->lds_size = 64;
7210aaa36a97SAlex Deucher }
7211a1255107SAlex Deucher 
7212a1255107SAlex Deucher const struct amdgpu_ip_block_version gfx_v8_0_ip_block =
7213a1255107SAlex Deucher {
7214a1255107SAlex Deucher 	.type = AMD_IP_BLOCK_TYPE_GFX,
7215a1255107SAlex Deucher 	.major = 8,
7216a1255107SAlex Deucher 	.minor = 0,
7217a1255107SAlex Deucher 	.rev = 0,
7218a1255107SAlex Deucher 	.funcs = &gfx_v8_0_ip_funcs,
7219a1255107SAlex Deucher };
7220a1255107SAlex Deucher 
7221a1255107SAlex Deucher const struct amdgpu_ip_block_version gfx_v8_1_ip_block =
7222a1255107SAlex Deucher {
7223a1255107SAlex Deucher 	.type = AMD_IP_BLOCK_TYPE_GFX,
7224a1255107SAlex Deucher 	.major = 8,
7225a1255107SAlex Deucher 	.minor = 1,
7226a1255107SAlex Deucher 	.rev = 0,
7227a1255107SAlex Deucher 	.funcs = &gfx_v8_0_ip_funcs,
7228a1255107SAlex Deucher };
7229acad2b2aSMonk Liu 
gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring * ring)723095243543SMonk Liu static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
7231acad2b2aSMonk Liu {
7232acad2b2aSMonk Liu 	uint64_t ce_payload_addr;
7233acad2b2aSMonk Liu 	int cnt_ce;
7234d81a2209SDave Airlie 	union {
723549abb980SXiangliang Yu 		struct vi_ce_ib_state regular;
723649abb980SXiangliang Yu 		struct vi_ce_ib_state_chained_ib chained;
7237e8411302SArnd Bergmann 	} ce_payload = {};
7238acad2b2aSMonk Liu 
7239acad2b2aSMonk Liu 	if (ring->adev->virt.chained_ib_support) {
72406f05c4e9SChristian König 		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
724195243543SMonk Liu 			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
7242acad2b2aSMonk Liu 		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
7243acad2b2aSMonk Liu 	} else {
72446f05c4e9SChristian König 		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
724595243543SMonk Liu 			offsetof(struct vi_gfx_meta_data, ce_payload);
7246acad2b2aSMonk Liu 		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
7247acad2b2aSMonk Liu 	}
7248acad2b2aSMonk Liu 
7249acad2b2aSMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_ce));
7250acad2b2aSMonk Liu 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
7251acad2b2aSMonk Liu 				WRITE_DATA_DST_SEL(8) |
7252acad2b2aSMonk Liu 				WR_CONFIRM) |
7253acad2b2aSMonk Liu 				WRITE_DATA_CACHE_POLICY(0));
7254acad2b2aSMonk Liu 	amdgpu_ring_write(ring, lower_32_bits(ce_payload_addr));
7255acad2b2aSMonk Liu 	amdgpu_ring_write(ring, upper_32_bits(ce_payload_addr));
7256acad2b2aSMonk Liu 	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
7257acad2b2aSMonk Liu }
7258acad2b2aSMonk Liu 
gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring * ring)725995243543SMonk Liu static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
7260acad2b2aSMonk Liu {
726195243543SMonk Liu 	uint64_t de_payload_addr, gds_addr, csa_addr;
7262acad2b2aSMonk Liu 	int cnt_de;
7263d81a2209SDave Airlie 	union {
726449abb980SXiangliang Yu 		struct vi_de_ib_state regular;
726549abb980SXiangliang Yu 		struct vi_de_ib_state_chained_ib chained;
7266e8411302SArnd Bergmann 	} de_payload = {};
7267acad2b2aSMonk Liu 
72686f05c4e9SChristian König 	csa_addr = amdgpu_csa_vaddr(ring->adev);
7269acad2b2aSMonk Liu 	gds_addr = csa_addr + 4096;
7270acad2b2aSMonk Liu 	if (ring->adev->virt.chained_ib_support) {
7271acad2b2aSMonk Liu 		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
7272acad2b2aSMonk Liu 		de_payload.chained.gds_backup_addrhi = upper_32_bits(gds_addr);
727349abb980SXiangliang Yu 		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data_chained_ib, de_payload);
7274acad2b2aSMonk Liu 		cnt_de = (sizeof(de_payload.chained) >> 2) + 4 - 2;
7275acad2b2aSMonk Liu 	} else {
7276acad2b2aSMonk Liu 		de_payload.regular.gds_backup_addrlo = lower_32_bits(gds_addr);
7277acad2b2aSMonk Liu 		de_payload.regular.gds_backup_addrhi = upper_32_bits(gds_addr);
727849abb980SXiangliang Yu 		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data, de_payload);
7279acad2b2aSMonk Liu 		cnt_de = (sizeof(de_payload.regular) >> 2) + 4 - 2;
7280acad2b2aSMonk Liu 	}
7281acad2b2aSMonk Liu 
7282acad2b2aSMonk Liu 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_de));
7283acad2b2aSMonk Liu 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(1) |
7284acad2b2aSMonk Liu 				WRITE_DATA_DST_SEL(8) |
7285acad2b2aSMonk Liu 				WR_CONFIRM) |
7286acad2b2aSMonk Liu 				WRITE_DATA_CACHE_POLICY(0));
7287acad2b2aSMonk Liu 	amdgpu_ring_write(ring, lower_32_bits(de_payload_addr));
7288acad2b2aSMonk Liu 	amdgpu_ring_write(ring, upper_32_bits(de_payload_addr));
7289acad2b2aSMonk Liu 	amdgpu_ring_write_multiple(ring, (void *)&de_payload, cnt_de - 2);
7290acad2b2aSMonk Liu }
7291