Linux Audio

Check our new training course

Loading...
v6.13.7
   1/*
   2 * Copyright 2014 Advanced Micro Devices, Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 */
  23
  24#include <linux/delay.h>
  25#include <linux/kernel.h>
  26#include <linux/firmware.h>
  27#include <linux/module.h>
  28#include <linux/pci.h>
  29
  30#include "amdgpu.h"
  31#include "amdgpu_gfx.h"
  32#include "amdgpu_ring.h"
  33#include "vi.h"
  34#include "vi_structs.h"
  35#include "vid.h"
  36#include "amdgpu_ucode.h"
  37#include "amdgpu_atombios.h"
  38#include "atombios_i2c.h"
  39#include "clearstate_vi.h"
  40
  41#include "gmc/gmc_8_2_d.h"
  42#include "gmc/gmc_8_2_sh_mask.h"
  43
  44#include "oss/oss_3_0_d.h"
  45#include "oss/oss_3_0_sh_mask.h"
  46
  47#include "bif/bif_5_0_d.h"
  48#include "bif/bif_5_0_sh_mask.h"
  49#include "gca/gfx_8_0_d.h"
  50#include "gca/gfx_8_0_enum.h"
  51#include "gca/gfx_8_0_sh_mask.h"
 
  52
  53#include "dce/dce_10_0_d.h"
  54#include "dce/dce_10_0_sh_mask.h"
  55
  56#include "smu/smu_7_1_3_d.h"
  57
  58#include "ivsrcid/ivsrcid_vislands30.h"
  59
  60#define GFX8_NUM_GFX_RINGS     1
  61#define GFX8_MEC_HPD_SIZE 4096
  62
  63#define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001
  64#define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001
  65#define POLARIS11_GB_ADDR_CONFIG_GOLDEN 0x22011002
  66#define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003
  67
  68#define ARRAY_MODE(x)					((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT)
  69#define PIPE_CONFIG(x)					((x) << GB_TILE_MODE0__PIPE_CONFIG__SHIFT)
  70#define TILE_SPLIT(x)					((x) << GB_TILE_MODE0__TILE_SPLIT__SHIFT)
  71#define MICRO_TILE_MODE_NEW(x)				((x) << GB_TILE_MODE0__MICRO_TILE_MODE_NEW__SHIFT)
  72#define SAMPLE_SPLIT(x)					((x) << GB_TILE_MODE0__SAMPLE_SPLIT__SHIFT)
  73#define BANK_WIDTH(x)					((x) << GB_MACROTILE_MODE0__BANK_WIDTH__SHIFT)
  74#define BANK_HEIGHT(x)					((x) << GB_MACROTILE_MODE0__BANK_HEIGHT__SHIFT)
  75#define MACRO_TILE_ASPECT(x)				((x) << GB_MACROTILE_MODE0__MACRO_TILE_ASPECT__SHIFT)
  76#define NUM_BANKS(x)					((x) << GB_MACROTILE_MODE0__NUM_BANKS__SHIFT)
  77
  78#define RLC_CGTT_MGCG_OVERRIDE__CPF_MASK            0x00000001L
  79#define RLC_CGTT_MGCG_OVERRIDE__RLC_MASK            0x00000002L
  80#define RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK           0x00000004L
  81#define RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK           0x00000008L
  82#define RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK           0x00000010L
  83#define RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK           0x00000020L
  84
  85/* BPM SERDES CMD */
  86#define SET_BPM_SERDES_CMD    1
  87#define CLE_BPM_SERDES_CMD    0
  88
  89/* BPM Register Address*/
  90enum {
  91	BPM_REG_CGLS_EN = 0,        /* Enable/Disable CGLS */
  92	BPM_REG_CGLS_ON,            /* ON/OFF CGLS: shall be controlled by RLC FW */
  93	BPM_REG_CGCG_OVERRIDE,      /* Set/Clear CGCG Override */
  94	BPM_REG_MGCG_OVERRIDE,      /* Set/Clear MGCG Override */
  95	BPM_REG_FGCG_OVERRIDE,      /* Set/Clear FGCG Override */
  96	BPM_REG_FGCG_MAX
  97};
  98
  99#define RLC_FormatDirectRegListLength        14
 100
 101MODULE_FIRMWARE("amdgpu/carrizo_ce.bin");
 102MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin");
 103MODULE_FIRMWARE("amdgpu/carrizo_me.bin");
 104MODULE_FIRMWARE("amdgpu/carrizo_mec.bin");
 105MODULE_FIRMWARE("amdgpu/carrizo_mec2.bin");
 106MODULE_FIRMWARE("amdgpu/carrizo_rlc.bin");
 107
 108MODULE_FIRMWARE("amdgpu/stoney_ce.bin");
 109MODULE_FIRMWARE("amdgpu/stoney_pfp.bin");
 110MODULE_FIRMWARE("amdgpu/stoney_me.bin");
 111MODULE_FIRMWARE("amdgpu/stoney_mec.bin");
 112MODULE_FIRMWARE("amdgpu/stoney_rlc.bin");
 113
 114MODULE_FIRMWARE("amdgpu/tonga_ce.bin");
 115MODULE_FIRMWARE("amdgpu/tonga_pfp.bin");
 116MODULE_FIRMWARE("amdgpu/tonga_me.bin");
 117MODULE_FIRMWARE("amdgpu/tonga_mec.bin");
 118MODULE_FIRMWARE("amdgpu/tonga_mec2.bin");
 119MODULE_FIRMWARE("amdgpu/tonga_rlc.bin");
 120
 121MODULE_FIRMWARE("amdgpu/topaz_ce.bin");
 122MODULE_FIRMWARE("amdgpu/topaz_pfp.bin");
 123MODULE_FIRMWARE("amdgpu/topaz_me.bin");
 124MODULE_FIRMWARE("amdgpu/topaz_mec.bin");
 125MODULE_FIRMWARE("amdgpu/topaz_rlc.bin");
 126
 127MODULE_FIRMWARE("amdgpu/fiji_ce.bin");
 128MODULE_FIRMWARE("amdgpu/fiji_pfp.bin");
 129MODULE_FIRMWARE("amdgpu/fiji_me.bin");
 130MODULE_FIRMWARE("amdgpu/fiji_mec.bin");
 131MODULE_FIRMWARE("amdgpu/fiji_mec2.bin");
 132MODULE_FIRMWARE("amdgpu/fiji_rlc.bin");
 133
 134MODULE_FIRMWARE("amdgpu/polaris10_ce.bin");
 135MODULE_FIRMWARE("amdgpu/polaris10_ce_2.bin");
 136MODULE_FIRMWARE("amdgpu/polaris10_pfp.bin");
 137MODULE_FIRMWARE("amdgpu/polaris10_pfp_2.bin");
 138MODULE_FIRMWARE("amdgpu/polaris10_me.bin");
 139MODULE_FIRMWARE("amdgpu/polaris10_me_2.bin");
 140MODULE_FIRMWARE("amdgpu/polaris10_mec.bin");
 141MODULE_FIRMWARE("amdgpu/polaris10_mec_2.bin");
 142MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
 143MODULE_FIRMWARE("amdgpu/polaris10_mec2_2.bin");
 144MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");
 145
 146MODULE_FIRMWARE("amdgpu/polaris11_ce.bin");
 147MODULE_FIRMWARE("amdgpu/polaris11_ce_2.bin");
 148MODULE_FIRMWARE("amdgpu/polaris11_pfp.bin");
 149MODULE_FIRMWARE("amdgpu/polaris11_pfp_2.bin");
 150MODULE_FIRMWARE("amdgpu/polaris11_me.bin");
 151MODULE_FIRMWARE("amdgpu/polaris11_me_2.bin");
 152MODULE_FIRMWARE("amdgpu/polaris11_mec.bin");
 153MODULE_FIRMWARE("amdgpu/polaris11_mec_2.bin");
 154MODULE_FIRMWARE("amdgpu/polaris11_mec2.bin");
 155MODULE_FIRMWARE("amdgpu/polaris11_mec2_2.bin");
 156MODULE_FIRMWARE("amdgpu/polaris11_rlc.bin");
 157
 
 
 
 
 
 
 
 
 
 
 
 
 158MODULE_FIRMWARE("amdgpu/polaris12_ce.bin");
 159MODULE_FIRMWARE("amdgpu/polaris12_ce_2.bin");
 160MODULE_FIRMWARE("amdgpu/polaris12_pfp.bin");
 161MODULE_FIRMWARE("amdgpu/polaris12_pfp_2.bin");
 162MODULE_FIRMWARE("amdgpu/polaris12_me.bin");
 163MODULE_FIRMWARE("amdgpu/polaris12_me_2.bin");
 164MODULE_FIRMWARE("amdgpu/polaris12_mec.bin");
 165MODULE_FIRMWARE("amdgpu/polaris12_mec_2.bin");
 166MODULE_FIRMWARE("amdgpu/polaris12_mec2.bin");
 167MODULE_FIRMWARE("amdgpu/polaris12_mec2_2.bin");
 168MODULE_FIRMWARE("amdgpu/polaris12_rlc.bin");
 169
 170MODULE_FIRMWARE("amdgpu/vegam_ce.bin");
 171MODULE_FIRMWARE("amdgpu/vegam_pfp.bin");
 172MODULE_FIRMWARE("amdgpu/vegam_me.bin");
 173MODULE_FIRMWARE("amdgpu/vegam_mec.bin");
 174MODULE_FIRMWARE("amdgpu/vegam_mec2.bin");
 175MODULE_FIRMWARE("amdgpu/vegam_rlc.bin");
 176
 177static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
 178{
 179	{mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
 180	{mmGDS_VMID1_BASE, mmGDS_VMID1_SIZE, mmGDS_GWS_VMID1, mmGDS_OA_VMID1},
 181	{mmGDS_VMID2_BASE, mmGDS_VMID2_SIZE, mmGDS_GWS_VMID2, mmGDS_OA_VMID2},
 182	{mmGDS_VMID3_BASE, mmGDS_VMID3_SIZE, mmGDS_GWS_VMID3, mmGDS_OA_VMID3},
 183	{mmGDS_VMID4_BASE, mmGDS_VMID4_SIZE, mmGDS_GWS_VMID4, mmGDS_OA_VMID4},
 184	{mmGDS_VMID5_BASE, mmGDS_VMID5_SIZE, mmGDS_GWS_VMID5, mmGDS_OA_VMID5},
 185	{mmGDS_VMID6_BASE, mmGDS_VMID6_SIZE, mmGDS_GWS_VMID6, mmGDS_OA_VMID6},
 186	{mmGDS_VMID7_BASE, mmGDS_VMID7_SIZE, mmGDS_GWS_VMID7, mmGDS_OA_VMID7},
 187	{mmGDS_VMID8_BASE, mmGDS_VMID8_SIZE, mmGDS_GWS_VMID8, mmGDS_OA_VMID8},
 188	{mmGDS_VMID9_BASE, mmGDS_VMID9_SIZE, mmGDS_GWS_VMID9, mmGDS_OA_VMID9},
 189	{mmGDS_VMID10_BASE, mmGDS_VMID10_SIZE, mmGDS_GWS_VMID10, mmGDS_OA_VMID10},
 190	{mmGDS_VMID11_BASE, mmGDS_VMID11_SIZE, mmGDS_GWS_VMID11, mmGDS_OA_VMID11},
 191	{mmGDS_VMID12_BASE, mmGDS_VMID12_SIZE, mmGDS_GWS_VMID12, mmGDS_OA_VMID12},
 192	{mmGDS_VMID13_BASE, mmGDS_VMID13_SIZE, mmGDS_GWS_VMID13, mmGDS_OA_VMID13},
 193	{mmGDS_VMID14_BASE, mmGDS_VMID14_SIZE, mmGDS_GWS_VMID14, mmGDS_OA_VMID14},
 194	{mmGDS_VMID15_BASE, mmGDS_VMID15_SIZE, mmGDS_GWS_VMID15, mmGDS_OA_VMID15}
 195};
 196
 197static const u32 golden_settings_tonga_a11[] =
 198{
 199	mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208,
 200	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 201	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 202	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 203	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 204	mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x000000fc,
 205	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 206	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 207	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 208	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 209	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 210	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 211	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000002fb,
 212	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x0000543b,
 213	mmTCP_CHAN_STEER_LO, 0xffffffff, 0xa9210876,
 214	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 215};
 216
 217static const u32 tonga_golden_common_all[] =
 218{
 219	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 220	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
 221	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
 222	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 223	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 224	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 225	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 226	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 227};
 228
 229static const u32 tonga_mgcg_cgcg_init[] =
 230{
 231	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 232	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 233	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 234	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 235	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 236	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 237	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
 238	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 239	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 240	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 241	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 242	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 243	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 244	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 245	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 246	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 247	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 248	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 249	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 250	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 251	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 252	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 253	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 254	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 255	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 256	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 257	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 258	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 259	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 260	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 261	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 262	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 263	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 264	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 265	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 266	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 267	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 268	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 269	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 270	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 271	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 272	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 273	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 274	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 275	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 276	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 277	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 278	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 279	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 280	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 281	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 282	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 283	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 284	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 285	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 286	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 287	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 288	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 289	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 290	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 291	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 292	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 293	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 294	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
 295	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 296	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 297	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 298	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 299	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
 300	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 301	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 302	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 303	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 304	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 305	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 306};
 307
 308static const u32 golden_settings_vegam_a11[] =
 309{
 310	mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
 311	mmCB_HW_CONTROL_2, 0x0f000000, 0x0d000000,
 312	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 313	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 314	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 315	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 316	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x3a00161a,
 317	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002e,
 318	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 319	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 320	mmSQ_CONFIG, 0x07f80000, 0x01180000,
 321	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 322	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 323	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
 324	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 325	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x32761054,
 326	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 327};
 328
 329static const u32 vegam_golden_common_all[] =
 330{
 331	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 332	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 333	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 334	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 335	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 336	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 337};
 338
 339static const u32 golden_settings_polaris11_a11[] =
 340{
 341	mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
 342	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
 343	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 344	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 345	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 346	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 347	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
 348	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
 349	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 350	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 351	mmSQ_CONFIG, 0x07f80000, 0x01180000,
 352	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 353	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 354	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
 355	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 356	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00003210,
 357	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 358};
 359
 360static const u32 polaris11_golden_common_all[] =
 361{
 362	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 363	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002,
 364	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 365	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 366	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 367	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 368};
 369
 370static const u32 golden_settings_polaris10_a11[] =
 371{
 372	mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
 373	mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
 374	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
 375	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 376	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 377	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 378	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 379	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
 380	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002a,
 381	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 382	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 383	mmSQ_CONFIG, 0x07f80000, 0x07180000,
 384	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 385	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 386	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
 387	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 388	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 389};
 390
 391static const u32 polaris10_golden_common_all[] =
 392{
 393	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 394	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
 395	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
 396	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 397	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 398	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 399	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 400	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 401};
 402
 403static const u32 fiji_golden_common_all[] =
 404{
 405	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 406	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a,
 407	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e,
 408	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 409	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 410	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 411	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 412	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 413	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 414	mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009,
 415};
 416
 417static const u32 golden_settings_fiji_a10[] =
 418{
 419	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 420	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 421	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 422	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 423	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 424	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 425	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 426	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 427	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 428	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff,
 429	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 430};
 431
 432static const u32 fiji_mgcg_cgcg_init[] =
 433{
 434	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 435	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 436	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 437	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 438	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 439	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 440	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
 441	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 442	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 443	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 444	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 445	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 446	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 447	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 448	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 449	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 450	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 451	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 452	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 453	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 454	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 455	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 456	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 457	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 458	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 459	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 460	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 461	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 462	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 463	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 464	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 465	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 466	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 467	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 468	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 469};
 470
 471static const u32 golden_settings_iceland_a11[] =
 472{
 473	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 474	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 475	mmDB_DEBUG3, 0xc0000000, 0xc0000000,
 476	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 477	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 478	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 479	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
 480	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
 481	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 482	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 483	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 484	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 485	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 486	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f1,
 487	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 488	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00000010,
 489};
 490
 491static const u32 iceland_golden_common_all[] =
 492{
 493	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 494	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
 495	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 496	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
 497	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 498	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 499	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 500	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 501};
 502
 503static const u32 iceland_mgcg_cgcg_init[] =
 504{
 505	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 506	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 507	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 508	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 509	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0xc0000100,
 510	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0xc0000100,
 511	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0xc0000100,
 512	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 513	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 514	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 515	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 516	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 517	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 518	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 519	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 520	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 521	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 522	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 523	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 524	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 525	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 526	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 527	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0xff000100,
 528	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 529	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 530	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 531	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 532	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 533	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 534	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 535	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 536	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 537	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 538	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
 539	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 540	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 541	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 542	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 543	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 544	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 545	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 546	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 547	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 548	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 549	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 550	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 551	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 552	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 553	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 554	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 555	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 556	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 557	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 558	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
 559	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 560	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 561	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 562	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 563	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 564	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 565	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 566	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 567	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 568	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 569};
 570
 571static const u32 cz_golden_settings_a11[] =
 572{
 573	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 574	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 575	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 576	mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
 577	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 578	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 579	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 580	mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
 581	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 582	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 583	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
 584	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
 585};
 586
 587static const u32 cz_golden_common_all[] =
 588{
 589	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 590	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
 591	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 592	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
 593	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 594	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 595	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 596	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 597};
 598
 599static const u32 cz_mgcg_cgcg_init[] =
 600{
 601	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 602	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 603	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 604	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 605	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 606	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 607	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x00000100,
 608	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 609	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 610	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 611	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 612	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 613	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 614	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 615	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 616	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 617	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 618	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 619	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 620	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 621	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 622	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 623	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 624	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 625	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 626	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 627	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 628	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 629	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 630	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 631	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 632	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 633	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 634	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 635	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 636	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 637	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 638	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 639	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 640	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 641	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 642	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 643	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 644	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 645	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 646	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 647	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 648	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 649	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 650	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 651	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 652	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 653	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 654	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 655	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 656	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 657	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 658	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 659	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 660	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 661	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 662	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 663	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 664	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
 665	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 666	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 667	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 668	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 669	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
 670	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 671	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 672	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 673	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 674	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
 675	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 676};
 677
 678static const u32 stoney_golden_settings_a11[] =
 679{
 680	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 681	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 682	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 683	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 684	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 685	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 686	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 687	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 688	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f1,
 689	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x10101010,
 690};
 691
 692static const u32 stoney_golden_common_all[] =
 693{
 694	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 695	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000000,
 696	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 697	mmGB_ADDR_CONFIG, 0xffffffff, 0x12010001,
 698	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 699	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 700	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 701	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 702};
 703
 704static const u32 stoney_mgcg_cgcg_init[] =
 705{
 706	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 707	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
 708	mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
 709	mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
 710	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200,
 711};
 712
 713
 714static const char * const sq_edc_source_names[] = {
 715	"SQ_EDC_INFO_SOURCE_INVALID: No EDC error has occurred",
 716	"SQ_EDC_INFO_SOURCE_INST: EDC source is Instruction Fetch",
 717	"SQ_EDC_INFO_SOURCE_SGPR: EDC source is SGPR or SQC data return",
 718	"SQ_EDC_INFO_SOURCE_VGPR: EDC source is VGPR",
 719	"SQ_EDC_INFO_SOURCE_LDS: EDC source is LDS",
 720	"SQ_EDC_INFO_SOURCE_GDS: EDC source is GDS",
 721	"SQ_EDC_INFO_SOURCE_TA: EDC source is TA",
 722};
 723
 724static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
 725static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev);
 726static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev);
 727static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
 728static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
 729static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
 730static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
 731static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
 732
 733#define CG_ACLK_CNTL__ACLK_DIVIDER_MASK                    0x0000007fL
 734#define CG_ACLK_CNTL__ACLK_DIVIDER__SHIFT                  0x00000000L
 735
 736static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
 737{
 738	uint32_t data;
 739
 740	switch (adev->asic_type) {
 741	case CHIP_TOPAZ:
 742		amdgpu_device_program_register_sequence(adev,
 743							iceland_mgcg_cgcg_init,
 744							ARRAY_SIZE(iceland_mgcg_cgcg_init));
 745		amdgpu_device_program_register_sequence(adev,
 746							golden_settings_iceland_a11,
 747							ARRAY_SIZE(golden_settings_iceland_a11));
 748		amdgpu_device_program_register_sequence(adev,
 749							iceland_golden_common_all,
 750							ARRAY_SIZE(iceland_golden_common_all));
 751		break;
 752	case CHIP_FIJI:
 753		amdgpu_device_program_register_sequence(adev,
 754							fiji_mgcg_cgcg_init,
 755							ARRAY_SIZE(fiji_mgcg_cgcg_init));
 756		amdgpu_device_program_register_sequence(adev,
 757							golden_settings_fiji_a10,
 758							ARRAY_SIZE(golden_settings_fiji_a10));
 759		amdgpu_device_program_register_sequence(adev,
 760							fiji_golden_common_all,
 761							ARRAY_SIZE(fiji_golden_common_all));
 762		break;
 763
 764	case CHIP_TONGA:
 765		amdgpu_device_program_register_sequence(adev,
 766							tonga_mgcg_cgcg_init,
 767							ARRAY_SIZE(tonga_mgcg_cgcg_init));
 768		amdgpu_device_program_register_sequence(adev,
 769							golden_settings_tonga_a11,
 770							ARRAY_SIZE(golden_settings_tonga_a11));
 771		amdgpu_device_program_register_sequence(adev,
 772							tonga_golden_common_all,
 773							ARRAY_SIZE(tonga_golden_common_all));
 774		break;
 775	case CHIP_VEGAM:
 776		amdgpu_device_program_register_sequence(adev,
 777							golden_settings_vegam_a11,
 778							ARRAY_SIZE(golden_settings_vegam_a11));
 779		amdgpu_device_program_register_sequence(adev,
 780							vegam_golden_common_all,
 781							ARRAY_SIZE(vegam_golden_common_all));
 782		break;
 783	case CHIP_POLARIS11:
 784	case CHIP_POLARIS12:
 785		amdgpu_device_program_register_sequence(adev,
 786							golden_settings_polaris11_a11,
 787							ARRAY_SIZE(golden_settings_polaris11_a11));
 788		amdgpu_device_program_register_sequence(adev,
 789							polaris11_golden_common_all,
 790							ARRAY_SIZE(polaris11_golden_common_all));
 791		break;
 792	case CHIP_POLARIS10:
 793		amdgpu_device_program_register_sequence(adev,
 794							golden_settings_polaris10_a11,
 795							ARRAY_SIZE(golden_settings_polaris10_a11));
 796		amdgpu_device_program_register_sequence(adev,
 797							polaris10_golden_common_all,
 798							ARRAY_SIZE(polaris10_golden_common_all));
 799		data = RREG32_SMC(ixCG_ACLK_CNTL);
 800		data &= ~CG_ACLK_CNTL__ACLK_DIVIDER_MASK;
 801		data |= 0x18 << CG_ACLK_CNTL__ACLK_DIVIDER__SHIFT;
 802		WREG32_SMC(ixCG_ACLK_CNTL, data);
 803		if ((adev->pdev->device == 0x67DF) && (adev->pdev->revision == 0xc7) &&
 804		    ((adev->pdev->subsystem_device == 0xb37 && adev->pdev->subsystem_vendor == 0x1002) ||
 805		     (adev->pdev->subsystem_device == 0x4a8 && adev->pdev->subsystem_vendor == 0x1043) ||
 806		     (adev->pdev->subsystem_device == 0x9480 && adev->pdev->subsystem_vendor == 0x1680))) {
 807			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1E, 0xDD);
 808			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1F, 0xD0);
 809		}
 810		break;
 811	case CHIP_CARRIZO:
 812		amdgpu_device_program_register_sequence(adev,
 813							cz_mgcg_cgcg_init,
 814							ARRAY_SIZE(cz_mgcg_cgcg_init));
 815		amdgpu_device_program_register_sequence(adev,
 816							cz_golden_settings_a11,
 817							ARRAY_SIZE(cz_golden_settings_a11));
 818		amdgpu_device_program_register_sequence(adev,
 819							cz_golden_common_all,
 820							ARRAY_SIZE(cz_golden_common_all));
 821		break;
 822	case CHIP_STONEY:
 823		amdgpu_device_program_register_sequence(adev,
 824							stoney_mgcg_cgcg_init,
 825							ARRAY_SIZE(stoney_mgcg_cgcg_init));
 826		amdgpu_device_program_register_sequence(adev,
 827							stoney_golden_settings_a11,
 828							ARRAY_SIZE(stoney_golden_settings_a11));
 829		amdgpu_device_program_register_sequence(adev,
 830							stoney_golden_common_all,
 831							ARRAY_SIZE(stoney_golden_common_all));
 832		break;
 833	default:
 834		break;
 835	}
 836}
 837
 
 
 
 
 
 
 
 838static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
 839{
 840	struct amdgpu_device *adev = ring->adev;
 
 841	uint32_t tmp = 0;
 842	unsigned i;
 843	int r;
 844
 845	WREG32(mmSCRATCH_REG0, 0xCAFEDEAD);
 
 
 
 
 
 846	r = amdgpu_ring_alloc(ring, 3);
 847	if (r)
 
 
 
 848		return r;
 849
 850	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
 851	amdgpu_ring_write(ring, mmSCRATCH_REG0 - PACKET3_SET_UCONFIG_REG_START);
 852	amdgpu_ring_write(ring, 0xDEADBEEF);
 853	amdgpu_ring_commit(ring);
 854
 855	for (i = 0; i < adev->usec_timeout; i++) {
 856		tmp = RREG32(mmSCRATCH_REG0);
 857		if (tmp == 0xDEADBEEF)
 858			break;
 859		udelay(1);
 860	}
 861
 862	if (i >= adev->usec_timeout)
 863		r = -ETIMEDOUT;
 864
 
 
 
 
 
 865	return r;
 866}
 867
 868static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 869{
 870	struct amdgpu_device *adev = ring->adev;
 871	struct amdgpu_ib ib;
 872	struct dma_fence *f = NULL;
 873
 874	unsigned int index;
 875	uint64_t gpu_addr;
 876	uint32_t tmp;
 877	long r;
 878
 879	r = amdgpu_device_wb_get(adev, &index);
 880	if (r)
 
 881		return r;
 882
 883	gpu_addr = adev->wb.gpu_addr + (index * 4);
 884	adev->wb.wb[index] = cpu_to_le32(0xCAFEDEAD);
 885	memset(&ib, 0, sizeof(ib));
 886
 887	r = amdgpu_ib_get(adev, NULL, 20, AMDGPU_IB_POOL_DIRECT, &ib);
 888	if (r)
 889		goto err1;
 890
 891	ib.ptr[0] = PACKET3(PACKET3_WRITE_DATA, 3);
 892	ib.ptr[1] = WRITE_DATA_DST_SEL(5) | WR_CONFIRM;
 893	ib.ptr[2] = lower_32_bits(gpu_addr);
 894	ib.ptr[3] = upper_32_bits(gpu_addr);
 895	ib.ptr[4] = 0xDEADBEEF;
 896	ib.length_dw = 5;
 897
 898	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
 899	if (r)
 900		goto err2;
 901
 902	r = dma_fence_wait_timeout(f, false, timeout);
 903	if (r == 0) {
 
 904		r = -ETIMEDOUT;
 905		goto err2;
 906	} else if (r < 0) {
 
 907		goto err2;
 908	}
 909
 910	tmp = adev->wb.wb[index];
 911	if (tmp == 0xDEADBEEF)
 912		r = 0;
 913	else
 
 
 914		r = -EINVAL;
 915
 916err2:
 917	amdgpu_ib_free(adev, &ib, NULL);
 918	dma_fence_put(f);
 919err1:
 920	amdgpu_device_wb_free(adev, index);
 921	return r;
 922}
 923
 924
 925static void gfx_v8_0_free_microcode(struct amdgpu_device *adev)
 926{
 927	amdgpu_ucode_release(&adev->gfx.pfp_fw);
 928	amdgpu_ucode_release(&adev->gfx.me_fw);
 929	amdgpu_ucode_release(&adev->gfx.ce_fw);
 930	amdgpu_ucode_release(&adev->gfx.rlc_fw);
 931	amdgpu_ucode_release(&adev->gfx.mec_fw);
 
 
 
 
 
 932	if ((adev->asic_type != CHIP_STONEY) &&
 933	    (adev->asic_type != CHIP_TOPAZ))
 934		amdgpu_ucode_release(&adev->gfx.mec2_fw);
 
 935
 936	kfree(adev->gfx.rlc.register_list_format);
 937}
 938
 939static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
 940{
 941	const char *chip_name;
 
 942	int err;
 943	struct amdgpu_firmware_info *info = NULL;
 944	const struct common_firmware_header *header = NULL;
 945	const struct gfx_firmware_header_v1_0 *cp_hdr;
 946	const struct rlc_firmware_header_v2_0 *rlc_hdr;
 947	unsigned int *tmp = NULL, i;
 948
 949	DRM_DEBUG("\n");
 950
 951	switch (adev->asic_type) {
 952	case CHIP_TOPAZ:
 953		chip_name = "topaz";
 954		break;
 955	case CHIP_TONGA:
 956		chip_name = "tonga";
 957		break;
 958	case CHIP_CARRIZO:
 959		chip_name = "carrizo";
 960		break;
 961	case CHIP_FIJI:
 962		chip_name = "fiji";
 963		break;
 964	case CHIP_STONEY:
 965		chip_name = "stoney";
 966		break;
 967	case CHIP_POLARIS10:
 968		chip_name = "polaris10";
 969		break;
 970	case CHIP_POLARIS11:
 971		chip_name = "polaris11";
 972		break;
 973	case CHIP_POLARIS12:
 974		chip_name = "polaris12";
 975		break;
 976	case CHIP_VEGAM:
 977		chip_name = "vegam";
 978		break;
 979	default:
 980		BUG();
 981	}
 982
 983	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
 984		err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
 985					   "amdgpu/%s_pfp_2.bin", chip_name);
 986		if (err == -ENODEV) {
 987			err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
 988						   "amdgpu/%s_pfp.bin", chip_name);
 989		}
 990	} else {
 991		err = amdgpu_ucode_request(adev, &adev->gfx.pfp_fw,
 992					   "amdgpu/%s_pfp.bin", chip_name);
 993	}
 994	if (err)
 995		goto out;
 
 
 
 996	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
 997	adev->gfx.pfp_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
 998	adev->gfx.pfp_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
 999
1000	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1001		err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
1002					   "amdgpu/%s_me_2.bin", chip_name);
1003		if (err == -ENODEV) {
1004			err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
1005						   "amdgpu/%s_me.bin", chip_name);
1006		}
1007	} else {
1008		err = amdgpu_ucode_request(adev, &adev->gfx.me_fw,
1009					   "amdgpu/%s_me.bin", chip_name);
1010	}
1011	if (err)
1012		goto out;
 
 
 
1013	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
1014	adev->gfx.me_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1015
1016	adev->gfx.me_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1017
1018	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1019		err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
1020					   "amdgpu/%s_ce_2.bin", chip_name);
1021		if (err == -ENODEV) {
1022			err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
1023						   "amdgpu/%s_ce.bin", chip_name);
1024		}
1025	} else {
1026		err = amdgpu_ucode_request(adev, &adev->gfx.ce_fw,
1027					   "amdgpu/%s_ce.bin", chip_name);
1028	}
1029	if (err)
1030		goto out;
 
 
 
1031	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
1032	adev->gfx.ce_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1033	adev->gfx.ce_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1034
1035	/*
1036	 * Support for MCBP/Virtualization in combination with chained IBs is
1037	 * formal released on feature version #46
1038	 */
1039	if (adev->gfx.ce_feature_version >= 46 &&
1040	    adev->gfx.pfp_feature_version >= 46) {
1041		adev->virt.chained_ib_support = true;
1042		DRM_INFO("Chained IB support enabled!\n");
1043	} else
1044		adev->virt.chained_ib_support = false;
1045
1046	err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw,
1047				   "amdgpu/%s_rlc.bin", chip_name);
1048	if (err)
1049		goto out;
 
1050	rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
1051	adev->gfx.rlc_fw_version = le32_to_cpu(rlc_hdr->header.ucode_version);
1052	adev->gfx.rlc_feature_version = le32_to_cpu(rlc_hdr->ucode_feature_version);
1053
1054	adev->gfx.rlc.save_and_restore_offset =
1055			le32_to_cpu(rlc_hdr->save_and_restore_offset);
1056	adev->gfx.rlc.clear_state_descriptor_offset =
1057			le32_to_cpu(rlc_hdr->clear_state_descriptor_offset);
1058	adev->gfx.rlc.avail_scratch_ram_locations =
1059			le32_to_cpu(rlc_hdr->avail_scratch_ram_locations);
1060	adev->gfx.rlc.reg_restore_list_size =
1061			le32_to_cpu(rlc_hdr->reg_restore_list_size);
1062	adev->gfx.rlc.reg_list_format_start =
1063			le32_to_cpu(rlc_hdr->reg_list_format_start);
1064	adev->gfx.rlc.reg_list_format_separate_start =
1065			le32_to_cpu(rlc_hdr->reg_list_format_separate_start);
1066	adev->gfx.rlc.starting_offsets_start =
1067			le32_to_cpu(rlc_hdr->starting_offsets_start);
1068	adev->gfx.rlc.reg_list_format_size_bytes =
1069			le32_to_cpu(rlc_hdr->reg_list_format_size_bytes);
1070	adev->gfx.rlc.reg_list_size_bytes =
1071			le32_to_cpu(rlc_hdr->reg_list_size_bytes);
1072
1073	adev->gfx.rlc.register_list_format =
1074			kmalloc(adev->gfx.rlc.reg_list_format_size_bytes +
1075					adev->gfx.rlc.reg_list_size_bytes, GFP_KERNEL);
1076
1077	if (!adev->gfx.rlc.register_list_format) {
1078		err = -ENOMEM;
1079		goto out;
1080	}
1081
1082	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
1083			le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
1084	for (i = 0 ; i < (adev->gfx.rlc.reg_list_format_size_bytes >> 2); i++)
1085		adev->gfx.rlc.register_list_format[i] =	le32_to_cpu(tmp[i]);
1086
1087	adev->gfx.rlc.register_restore = adev->gfx.rlc.register_list_format + i;
1088
1089	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
1090			le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
1091	for (i = 0 ; i < (adev->gfx.rlc.reg_list_size_bytes >> 2); i++)
1092		adev->gfx.rlc.register_restore[i] = le32_to_cpu(tmp[i]);
1093
1094	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1095		err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
1096					   "amdgpu/%s_mec_2.bin", chip_name);
1097		if (err == -ENODEV) {
1098			err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
1099						   "amdgpu/%s_mec.bin", chip_name);
1100		}
1101	} else {
1102		err = amdgpu_ucode_request(adev, &adev->gfx.mec_fw,
1103					   "amdgpu/%s_mec.bin", chip_name);
1104	}
1105	if (err)
1106		goto out;
 
 
 
1107	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1108	adev->gfx.mec_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1109	adev->gfx.mec_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1110
1111	if ((adev->asic_type != CHIP_STONEY) &&
1112	    (adev->asic_type != CHIP_TOPAZ)) {
1113		if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1114			err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
1115						   "amdgpu/%s_mec2_2.bin", chip_name);
1116			if (err == -ENODEV) {
1117				err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
1118							   "amdgpu/%s_mec2.bin", chip_name);
1119			}
1120		} else {
1121			err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw,
1122						   "amdgpu/%s_mec2.bin", chip_name);
1123		}
1124		if (!err) {
 
 
 
1125			cp_hdr = (const struct gfx_firmware_header_v1_0 *)
1126				adev->gfx.mec2_fw->data;
1127			adev->gfx.mec2_fw_version =
1128				le32_to_cpu(cp_hdr->header.ucode_version);
1129			adev->gfx.mec2_feature_version =
1130				le32_to_cpu(cp_hdr->ucode_feature_version);
1131		} else {
1132			err = 0;
1133			adev->gfx.mec2_fw = NULL;
1134		}
1135	}
1136
1137	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_PFP];
1138	info->ucode_id = AMDGPU_UCODE_ID_CP_PFP;
1139	info->fw = adev->gfx.pfp_fw;
1140	header = (const struct common_firmware_header *)info->fw->data;
1141	adev->firmware.fw_size +=
1142		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1143
1144	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_ME];
1145	info->ucode_id = AMDGPU_UCODE_ID_CP_ME;
1146	info->fw = adev->gfx.me_fw;
1147	header = (const struct common_firmware_header *)info->fw->data;
1148	adev->firmware.fw_size +=
1149		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1150
1151	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_CE];
1152	info->ucode_id = AMDGPU_UCODE_ID_CP_CE;
1153	info->fw = adev->gfx.ce_fw;
1154	header = (const struct common_firmware_header *)info->fw->data;
1155	adev->firmware.fw_size +=
1156		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1157
1158	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_RLC_G];
1159	info->ucode_id = AMDGPU_UCODE_ID_RLC_G;
1160	info->fw = adev->gfx.rlc_fw;
1161	header = (const struct common_firmware_header *)info->fw->data;
1162	adev->firmware.fw_size +=
1163		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1164
1165	info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC1];
1166	info->ucode_id = AMDGPU_UCODE_ID_CP_MEC1;
1167	info->fw = adev->gfx.mec_fw;
1168	header = (const struct common_firmware_header *)info->fw->data;
1169	adev->firmware.fw_size +=
1170		ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1171
1172	/* we need account JT in */
1173	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1174	adev->firmware.fw_size +=
1175		ALIGN(le32_to_cpu(cp_hdr->jt_size) << 2, PAGE_SIZE);
 
 
1176
1177	if (amdgpu_sriov_vf(adev)) {
1178		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_STORAGE];
1179		info->ucode_id = AMDGPU_UCODE_ID_STORAGE;
1180		info->fw = adev->gfx.mec_fw;
1181		adev->firmware.fw_size +=
1182			ALIGN(le32_to_cpu(64 * PAGE_SIZE), PAGE_SIZE);
1183	}
1184
1185	if (adev->gfx.mec2_fw) {
1186		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC2];
1187		info->ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
1188		info->fw = adev->gfx.mec2_fw;
1189		header = (const struct common_firmware_header *)info->fw->data;
1190		adev->firmware.fw_size +=
1191			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1192	}
1193
1194out:
1195	if (err) {
1196		dev_err(adev->dev, "gfx8: Failed to load firmware %s gfx firmware\n", chip_name);
1197		amdgpu_ucode_release(&adev->gfx.pfp_fw);
1198		amdgpu_ucode_release(&adev->gfx.me_fw);
1199		amdgpu_ucode_release(&adev->gfx.ce_fw);
1200		amdgpu_ucode_release(&adev->gfx.rlc_fw);
1201		amdgpu_ucode_release(&adev->gfx.mec_fw);
1202		amdgpu_ucode_release(&adev->gfx.mec2_fw);
 
 
 
 
 
 
 
 
1203	}
1204	return err;
1205}
1206
1207static void gfx_v8_0_get_csb_buffer(struct amdgpu_device *adev,
1208				    volatile u32 *buffer)
1209{
1210	u32 count = 0, i;
1211	const struct cs_section_def *sect = NULL;
1212	const struct cs_extent_def *ext = NULL;
1213
1214	if (adev->gfx.rlc.cs_data == NULL)
1215		return;
1216	if (buffer == NULL)
1217		return;
1218
1219	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1220	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
1221
1222	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
1223	buffer[count++] = cpu_to_le32(0x80000000);
1224	buffer[count++] = cpu_to_le32(0x80000000);
1225
1226	for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
1227		for (ext = sect->section; ext->extent != NULL; ++ext) {
1228			if (sect->id == SECT_CONTEXT) {
1229				buffer[count++] =
1230					cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
1231				buffer[count++] = cpu_to_le32(ext->reg_index -
1232						PACKET3_SET_CONTEXT_REG_START);
1233				for (i = 0; i < ext->reg_count; i++)
1234					buffer[count++] = cpu_to_le32(ext->extent[i]);
1235			} else {
1236				return;
1237			}
1238		}
1239	}
1240
1241	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
1242	buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG -
1243			PACKET3_SET_CONTEXT_REG_START);
1244	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
1245	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
1246
1247	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1248	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
1249
1250	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
1251	buffer[count++] = cpu_to_le32(0);
1252}
1253
1254static int gfx_v8_0_cp_jump_table_num(struct amdgpu_device *adev)
1255{
 
 
 
 
 
 
1256	if (adev->asic_type == CHIP_CARRIZO)
1257		return 5;
1258	else
1259		return 4;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1260}
1261
1262static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)
1263{
 
 
1264	const struct cs_section_def *cs_data;
1265	int r;
1266
1267	adev->gfx.rlc.cs_data = vi_cs_data;
1268
1269	cs_data = adev->gfx.rlc.cs_data;
1270
1271	if (cs_data) {
1272		/* init clear state block */
1273		r = amdgpu_gfx_rlc_init_csb(adev);
1274		if (r)
 
 
 
 
 
 
 
 
1275			return r;
 
 
 
 
 
 
 
1276	}
1277
1278	if ((adev->asic_type == CHIP_CARRIZO) ||
1279	    (adev->asic_type == CHIP_STONEY)) {
1280		adev->gfx.rlc.cp_table_size = ALIGN(96 * 5 * 4, 2048) + (64 * 1024); /* JT + GDS */
1281		r = amdgpu_gfx_rlc_init_cpt(adev);
1282		if (r)
 
 
 
 
 
1283			return r;
1284	}
 
 
1285
1286	/* init spm vmid with 0xf */
1287	if (adev->gfx.rlc.funcs->update_spm_vmid)
1288		adev->gfx.rlc.funcs->update_spm_vmid(adev, NULL, 0xf);
1289
1290	return 0;
1291}
1292
1293static void gfx_v8_0_mec_fini(struct amdgpu_device *adev)
1294{
1295	amdgpu_bo_free_kernel(&adev->gfx.mec.hpd_eop_obj, NULL, NULL);
1296}
1297
1298static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
1299{
1300	int r;
1301	u32 *hpd;
1302	size_t mec_hpd_size;
1303
1304	bitmap_zero(adev->gfx.mec_bitmap[0].queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
1305
1306	/* take ownership of the relevant compute queues */
1307	amdgpu_gfx_compute_queue_acquire(adev);
1308
1309	mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
1310	if (mec_hpd_size) {
1311		r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
1312					      AMDGPU_GEM_DOMAIN_VRAM |
1313					      AMDGPU_GEM_DOMAIN_GTT,
1314					      &adev->gfx.mec.hpd_eop_obj,
1315					      &adev->gfx.mec.hpd_eop_gpu_addr,
1316					      (void **)&hpd);
1317		if (r) {
1318			dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
1319			return r;
1320		}
1321
1322		memset(hpd, 0, mec_hpd_size);
1323
1324		amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
1325		amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
 
 
 
 
 
 
1326	}
1327
 
 
 
 
 
1328	return 0;
1329}
1330
1331static const u32 vgpr_init_compute_shader[] =
1332{
1333	0x7e000209, 0x7e020208,
1334	0x7e040207, 0x7e060206,
1335	0x7e080205, 0x7e0a0204,
1336	0x7e0c0203, 0x7e0e0202,
1337	0x7e100201, 0x7e120200,
1338	0x7e140209, 0x7e160208,
1339	0x7e180207, 0x7e1a0206,
1340	0x7e1c0205, 0x7e1e0204,
1341	0x7e200203, 0x7e220202,
1342	0x7e240201, 0x7e260200,
1343	0x7e280209, 0x7e2a0208,
1344	0x7e2c0207, 0x7e2e0206,
1345	0x7e300205, 0x7e320204,
1346	0x7e340203, 0x7e360202,
1347	0x7e380201, 0x7e3a0200,
1348	0x7e3c0209, 0x7e3e0208,
1349	0x7e400207, 0x7e420206,
1350	0x7e440205, 0x7e460204,
1351	0x7e480203, 0x7e4a0202,
1352	0x7e4c0201, 0x7e4e0200,
1353	0x7e500209, 0x7e520208,
1354	0x7e540207, 0x7e560206,
1355	0x7e580205, 0x7e5a0204,
1356	0x7e5c0203, 0x7e5e0202,
1357	0x7e600201, 0x7e620200,
1358	0x7e640209, 0x7e660208,
1359	0x7e680207, 0x7e6a0206,
1360	0x7e6c0205, 0x7e6e0204,
1361	0x7e700203, 0x7e720202,
1362	0x7e740201, 0x7e760200,
1363	0x7e780209, 0x7e7a0208,
1364	0x7e7c0207, 0x7e7e0206,
1365	0xbf8a0000, 0xbf810000,
1366};
1367
1368static const u32 sgpr_init_compute_shader[] =
1369{
1370	0xbe8a0100, 0xbe8c0102,
1371	0xbe8e0104, 0xbe900106,
1372	0xbe920108, 0xbe940100,
1373	0xbe960102, 0xbe980104,
1374	0xbe9a0106, 0xbe9c0108,
1375	0xbe9e0100, 0xbea00102,
1376	0xbea20104, 0xbea40106,
1377	0xbea60108, 0xbea80100,
1378	0xbeaa0102, 0xbeac0104,
1379	0xbeae0106, 0xbeb00108,
1380	0xbeb20100, 0xbeb40102,
1381	0xbeb60104, 0xbeb80106,
1382	0xbeba0108, 0xbebc0100,
1383	0xbebe0102, 0xbec00104,
1384	0xbec20106, 0xbec40108,
1385	0xbec60100, 0xbec80102,
1386	0xbee60004, 0xbee70005,
1387	0xbeea0006, 0xbeeb0007,
1388	0xbee80008, 0xbee90009,
1389	0xbefc0000, 0xbf8a0000,
1390	0xbf810000, 0x00000000,
1391};
1392
1393static const u32 vgpr_init_regs[] =
1394{
1395	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xffffffff,
1396	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1397	mmCOMPUTE_NUM_THREAD_X, 256*4,
1398	mmCOMPUTE_NUM_THREAD_Y, 1,
1399	mmCOMPUTE_NUM_THREAD_Z, 1,
1400	mmCOMPUTE_PGM_RSRC1, 0x100004f, /* VGPRS=15 (64 logical VGPRs), SGPRS=1 (16 SGPRs), BULKY=1 */
1401	mmCOMPUTE_PGM_RSRC2, 20,
1402	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1403	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1404	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1405	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1406	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1407	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1408	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1409	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1410	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1411	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1412};
1413
1414static const u32 sgpr1_init_regs[] =
1415{
1416	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0x0f,
1417	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1418	mmCOMPUTE_NUM_THREAD_X, 256*5,
1419	mmCOMPUTE_NUM_THREAD_Y, 1,
1420	mmCOMPUTE_NUM_THREAD_Z, 1,
1421	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1422	mmCOMPUTE_PGM_RSRC2, 20,
1423	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1424	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1425	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1426	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1427	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1428	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1429	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1430	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1431	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1432	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1433};
1434
1435static const u32 sgpr2_init_regs[] =
1436{
1437	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xf0,
1438	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000,
1439	mmCOMPUTE_NUM_THREAD_X, 256*5,
1440	mmCOMPUTE_NUM_THREAD_Y, 1,
1441	mmCOMPUTE_NUM_THREAD_Z, 1,
1442	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1443	mmCOMPUTE_PGM_RSRC2, 20,
1444	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1445	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1446	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1447	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1448	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1449	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1450	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1451	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1452	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1453	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1454};
1455
1456static const u32 sec_ded_counter_registers[] =
1457{
1458	mmCPC_EDC_ATC_CNT,
1459	mmCPC_EDC_SCRATCH_CNT,
1460	mmCPC_EDC_UCODE_CNT,
1461	mmCPF_EDC_ATC_CNT,
1462	mmCPF_EDC_ROQ_CNT,
1463	mmCPF_EDC_TAG_CNT,
1464	mmCPG_EDC_ATC_CNT,
1465	mmCPG_EDC_DMA_CNT,
1466	mmCPG_EDC_TAG_CNT,
1467	mmDC_EDC_CSINVOC_CNT,
1468	mmDC_EDC_RESTORE_CNT,
1469	mmDC_EDC_STATE_CNT,
1470	mmGDS_EDC_CNT,
1471	mmGDS_EDC_GRBM_CNT,
1472	mmGDS_EDC_OA_DED,
1473	mmSPI_EDC_CNT,
1474	mmSQC_ATC_EDC_GATCL1_CNT,
1475	mmSQC_EDC_CNT,
1476	mmSQ_EDC_DED_CNT,
1477	mmSQ_EDC_INFO,
1478	mmSQ_EDC_SEC_CNT,
1479	mmTCC_EDC_CNT,
1480	mmTCP_ATC_EDC_GATCL1_CNT,
1481	mmTCP_EDC_CNT,
1482	mmTD_EDC_CNT
1483};
1484
1485static int gfx_v8_0_do_edc_gpr_workarounds(struct amdgpu_device *adev)
1486{
1487	struct amdgpu_ring *ring = &adev->gfx.compute_ring[0];
1488	struct amdgpu_ib ib;
1489	struct dma_fence *f = NULL;
1490	int r, i;
1491	u32 tmp;
1492	unsigned total_size, vgpr_offset, sgpr_offset;
1493	u64 gpu_addr;
1494
1495	/* only supported on CZ */
1496	if (adev->asic_type != CHIP_CARRIZO)
1497		return 0;
1498
1499	/* bail if the compute ring is not ready */
1500	if (!ring->sched.ready)
1501		return 0;
1502
1503	tmp = RREG32(mmGB_EDC_MODE);
1504	WREG32(mmGB_EDC_MODE, 0);
1505
1506	total_size =
1507		(((ARRAY_SIZE(vgpr_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1508	total_size +=
1509		(((ARRAY_SIZE(sgpr1_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1510	total_size +=
1511		(((ARRAY_SIZE(sgpr2_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1512	total_size = ALIGN(total_size, 256);
1513	vgpr_offset = total_size;
1514	total_size += ALIGN(sizeof(vgpr_init_compute_shader), 256);
1515	sgpr_offset = total_size;
1516	total_size += sizeof(sgpr_init_compute_shader);
1517
1518	/* allocate an indirect buffer to put the commands in */
1519	memset(&ib, 0, sizeof(ib));
1520	r = amdgpu_ib_get(adev, NULL, total_size,
1521					AMDGPU_IB_POOL_DIRECT, &ib);
1522	if (r) {
1523		DRM_ERROR("amdgpu: failed to get ib (%d).\n", r);
1524		return r;
1525	}
1526
1527	/* load the compute shaders */
1528	for (i = 0; i < ARRAY_SIZE(vgpr_init_compute_shader); i++)
1529		ib.ptr[i + (vgpr_offset / 4)] = vgpr_init_compute_shader[i];
1530
1531	for (i = 0; i < ARRAY_SIZE(sgpr_init_compute_shader); i++)
1532		ib.ptr[i + (sgpr_offset / 4)] = sgpr_init_compute_shader[i];
1533
1534	/* init the ib length to 0 */
1535	ib.length_dw = 0;
1536
1537	/* VGPR */
1538	/* write the register state for the compute dispatch */
1539	for (i = 0; i < ARRAY_SIZE(vgpr_init_regs); i += 2) {
1540		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1541		ib.ptr[ib.length_dw++] = vgpr_init_regs[i] - PACKET3_SET_SH_REG_START;
1542		ib.ptr[ib.length_dw++] = vgpr_init_regs[i + 1];
1543	}
1544	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1545	gpu_addr = (ib.gpu_addr + (u64)vgpr_offset) >> 8;
1546	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1547	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1548	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1549	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1550
1551	/* write dispatch packet */
1552	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1553	ib.ptr[ib.length_dw++] = 8; /* x */
1554	ib.ptr[ib.length_dw++] = 1; /* y */
1555	ib.ptr[ib.length_dw++] = 1; /* z */
1556	ib.ptr[ib.length_dw++] =
1557		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1558
1559	/* write CS partial flush packet */
1560	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1561	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1562
1563	/* SGPR1 */
1564	/* write the register state for the compute dispatch */
1565	for (i = 0; i < ARRAY_SIZE(sgpr1_init_regs); i += 2) {
1566		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1567		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i] - PACKET3_SET_SH_REG_START;
1568		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i + 1];
1569	}
1570	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1571	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1572	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1573	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1574	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1575	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1576
1577	/* write dispatch packet */
1578	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1579	ib.ptr[ib.length_dw++] = 8; /* x */
1580	ib.ptr[ib.length_dw++] = 1; /* y */
1581	ib.ptr[ib.length_dw++] = 1; /* z */
1582	ib.ptr[ib.length_dw++] =
1583		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1584
1585	/* write CS partial flush packet */
1586	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1587	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1588
1589	/* SGPR2 */
1590	/* write the register state for the compute dispatch */
1591	for (i = 0; i < ARRAY_SIZE(sgpr2_init_regs); i += 2) {
1592		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1593		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i] - PACKET3_SET_SH_REG_START;
1594		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i + 1];
1595	}
1596	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1597	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1598	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1599	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1600	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1601	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1602
1603	/* write dispatch packet */
1604	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1605	ib.ptr[ib.length_dw++] = 8; /* x */
1606	ib.ptr[ib.length_dw++] = 1; /* y */
1607	ib.ptr[ib.length_dw++] = 1; /* z */
1608	ib.ptr[ib.length_dw++] =
1609		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1610
1611	/* write CS partial flush packet */
1612	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1613	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1614
1615	/* shedule the ib on the ring */
1616	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
1617	if (r) {
1618		DRM_ERROR("amdgpu: ib submit failed (%d).\n", r);
1619		goto fail;
1620	}
1621
1622	/* wait for the GPU to finish processing the IB */
1623	r = dma_fence_wait(f, false);
1624	if (r) {
1625		DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
1626		goto fail;
1627	}
1628
1629	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, DED_MODE, 2);
1630	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, PROP_FED, 1);
1631	WREG32(mmGB_EDC_MODE, tmp);
1632
1633	tmp = RREG32(mmCC_GC_EDC_CONFIG);
1634	tmp = REG_SET_FIELD(tmp, CC_GC_EDC_CONFIG, DIS_EDC, 0) | 1;
1635	WREG32(mmCC_GC_EDC_CONFIG, tmp);
1636
1637
1638	/* read back registers to clear the counters */
1639	for (i = 0; i < ARRAY_SIZE(sec_ded_counter_registers); i++)
1640		RREG32(sec_ded_counter_registers[i]);
1641
1642fail:
1643	amdgpu_ib_free(adev, &ib, NULL);
1644	dma_fence_put(f);
1645
1646	return r;
1647}
1648
1649static int gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1650{
1651	u32 gb_addr_config;
1652	u32 mc_arb_ramcfg;
1653	u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
1654	u32 tmp;
1655	int ret;
1656
1657	switch (adev->asic_type) {
1658	case CHIP_TOPAZ:
1659		adev->gfx.config.max_shader_engines = 1;
1660		adev->gfx.config.max_tile_pipes = 2;
1661		adev->gfx.config.max_cu_per_sh = 6;
1662		adev->gfx.config.max_sh_per_se = 1;
1663		adev->gfx.config.max_backends_per_se = 2;
1664		adev->gfx.config.max_texture_channel_caches = 2;
1665		adev->gfx.config.max_gprs = 256;
1666		adev->gfx.config.max_gs_threads = 32;
1667		adev->gfx.config.max_hw_contexts = 8;
1668
1669		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1670		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1671		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1672		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1673		gb_addr_config = TOPAZ_GB_ADDR_CONFIG_GOLDEN;
1674		break;
1675	case CHIP_FIJI:
1676		adev->gfx.config.max_shader_engines = 4;
1677		adev->gfx.config.max_tile_pipes = 16;
1678		adev->gfx.config.max_cu_per_sh = 16;
1679		adev->gfx.config.max_sh_per_se = 1;
1680		adev->gfx.config.max_backends_per_se = 4;
1681		adev->gfx.config.max_texture_channel_caches = 16;
1682		adev->gfx.config.max_gprs = 256;
1683		adev->gfx.config.max_gs_threads = 32;
1684		adev->gfx.config.max_hw_contexts = 8;
1685
1686		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1687		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1688		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1689		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1690		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1691		break;
1692	case CHIP_POLARIS11:
1693	case CHIP_POLARIS12:
1694		ret = amdgpu_atombios_get_gfx_info(adev);
1695		if (ret)
1696			return ret;
1697		adev->gfx.config.max_gprs = 256;
1698		adev->gfx.config.max_gs_threads = 32;
1699		adev->gfx.config.max_hw_contexts = 8;
1700
1701		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1702		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1703		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1704		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1705		gb_addr_config = POLARIS11_GB_ADDR_CONFIG_GOLDEN;
1706		break;
1707	case CHIP_POLARIS10:
1708	case CHIP_VEGAM:
1709		ret = amdgpu_atombios_get_gfx_info(adev);
1710		if (ret)
1711			return ret;
1712		adev->gfx.config.max_gprs = 256;
1713		adev->gfx.config.max_gs_threads = 32;
1714		adev->gfx.config.max_hw_contexts = 8;
1715
1716		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1717		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1718		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1719		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1720		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1721		break;
1722	case CHIP_TONGA:
1723		adev->gfx.config.max_shader_engines = 4;
1724		adev->gfx.config.max_tile_pipes = 8;
1725		adev->gfx.config.max_cu_per_sh = 8;
1726		adev->gfx.config.max_sh_per_se = 1;
1727		adev->gfx.config.max_backends_per_se = 2;
1728		adev->gfx.config.max_texture_channel_caches = 8;
1729		adev->gfx.config.max_gprs = 256;
1730		adev->gfx.config.max_gs_threads = 32;
1731		adev->gfx.config.max_hw_contexts = 8;
1732
1733		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1734		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1735		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1736		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1737		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1738		break;
1739	case CHIP_CARRIZO:
1740		adev->gfx.config.max_shader_engines = 1;
1741		adev->gfx.config.max_tile_pipes = 2;
1742		adev->gfx.config.max_sh_per_se = 1;
1743		adev->gfx.config.max_backends_per_se = 2;
1744		adev->gfx.config.max_cu_per_sh = 8;
1745		adev->gfx.config.max_texture_channel_caches = 2;
1746		adev->gfx.config.max_gprs = 256;
1747		adev->gfx.config.max_gs_threads = 32;
1748		adev->gfx.config.max_hw_contexts = 8;
1749
1750		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1751		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1752		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1753		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1754		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
1755		break;
1756	case CHIP_STONEY:
1757		adev->gfx.config.max_shader_engines = 1;
1758		adev->gfx.config.max_tile_pipes = 2;
1759		adev->gfx.config.max_sh_per_se = 1;
1760		adev->gfx.config.max_backends_per_se = 1;
1761		adev->gfx.config.max_cu_per_sh = 3;
1762		adev->gfx.config.max_texture_channel_caches = 2;
1763		adev->gfx.config.max_gprs = 256;
1764		adev->gfx.config.max_gs_threads = 16;
1765		adev->gfx.config.max_hw_contexts = 8;
1766
1767		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1768		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1769		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1770		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1771		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
1772		break;
1773	default:
1774		adev->gfx.config.max_shader_engines = 2;
1775		adev->gfx.config.max_tile_pipes = 4;
1776		adev->gfx.config.max_cu_per_sh = 2;
1777		adev->gfx.config.max_sh_per_se = 1;
1778		adev->gfx.config.max_backends_per_se = 2;
1779		adev->gfx.config.max_texture_channel_caches = 4;
1780		adev->gfx.config.max_gprs = 256;
1781		adev->gfx.config.max_gs_threads = 32;
1782		adev->gfx.config.max_hw_contexts = 8;
1783
1784		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1785		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1786		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1787		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1788		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1789		break;
1790	}
1791
 
1792	adev->gfx.config.mc_arb_ramcfg = RREG32(mmMC_ARB_RAMCFG);
1793	mc_arb_ramcfg = adev->gfx.config.mc_arb_ramcfg;
1794
1795	adev->gfx.config.num_banks = REG_GET_FIELD(mc_arb_ramcfg,
1796				MC_ARB_RAMCFG, NOOFBANK);
1797	adev->gfx.config.num_ranks = REG_GET_FIELD(mc_arb_ramcfg,
1798				MC_ARB_RAMCFG, NOOFRANKS);
1799
1800	adev->gfx.config.num_tile_pipes = adev->gfx.config.max_tile_pipes;
1801	adev->gfx.config.mem_max_burst_length_bytes = 256;
1802	if (adev->flags & AMD_IS_APU) {
1803		/* Get memory bank mapping mode. */
1804		tmp = RREG32(mmMC_FUS_DRAM0_BANK_ADDR_MAPPING);
1805		dimm00_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
1806		dimm01_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
1807
1808		tmp = RREG32(mmMC_FUS_DRAM1_BANK_ADDR_MAPPING);
1809		dimm10_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
1810		dimm11_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
1811
1812		/* Validate settings in case only one DIMM installed. */
1813		if ((dimm00_addr_map == 0) || (dimm00_addr_map == 3) || (dimm00_addr_map == 4) || (dimm00_addr_map > 12))
1814			dimm00_addr_map = 0;
1815		if ((dimm01_addr_map == 0) || (dimm01_addr_map == 3) || (dimm01_addr_map == 4) || (dimm01_addr_map > 12))
1816			dimm01_addr_map = 0;
1817		if ((dimm10_addr_map == 0) || (dimm10_addr_map == 3) || (dimm10_addr_map == 4) || (dimm10_addr_map > 12))
1818			dimm10_addr_map = 0;
1819		if ((dimm11_addr_map == 0) || (dimm11_addr_map == 3) || (dimm11_addr_map == 4) || (dimm11_addr_map > 12))
1820			dimm11_addr_map = 0;
1821
1822		/* If DIMM Addr map is 8GB, ROW size should be 2KB. Otherwise 1KB. */
1823		/* If ROW size(DIMM1) != ROW size(DMIMM0), ROW size should be larger one. */
1824		if ((dimm00_addr_map == 11) || (dimm01_addr_map == 11) || (dimm10_addr_map == 11) || (dimm11_addr_map == 11))
1825			adev->gfx.config.mem_row_size_in_kb = 2;
1826		else
1827			adev->gfx.config.mem_row_size_in_kb = 1;
1828	} else {
1829		tmp = REG_GET_FIELD(mc_arb_ramcfg, MC_ARB_RAMCFG, NOOFCOLS);
1830		adev->gfx.config.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
1831		if (adev->gfx.config.mem_row_size_in_kb > 4)
1832			adev->gfx.config.mem_row_size_in_kb = 4;
1833	}
1834
1835	adev->gfx.config.shader_engine_tile_size = 32;
1836	adev->gfx.config.num_gpus = 1;
1837	adev->gfx.config.multi_gpu_tile_size = 64;
1838
1839	/* fix up row size */
1840	switch (adev->gfx.config.mem_row_size_in_kb) {
1841	case 1:
1842	default:
1843		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 0);
1844		break;
1845	case 2:
1846		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 1);
1847		break;
1848	case 4:
1849		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 2);
1850		break;
1851	}
1852	adev->gfx.config.gb_addr_config = gb_addr_config;
1853
1854	return 0;
1855}
1856
1857static int gfx_v8_0_compute_ring_init(struct amdgpu_device *adev, int ring_id,
1858					int mec, int pipe, int queue)
1859{
1860	int r;
1861	unsigned irq_type;
1862	struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
1863	unsigned int hw_prio;
1864
1865	ring = &adev->gfx.compute_ring[ring_id];
1866
1867	/* mec0 is me1 */
1868	ring->me = mec + 1;
1869	ring->pipe = pipe;
1870	ring->queue = queue;
1871
1872	ring->ring_obj = NULL;
1873	ring->use_doorbell = true;
1874	ring->doorbell_index = adev->doorbell_index.mec_ring0 + ring_id;
1875	ring->eop_gpu_addr = adev->gfx.mec.hpd_eop_gpu_addr
1876				+ (ring_id * GFX8_MEC_HPD_SIZE);
1877	sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
1878
1879	irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP
1880		+ ((ring->me - 1) * adev->gfx.mec.num_pipe_per_mec)
1881		+ ring->pipe;
1882
1883	hw_prio = amdgpu_gfx_is_high_priority_compute_queue(adev, ring) ?
1884			AMDGPU_RING_PRIO_2 : AMDGPU_RING_PRIO_DEFAULT;
1885	/* type-2 packets are deprecated on MEC, use type-3 instead */
1886	r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq, irq_type,
1887			     hw_prio, NULL);
1888	if (r)
1889		return r;
1890
1891
1892	return 0;
1893}
1894
1895static void gfx_v8_0_sq_irq_work_func(struct work_struct *work);
1896
1897static int gfx_v8_0_sw_init(struct amdgpu_ip_block *ip_block)
1898{
1899	int i, j, k, r, ring_id;
1900	int xcc_id = 0;
1901	struct amdgpu_ring *ring;
1902	struct amdgpu_device *adev = ip_block->adev;
 
1903
1904	switch (adev->asic_type) {
1905	case CHIP_TONGA:
1906	case CHIP_CARRIZO:
1907	case CHIP_FIJI:
1908	case CHIP_POLARIS10:
1909	case CHIP_POLARIS11:
1910	case CHIP_POLARIS12:
1911	case CHIP_VEGAM:
 
1912		adev->gfx.mec.num_mec = 2;
1913		break;
1914	case CHIP_TOPAZ:
1915	case CHIP_STONEY:
1916	default:
1917		adev->gfx.mec.num_mec = 1;
1918		break;
1919	}
1920
1921	adev->gfx.mec.num_pipe_per_mec = 4;
1922	adev->gfx.mec.num_queue_per_pipe = 8;
1923
 
 
 
 
 
1924	/* EOP Event */
1925	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_END_OF_PIPE, &adev->gfx.eop_irq);
1926	if (r)
1927		return r;
1928
1929	/* Privileged reg */
1930	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_PRIV_REG_FAULT,
1931			      &adev->gfx.priv_reg_irq);
1932	if (r)
1933		return r;
1934
1935	/* Privileged inst */
1936	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_PRIV_INSTR_FAULT,
1937			      &adev->gfx.priv_inst_irq);
1938	if (r)
1939		return r;
1940
1941	/* Add CP EDC/ECC irq  */
1942	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_CP_ECC_ERROR,
1943			      &adev->gfx.cp_ecc_error_irq);
1944	if (r)
1945		return r;
1946
1947	/* SQ interrupts. */
1948	r = amdgpu_irq_add_id(adev, AMDGPU_IRQ_CLIENTID_LEGACY, VISLANDS30_IV_SRCID_SQ_INTERRUPT_MSG,
1949			      &adev->gfx.sq_irq);
1950	if (r) {
1951		DRM_ERROR("amdgpu_irq_add() for SQ failed: %d\n", r);
1952		return r;
1953	}
1954
1955	INIT_WORK(&adev->gfx.sq_work.work, gfx_v8_0_sq_irq_work_func);
1956
1957	adev->gfx.gfx_current_status = AMDGPU_GFX_NORMAL_MODE;
1958
 
 
1959	r = gfx_v8_0_init_microcode(adev);
1960	if (r) {
1961		DRM_ERROR("Failed to load gfx firmware!\n");
1962		return r;
1963	}
1964
1965	r = adev->gfx.rlc.funcs->init(adev);
1966	if (r) {
1967		DRM_ERROR("Failed to init rlc BOs!\n");
1968		return r;
1969	}
1970
1971	r = gfx_v8_0_mec_init(adev);
1972	if (r) {
1973		DRM_ERROR("Failed to init MEC BOs!\n");
1974		return r;
1975	}
1976
1977	/* set up the gfx ring */
1978	for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
1979		ring = &adev->gfx.gfx_ring[i];
1980		ring->ring_obj = NULL;
1981		sprintf(ring->name, "gfx");
1982		/* no gfx doorbells on iceland */
1983		if (adev->asic_type != CHIP_TOPAZ) {
1984			ring->use_doorbell = true;
1985			ring->doorbell_index = adev->doorbell_index.gfx_ring0;
1986		}
1987
1988		r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq,
1989				     AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP,
1990				     AMDGPU_RING_PRIO_DEFAULT, NULL);
1991		if (r)
1992			return r;
1993	}
1994
1995
1996	/* set up the compute queues - allocate horizontally across pipes */
1997	ring_id = 0;
1998	for (i = 0; i < adev->gfx.mec.num_mec; ++i) {
1999		for (j = 0; j < adev->gfx.mec.num_queue_per_pipe; j++) {
2000			for (k = 0; k < adev->gfx.mec.num_pipe_per_mec; k++) {
2001				if (!amdgpu_gfx_is_mec_queue_enabled(adev, 0, i,
2002								     k, j))
2003					continue;
2004
2005				r = gfx_v8_0_compute_ring_init(adev,
2006								ring_id,
2007								i, k, j);
2008				if (r)
2009					return r;
2010
2011				ring_id++;
2012			}
2013		}
2014	}
2015
2016	r = amdgpu_gfx_kiq_init(adev, GFX8_MEC_HPD_SIZE, 0);
2017	if (r) {
2018		DRM_ERROR("Failed to init KIQ BOs!\n");
2019		return r;
2020	}
2021
2022	r = amdgpu_gfx_kiq_init_ring(adev, xcc_id);
 
2023	if (r)
2024		return r;
2025
2026	/* create MQD for all compute queues as well as KIQ for SRIOV case */
2027	r = amdgpu_gfx_mqd_sw_init(adev, sizeof(struct vi_mqd_allocation), 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2028	if (r)
2029		return r;
2030
2031	adev->gfx.ce_ram_size = 0x8000;
2032
2033	r = gfx_v8_0_gpu_early_init(adev);
2034	if (r)
2035		return r;
2036
2037	return 0;
2038}
2039
2040static int gfx_v8_0_sw_fini(struct amdgpu_ip_block *ip_block)
2041{
2042	struct amdgpu_device *adev = ip_block->adev;
2043	int i;
 
 
 
 
 
2044
2045	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
2046		amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
2047	for (i = 0; i < adev->gfx.num_compute_rings; i++)
2048		amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
2049
2050	amdgpu_gfx_mqd_sw_fini(adev, 0);
2051	amdgpu_gfx_kiq_free_ring(&adev->gfx.kiq[0].ring);
2052	amdgpu_gfx_kiq_fini(adev, 0);
2053
2054	gfx_v8_0_mec_fini(adev);
2055	amdgpu_gfx_rlc_fini(adev);
2056	amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj,
2057				&adev->gfx.rlc.clear_state_gpu_addr,
2058				(void **)&adev->gfx.rlc.cs_ptr);
2059	if ((adev->asic_type == CHIP_CARRIZO) ||
2060	    (adev->asic_type == CHIP_STONEY)) {
2061		amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj,
2062				&adev->gfx.rlc.cp_table_gpu_addr,
2063				(void **)&adev->gfx.rlc.cp_table_ptr);
2064	}
2065	gfx_v8_0_free_microcode(adev);
2066
2067	return 0;
2068}
2069
2070static void gfx_v8_0_tiling_mode_table_init(struct amdgpu_device *adev)
2071{
2072	uint32_t *modearray, *mod2array;
2073	const u32 num_tile_mode_states = ARRAY_SIZE(adev->gfx.config.tile_mode_array);
2074	const u32 num_secondary_tile_mode_states = ARRAY_SIZE(adev->gfx.config.macrotile_mode_array);
2075	u32 reg_offset;
2076
2077	modearray = adev->gfx.config.tile_mode_array;
2078	mod2array = adev->gfx.config.macrotile_mode_array;
2079
2080	for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2081		modearray[reg_offset] = 0;
2082
2083	for (reg_offset = 0; reg_offset <  num_secondary_tile_mode_states; reg_offset++)
2084		mod2array[reg_offset] = 0;
2085
2086	switch (adev->asic_type) {
2087	case CHIP_TOPAZ:
2088		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2089				PIPE_CONFIG(ADDR_SURF_P2) |
2090				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2091				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2092		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2093				PIPE_CONFIG(ADDR_SURF_P2) |
2094				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2095				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2096		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2097				PIPE_CONFIG(ADDR_SURF_P2) |
2098				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2099				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2100		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2101				PIPE_CONFIG(ADDR_SURF_P2) |
2102				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2103				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2104		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2105				PIPE_CONFIG(ADDR_SURF_P2) |
2106				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2107				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2108		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2109				PIPE_CONFIG(ADDR_SURF_P2) |
2110				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2111				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2112		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2113				PIPE_CONFIG(ADDR_SURF_P2) |
2114				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2115				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2116		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2117				PIPE_CONFIG(ADDR_SURF_P2));
2118		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2119				PIPE_CONFIG(ADDR_SURF_P2) |
2120				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2121				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2122		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2123				 PIPE_CONFIG(ADDR_SURF_P2) |
2124				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2125				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2126		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2127				 PIPE_CONFIG(ADDR_SURF_P2) |
2128				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2129				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2130		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2131				 PIPE_CONFIG(ADDR_SURF_P2) |
2132				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2133				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2134		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2135				 PIPE_CONFIG(ADDR_SURF_P2) |
2136				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2137				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2138		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2139				 PIPE_CONFIG(ADDR_SURF_P2) |
2140				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2141				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2142		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2143				 PIPE_CONFIG(ADDR_SURF_P2) |
2144				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2145				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2146		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2147				 PIPE_CONFIG(ADDR_SURF_P2) |
2148				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2149				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2150		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2151				 PIPE_CONFIG(ADDR_SURF_P2) |
2152				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2153				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2154		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2155				 PIPE_CONFIG(ADDR_SURF_P2) |
2156				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2157				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2158		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2159				 PIPE_CONFIG(ADDR_SURF_P2) |
2160				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2161				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2162		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2163				 PIPE_CONFIG(ADDR_SURF_P2) |
2164				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2165				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2166		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2167				 PIPE_CONFIG(ADDR_SURF_P2) |
2168				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2169				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2170		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2171				 PIPE_CONFIG(ADDR_SURF_P2) |
2172				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2173				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2174		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2175				 PIPE_CONFIG(ADDR_SURF_P2) |
2176				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2177				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2178		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2179				 PIPE_CONFIG(ADDR_SURF_P2) |
2180				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2181				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2182		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2183				 PIPE_CONFIG(ADDR_SURF_P2) |
2184				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2185				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2186		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2187				 PIPE_CONFIG(ADDR_SURF_P2) |
2188				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2189				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2190
2191		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2192				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2193				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2194				NUM_BANKS(ADDR_SURF_8_BANK));
2195		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2196				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2197				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2198				NUM_BANKS(ADDR_SURF_8_BANK));
2199		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2200				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2201				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2202				NUM_BANKS(ADDR_SURF_8_BANK));
2203		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2204				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2205				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2206				NUM_BANKS(ADDR_SURF_8_BANK));
2207		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2208				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2209				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2210				NUM_BANKS(ADDR_SURF_8_BANK));
2211		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2212				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2213				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2214				NUM_BANKS(ADDR_SURF_8_BANK));
2215		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2216				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2217				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2218				NUM_BANKS(ADDR_SURF_8_BANK));
2219		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2220				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2221				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2222				NUM_BANKS(ADDR_SURF_16_BANK));
2223		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2224				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2225				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2226				NUM_BANKS(ADDR_SURF_16_BANK));
2227		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2228				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2229				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2230				 NUM_BANKS(ADDR_SURF_16_BANK));
2231		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2232				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2233				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2234				 NUM_BANKS(ADDR_SURF_16_BANK));
2235		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2236				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2237				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2238				 NUM_BANKS(ADDR_SURF_16_BANK));
2239		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2240				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2241				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2242				 NUM_BANKS(ADDR_SURF_16_BANK));
2243		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2244				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2245				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2246				 NUM_BANKS(ADDR_SURF_8_BANK));
2247
2248		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2249			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
2250			    reg_offset != 23)
2251				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2252
2253		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2254			if (reg_offset != 7)
2255				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2256
2257		break;
2258	case CHIP_FIJI:
2259	case CHIP_VEGAM:
2260		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2261				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2262				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2263				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2264		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2265				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2266				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2267				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2268		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2269				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2270				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2271				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2272		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2273				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2274				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2275				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2276		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2277				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2278				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2279				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2280		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2281				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2282				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2283				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2284		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2285				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2286				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2287				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2288		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2289				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2290				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2291				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2292		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2293				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
2294		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2295				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2296				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2297				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2298		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2299				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2300				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2301				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2302		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2303				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2304				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2305				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2306		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2307				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2308				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2309				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2310		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2311				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2312				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2313				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2314		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2315				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2316				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2317				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2318		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2319				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2320				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2321				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2322		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2323				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2324				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2325				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2326		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2327				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2328				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2329				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2330		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2331				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2332				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2333				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2334		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2335				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2336				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2337				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2338		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2339				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2340				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2341				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2342		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2343				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2344				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2345				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2346		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2347				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2348				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2349				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2350		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2351				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2352				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2353				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2354		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2355				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2356				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2357				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2358		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2359				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2360				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2361				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2362		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2363				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2364				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2365				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2366		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2367				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2368				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2369				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2370		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2371				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2372				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2373				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2374		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2375				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2376				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2377				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2378		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2379				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2380				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2381				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2382
2383		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2384				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2385				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2386				NUM_BANKS(ADDR_SURF_8_BANK));
2387		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2388				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2389				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2390				NUM_BANKS(ADDR_SURF_8_BANK));
2391		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2392				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2393				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2394				NUM_BANKS(ADDR_SURF_8_BANK));
2395		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2396				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2397				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2398				NUM_BANKS(ADDR_SURF_8_BANK));
2399		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2400				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2401				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2402				NUM_BANKS(ADDR_SURF_8_BANK));
2403		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2404				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2405				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2406				NUM_BANKS(ADDR_SURF_8_BANK));
2407		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2408				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2409				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2410				NUM_BANKS(ADDR_SURF_8_BANK));
2411		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2412				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2413				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2414				NUM_BANKS(ADDR_SURF_8_BANK));
2415		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2416				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2417				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2418				NUM_BANKS(ADDR_SURF_8_BANK));
2419		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2420				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2421				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2422				 NUM_BANKS(ADDR_SURF_8_BANK));
2423		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2424				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2425				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2426				 NUM_BANKS(ADDR_SURF_8_BANK));
2427		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2428				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2429				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2430				 NUM_BANKS(ADDR_SURF_8_BANK));
2431		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2432				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2433				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2434				 NUM_BANKS(ADDR_SURF_8_BANK));
2435		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2436				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2437				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2438				 NUM_BANKS(ADDR_SURF_4_BANK));
2439
2440		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2441			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2442
2443		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2444			if (reg_offset != 7)
2445				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2446
2447		break;
2448	case CHIP_TONGA:
2449		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2450				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2451				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2452				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2453		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2454				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2455				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2456				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2457		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2458				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2459				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2460				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2461		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2462				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2463				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2464				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2465		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2466				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2467				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2468				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2469		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2470				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2471				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2472				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2473		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2474				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2475				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2476				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2477		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2478				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2479				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2480				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2481		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2482				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2483		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2484				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2485				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2486				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2487		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2488				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2489				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2490				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2491		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2492				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2493				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2494				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2495		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2496				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2497				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2498				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2499		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2500				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2501				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2502				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2503		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2504				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2505				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2506				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2507		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2508				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2509				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2510				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2511		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2512				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2513				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2514				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2515		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2516				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2517				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2518				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2519		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2520				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2521				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2522				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2523		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2524				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2525				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2526				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2527		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2528				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2529				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2530				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2531		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2532				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2533				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2534				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2535		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2536				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2537				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2538				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2539		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2540				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2541				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2542				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2543		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2544				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2545				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2546				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2547		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2548				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2549				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2550				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2551		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2552				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2553				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2554				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2555		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2556				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2557				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2558				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2559		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2560				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2561				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2562				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2563		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2564				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2565				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2566				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2567		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2568				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2569				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2570				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2571
2572		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2573				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2574				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2575				NUM_BANKS(ADDR_SURF_16_BANK));
2576		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2577				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2578				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2579				NUM_BANKS(ADDR_SURF_16_BANK));
2580		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2581				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2582				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2583				NUM_BANKS(ADDR_SURF_16_BANK));
2584		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2585				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2586				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2587				NUM_BANKS(ADDR_SURF_16_BANK));
2588		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2589				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2590				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2591				NUM_BANKS(ADDR_SURF_16_BANK));
2592		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2593				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2594				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2595				NUM_BANKS(ADDR_SURF_16_BANK));
2596		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2597				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2598				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2599				NUM_BANKS(ADDR_SURF_16_BANK));
2600		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2601				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2602				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2603				NUM_BANKS(ADDR_SURF_16_BANK));
2604		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2605				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2606				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2607				NUM_BANKS(ADDR_SURF_16_BANK));
2608		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2609				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2610				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2611				 NUM_BANKS(ADDR_SURF_16_BANK));
2612		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2613				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2614				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2615				 NUM_BANKS(ADDR_SURF_16_BANK));
2616		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2617				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2618				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2619				 NUM_BANKS(ADDR_SURF_8_BANK));
2620		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2621				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2622				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2623				 NUM_BANKS(ADDR_SURF_4_BANK));
2624		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2625				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2626				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2627				 NUM_BANKS(ADDR_SURF_4_BANK));
2628
2629		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2630			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2631
2632		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2633			if (reg_offset != 7)
2634				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2635
2636		break;
2637	case CHIP_POLARIS11:
2638	case CHIP_POLARIS12:
2639		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2640				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2641				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2642				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2643		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2644				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2645				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2646				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2647		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2648				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2649				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2650				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2651		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2652				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2653				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2654				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2655		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2656				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2657				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2658				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2659		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2660				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2661				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2662				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2663		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2664				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2665				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2666				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2667		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2668				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2669				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2670				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2671		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2672				PIPE_CONFIG(ADDR_SURF_P4_16x16));
2673		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2674				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2675				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2676				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2677		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2678				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2679				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2680				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2681		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2682				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2683				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2684				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2685		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2686				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2687				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2688				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2689		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2690				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2691				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2692				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2693		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2694				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2695				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2696				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2697		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2698				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2699				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2700				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2701		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2702				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2703				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2704				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2705		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2706				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2707				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2708				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2709		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2710				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2711				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2712				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2713		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2714				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2715				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2716				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2717		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2718				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2719				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2720				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2721		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2722				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2723				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2724				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2725		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2726				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2727				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2728				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2729		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2730				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2731				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2732				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2733		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2734				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2735				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2736				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2737		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2738				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2739				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2740				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2741		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2742				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2743				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2744				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2745		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2746				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2747				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2748				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2749		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2750				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2751				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2752				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2753		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2754				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2755				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2756				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2757		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2758				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2759				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2760				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2761
2762		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2763				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2764				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2765				NUM_BANKS(ADDR_SURF_16_BANK));
2766
2767		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2768				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2769				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2770				NUM_BANKS(ADDR_SURF_16_BANK));
2771
2772		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2773				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2774				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2775				NUM_BANKS(ADDR_SURF_16_BANK));
2776
2777		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2778				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2779				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2780				NUM_BANKS(ADDR_SURF_16_BANK));
2781
2782		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2783				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2784				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2785				NUM_BANKS(ADDR_SURF_16_BANK));
2786
2787		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2788				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2789				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2790				NUM_BANKS(ADDR_SURF_16_BANK));
2791
2792		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2793				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2794				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2795				NUM_BANKS(ADDR_SURF_16_BANK));
2796
2797		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2798				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2799				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2800				NUM_BANKS(ADDR_SURF_16_BANK));
2801
2802		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2803				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2804				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2805				NUM_BANKS(ADDR_SURF_16_BANK));
2806
2807		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2808				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2809				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2810				NUM_BANKS(ADDR_SURF_16_BANK));
2811
2812		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2813				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2814				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2815				NUM_BANKS(ADDR_SURF_16_BANK));
2816
2817		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2818				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2819				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2820				NUM_BANKS(ADDR_SURF_16_BANK));
2821
2822		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2823				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2824				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2825				NUM_BANKS(ADDR_SURF_8_BANK));
2826
2827		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2828				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2829				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2830				NUM_BANKS(ADDR_SURF_4_BANK));
2831
2832		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2833			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2834
2835		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2836			if (reg_offset != 7)
2837				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2838
2839		break;
2840	case CHIP_POLARIS10:
2841		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2842				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2843				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2844				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2845		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2846				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2847				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2848				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2849		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2850				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2851				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2852				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2853		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2854				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2855				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2856				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2857		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2858				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2859				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2860				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2861		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2862				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2863				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2864				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2865		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2866				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2867				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2868				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2869		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2870				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2871				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2872				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2873		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2874				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2875		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2876				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2877				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2878				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2879		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2880				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2881				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2882				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2883		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2884				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2885				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2886				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2887		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2888				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2889				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2890				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2891		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2892				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2893				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2894				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2895		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2896				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2897				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2898				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2899		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2900				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2901				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2902				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2903		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2904				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2905				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2906				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2907		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2908				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2909				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2910				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2911		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2912				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2913				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2914				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2915		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2916				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2917				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2918				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2919		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2920				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2921				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2922				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2923		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2924				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2925				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2926				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2927		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2928				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2929				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2930				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2931		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2932				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2933				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2934				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2935		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2936				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2937				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2938				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2939		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2940				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2941				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2942				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2943		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2944				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2945				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2946				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2947		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2948				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2949				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2950				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2951		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2952				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2953				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2954				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2955		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2956				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2957				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2958				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2959		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2960				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2961				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2962				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2963
2964		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2965				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2966				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2967				NUM_BANKS(ADDR_SURF_16_BANK));
2968
2969		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2970				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2971				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2972				NUM_BANKS(ADDR_SURF_16_BANK));
2973
2974		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2975				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2976				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2977				NUM_BANKS(ADDR_SURF_16_BANK));
2978
2979		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2980				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2981				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2982				NUM_BANKS(ADDR_SURF_16_BANK));
2983
2984		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2985				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2986				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2987				NUM_BANKS(ADDR_SURF_16_BANK));
2988
2989		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2990				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2991				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2992				NUM_BANKS(ADDR_SURF_16_BANK));
2993
2994		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2995				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2996				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2997				NUM_BANKS(ADDR_SURF_16_BANK));
2998
2999		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3000				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3001				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3002				NUM_BANKS(ADDR_SURF_16_BANK));
3003
3004		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3005				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3006				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3007				NUM_BANKS(ADDR_SURF_16_BANK));
3008
3009		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3010				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3011				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3012				NUM_BANKS(ADDR_SURF_16_BANK));
3013
3014		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3015				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3016				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3017				NUM_BANKS(ADDR_SURF_16_BANK));
3018
3019		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3020				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3021				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3022				NUM_BANKS(ADDR_SURF_8_BANK));
3023
3024		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3025				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3026				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3027				NUM_BANKS(ADDR_SURF_4_BANK));
3028
3029		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3030				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3031				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3032				NUM_BANKS(ADDR_SURF_4_BANK));
3033
3034		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3035			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3036
3037		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3038			if (reg_offset != 7)
3039				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3040
3041		break;
3042	case CHIP_STONEY:
3043		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3044				PIPE_CONFIG(ADDR_SURF_P2) |
3045				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3046				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3047		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3048				PIPE_CONFIG(ADDR_SURF_P2) |
3049				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3050				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3051		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3052				PIPE_CONFIG(ADDR_SURF_P2) |
3053				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3054				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3055		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3056				PIPE_CONFIG(ADDR_SURF_P2) |
3057				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3058				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3059		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3060				PIPE_CONFIG(ADDR_SURF_P2) |
3061				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3062				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3063		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3064				PIPE_CONFIG(ADDR_SURF_P2) |
3065				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3066				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3067		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3068				PIPE_CONFIG(ADDR_SURF_P2) |
3069				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3070				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3071		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3072				PIPE_CONFIG(ADDR_SURF_P2));
3073		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3074				PIPE_CONFIG(ADDR_SURF_P2) |
3075				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3076				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3077		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3078				 PIPE_CONFIG(ADDR_SURF_P2) |
3079				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3080				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3081		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3082				 PIPE_CONFIG(ADDR_SURF_P2) |
3083				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3084				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3085		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3086				 PIPE_CONFIG(ADDR_SURF_P2) |
3087				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3088				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3089		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3090				 PIPE_CONFIG(ADDR_SURF_P2) |
3091				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3092				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3093		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3094				 PIPE_CONFIG(ADDR_SURF_P2) |
3095				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3096				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3097		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3098				 PIPE_CONFIG(ADDR_SURF_P2) |
3099				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3100				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3101		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3102				 PIPE_CONFIG(ADDR_SURF_P2) |
3103				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3104				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3105		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3106				 PIPE_CONFIG(ADDR_SURF_P2) |
3107				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3108				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3109		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3110				 PIPE_CONFIG(ADDR_SURF_P2) |
3111				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3112				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3113		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3114				 PIPE_CONFIG(ADDR_SURF_P2) |
3115				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3116				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3117		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3118				 PIPE_CONFIG(ADDR_SURF_P2) |
3119				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3120				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3121		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3122				 PIPE_CONFIG(ADDR_SURF_P2) |
3123				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3124				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3125		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3126				 PIPE_CONFIG(ADDR_SURF_P2) |
3127				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3128				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3129		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3130				 PIPE_CONFIG(ADDR_SURF_P2) |
3131				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3132				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3133		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3134				 PIPE_CONFIG(ADDR_SURF_P2) |
3135				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3136				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3137		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3138				 PIPE_CONFIG(ADDR_SURF_P2) |
3139				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3140				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3141		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3142				 PIPE_CONFIG(ADDR_SURF_P2) |
3143				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3144				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3145
3146		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3147				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3148				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3149				NUM_BANKS(ADDR_SURF_8_BANK));
3150		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3151				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3152				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3153				NUM_BANKS(ADDR_SURF_8_BANK));
3154		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3155				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3156				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3157				NUM_BANKS(ADDR_SURF_8_BANK));
3158		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3159				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3160				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3161				NUM_BANKS(ADDR_SURF_8_BANK));
3162		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3163				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3164				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3165				NUM_BANKS(ADDR_SURF_8_BANK));
3166		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3167				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3168				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3169				NUM_BANKS(ADDR_SURF_8_BANK));
3170		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3171				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3172				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3173				NUM_BANKS(ADDR_SURF_8_BANK));
3174		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3175				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3176				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3177				NUM_BANKS(ADDR_SURF_16_BANK));
3178		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3179				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3180				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3181				NUM_BANKS(ADDR_SURF_16_BANK));
3182		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3183				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3184				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3185				 NUM_BANKS(ADDR_SURF_16_BANK));
3186		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3187				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3188				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3189				 NUM_BANKS(ADDR_SURF_16_BANK));
3190		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3191				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3192				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3193				 NUM_BANKS(ADDR_SURF_16_BANK));
3194		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3195				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3196				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3197				 NUM_BANKS(ADDR_SURF_16_BANK));
3198		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3199				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3200				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3201				 NUM_BANKS(ADDR_SURF_8_BANK));
3202
3203		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3204			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
3205			    reg_offset != 23)
3206				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3207
3208		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3209			if (reg_offset != 7)
3210				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3211
3212		break;
3213	default:
3214		dev_warn(adev->dev,
3215			 "Unknown chip type (%d) in function gfx_v8_0_tiling_mode_table_init() falling through to CHIP_CARRIZO\n",
3216			 adev->asic_type);
3217		fallthrough;
3218
3219	case CHIP_CARRIZO:
3220		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3221				PIPE_CONFIG(ADDR_SURF_P2) |
3222				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3223				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3224		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3225				PIPE_CONFIG(ADDR_SURF_P2) |
3226				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3227				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3228		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3229				PIPE_CONFIG(ADDR_SURF_P2) |
3230				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3231				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3232		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3233				PIPE_CONFIG(ADDR_SURF_P2) |
3234				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3235				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3236		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3237				PIPE_CONFIG(ADDR_SURF_P2) |
3238				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3239				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3240		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3241				PIPE_CONFIG(ADDR_SURF_P2) |
3242				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3243				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3244		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3245				PIPE_CONFIG(ADDR_SURF_P2) |
3246				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3247				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3248		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3249				PIPE_CONFIG(ADDR_SURF_P2));
3250		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3251				PIPE_CONFIG(ADDR_SURF_P2) |
3252				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3253				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3254		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3255				 PIPE_CONFIG(ADDR_SURF_P2) |
3256				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3257				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3258		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3259				 PIPE_CONFIG(ADDR_SURF_P2) |
3260				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3261				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3262		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3263				 PIPE_CONFIG(ADDR_SURF_P2) |
3264				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3265				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3266		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3267				 PIPE_CONFIG(ADDR_SURF_P2) |
3268				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3269				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3270		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3271				 PIPE_CONFIG(ADDR_SURF_P2) |
3272				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3273				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3274		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3275				 PIPE_CONFIG(ADDR_SURF_P2) |
3276				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3277				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3278		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3279				 PIPE_CONFIG(ADDR_SURF_P2) |
3280				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3281				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3282		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3283				 PIPE_CONFIG(ADDR_SURF_P2) |
3284				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3285				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3286		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3287				 PIPE_CONFIG(ADDR_SURF_P2) |
3288				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3289				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3290		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3291				 PIPE_CONFIG(ADDR_SURF_P2) |
3292				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3293				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3294		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3295				 PIPE_CONFIG(ADDR_SURF_P2) |
3296				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3297				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3298		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3299				 PIPE_CONFIG(ADDR_SURF_P2) |
3300				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3301				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3302		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3303				 PIPE_CONFIG(ADDR_SURF_P2) |
3304				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3305				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3306		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3307				 PIPE_CONFIG(ADDR_SURF_P2) |
3308				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3309				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3310		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3311				 PIPE_CONFIG(ADDR_SURF_P2) |
3312				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3313				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3314		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3315				 PIPE_CONFIG(ADDR_SURF_P2) |
3316				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3317				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3318		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3319				 PIPE_CONFIG(ADDR_SURF_P2) |
3320				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3321				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3322
3323		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3324				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3325				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3326				NUM_BANKS(ADDR_SURF_8_BANK));
3327		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3328				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3329				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3330				NUM_BANKS(ADDR_SURF_8_BANK));
3331		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3332				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3333				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3334				NUM_BANKS(ADDR_SURF_8_BANK));
3335		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3336				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3337				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3338				NUM_BANKS(ADDR_SURF_8_BANK));
3339		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3340				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3341				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3342				NUM_BANKS(ADDR_SURF_8_BANK));
3343		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3344				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3345				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3346				NUM_BANKS(ADDR_SURF_8_BANK));
3347		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3348				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3349				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3350				NUM_BANKS(ADDR_SURF_8_BANK));
3351		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3352				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3353				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3354				NUM_BANKS(ADDR_SURF_16_BANK));
3355		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3356				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3357				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3358				NUM_BANKS(ADDR_SURF_16_BANK));
3359		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3360				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3361				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3362				 NUM_BANKS(ADDR_SURF_16_BANK));
3363		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3364				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3365				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3366				 NUM_BANKS(ADDR_SURF_16_BANK));
3367		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3368				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3369				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3370				 NUM_BANKS(ADDR_SURF_16_BANK));
3371		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3372				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3373				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3374				 NUM_BANKS(ADDR_SURF_16_BANK));
3375		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3376				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3377				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3378				 NUM_BANKS(ADDR_SURF_8_BANK));
3379
3380		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3381			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
3382			    reg_offset != 23)
3383				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3384
3385		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3386			if (reg_offset != 7)
3387				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3388
3389		break;
3390	}
3391}
3392
3393static void gfx_v8_0_select_se_sh(struct amdgpu_device *adev,
3394				  u32 se_num, u32 sh_num, u32 instance,
3395				  int xcc_id)
3396{
3397	u32 data;
3398
3399	if (instance == 0xffffffff)
3400		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES, 1);
3401	else
3402		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
3403
3404	if (se_num == 0xffffffff)
3405		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
3406	else
3407		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
3408
3409	if (sh_num == 0xffffffff)
3410		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
3411	else
3412		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
3413
3414	WREG32(mmGRBM_GFX_INDEX, data);
3415}
3416
3417static void gfx_v8_0_select_me_pipe_q(struct amdgpu_device *adev,
3418				  u32 me, u32 pipe, u32 q, u32 vm, u32 xcc_id)
3419{
3420	vi_srbm_select(adev, me, pipe, q, vm);
3421}
3422
3423static u32 gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device *adev)
3424{
3425	u32 data, mask;
3426
3427	data =  RREG32(mmCC_RB_BACKEND_DISABLE) |
3428		RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3429
3430	data = REG_GET_FIELD(data, GC_USER_RB_BACKEND_DISABLE, BACKEND_DISABLE);
3431
3432	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_backends_per_se /
3433					 adev->gfx.config.max_sh_per_se);
3434
3435	return (~data) & mask;
3436}
3437
3438static void
3439gfx_v8_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
3440{
3441	switch (adev->asic_type) {
3442	case CHIP_FIJI:
3443	case CHIP_VEGAM:
3444		*rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
3445			  RB_XSEL2(1) | PKR_MAP(2) |
3446			  PKR_XSEL(1) | PKR_YSEL(1) |
3447			  SE_MAP(2) | SE_XSEL(2) | SE_YSEL(3);
3448		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
3449			   SE_PAIR_YSEL(2);
3450		break;
3451	case CHIP_TONGA:
3452	case CHIP_POLARIS10:
3453		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3454			  SE_XSEL(1) | SE_YSEL(1);
3455		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(2) |
3456			   SE_PAIR_YSEL(2);
3457		break;
3458	case CHIP_TOPAZ:
3459	case CHIP_CARRIZO:
3460		*rconf |= RB_MAP_PKR0(2);
3461		*rconf1 |= 0x0;
3462		break;
3463	case CHIP_POLARIS11:
3464	case CHIP_POLARIS12:
3465		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3466			  SE_XSEL(1) | SE_YSEL(1);
3467		*rconf1 |= 0x0;
3468		break;
3469	case CHIP_STONEY:
3470		*rconf |= 0x0;
3471		*rconf1 |= 0x0;
3472		break;
3473	default:
3474		DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
3475		break;
3476	}
3477}
3478
3479static void
3480gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device *adev,
3481					u32 raster_config, u32 raster_config_1,
3482					unsigned rb_mask, unsigned num_rb)
3483{
3484	unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
3485	unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
3486	unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
3487	unsigned rb_per_se = num_rb / num_se;
3488	unsigned se_mask[4];
3489	unsigned se;
3490
3491	se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
3492	se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
3493	se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
3494	se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
3495
3496	WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
3497	WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
3498	WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
3499
3500	if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
3501			     (!se_mask[2] && !se_mask[3]))) {
3502		raster_config_1 &= ~SE_PAIR_MAP_MASK;
3503
3504		if (!se_mask[0] && !se_mask[1]) {
3505			raster_config_1 |=
3506				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
3507		} else {
3508			raster_config_1 |=
3509				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
3510		}
3511	}
3512
3513	for (se = 0; se < num_se; se++) {
3514		unsigned raster_config_se = raster_config;
3515		unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
3516		unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
3517		int idx = (se / 2) * 2;
3518
3519		if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
3520			raster_config_se &= ~SE_MAP_MASK;
3521
3522			if (!se_mask[idx]) {
3523				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
3524			} else {
3525				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
3526			}
3527		}
3528
3529		pkr0_mask &= rb_mask;
3530		pkr1_mask &= rb_mask;
3531		if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
3532			raster_config_se &= ~PKR_MAP_MASK;
3533
3534			if (!pkr0_mask) {
3535				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
3536			} else {
3537				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
3538			}
3539		}
3540
3541		if (rb_per_se >= 2) {
3542			unsigned rb0_mask = 1 << (se * rb_per_se);
3543			unsigned rb1_mask = rb0_mask << 1;
3544
3545			rb0_mask &= rb_mask;
3546			rb1_mask &= rb_mask;
3547			if (!rb0_mask || !rb1_mask) {
3548				raster_config_se &= ~RB_MAP_PKR0_MASK;
3549
3550				if (!rb0_mask) {
3551					raster_config_se |=
3552						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
3553				} else {
3554					raster_config_se |=
3555						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
3556				}
3557			}
3558
3559			if (rb_per_se > 2) {
3560				rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
3561				rb1_mask = rb0_mask << 1;
3562				rb0_mask &= rb_mask;
3563				rb1_mask &= rb_mask;
3564				if (!rb0_mask || !rb1_mask) {
3565					raster_config_se &= ~RB_MAP_PKR1_MASK;
3566
3567					if (!rb0_mask) {
3568						raster_config_se |=
3569							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
3570					} else {
3571						raster_config_se |=
3572							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
3573					}
3574				}
3575			}
3576		}
3577
3578		/* GRBM_GFX_INDEX has a different offset on VI */
3579		gfx_v8_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff, 0);
3580		WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
3581		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3582	}
3583
3584	/* GRBM_GFX_INDEX has a different offset on VI */
3585	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3586}
3587
3588static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)
3589{
3590	int i, j;
3591	u32 data;
3592	u32 raster_config = 0, raster_config_1 = 0;
3593	u32 active_rbs = 0;
3594	u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
3595					adev->gfx.config.max_sh_per_se;
3596	unsigned num_rb_pipes;
3597
3598	mutex_lock(&adev->grbm_idx_mutex);
3599	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3600		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3601			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
3602			data = gfx_v8_0_get_rb_active_bitmap(adev);
3603			active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
3604					       rb_bitmap_width_per_sh);
3605		}
3606	}
3607	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3608
3609	adev->gfx.config.backend_enable_mask = active_rbs;
3610	adev->gfx.config.num_rbs = hweight32(active_rbs);
3611
3612	num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
3613			     adev->gfx.config.max_shader_engines, 16);
3614
3615	gfx_v8_0_raster_config(adev, &raster_config, &raster_config_1);
3616
3617	if (!adev->gfx.config.backend_enable_mask ||
3618			adev->gfx.config.num_rbs >= num_rb_pipes) {
3619		WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
3620		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3621	} else {
3622		gfx_v8_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
3623							adev->gfx.config.backend_enable_mask,
3624							num_rb_pipes);
3625	}
3626
3627	/* cache the values for userspace */
3628	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3629		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3630			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
3631			adev->gfx.config.rb_config[i][j].rb_backend_disable =
3632				RREG32(mmCC_RB_BACKEND_DISABLE);
3633			adev->gfx.config.rb_config[i][j].user_rb_backend_disable =
3634				RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3635			adev->gfx.config.rb_config[i][j].raster_config =
3636				RREG32(mmPA_SC_RASTER_CONFIG);
3637			adev->gfx.config.rb_config[i][j].raster_config_1 =
3638				RREG32(mmPA_SC_RASTER_CONFIG_1);
3639		}
3640	}
3641	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3642	mutex_unlock(&adev->grbm_idx_mutex);
3643}
3644
3645#define DEFAULT_SH_MEM_BASES	(0x6000)
3646/**
3647 * gfx_v8_0_init_compute_vmid - gart enable
3648 *
3649 * @adev: amdgpu_device pointer
3650 *
3651 * Initialize compute vmid sh_mem registers
3652 *
3653 */
 
 
 
3654static void gfx_v8_0_init_compute_vmid(struct amdgpu_device *adev)
3655{
3656	int i;
3657	uint32_t sh_mem_config;
3658	uint32_t sh_mem_bases;
3659
3660	/*
3661	 * Configure apertures:
3662	 * LDS:         0x60000000'00000000 - 0x60000001'00000000 (4GB)
3663	 * Scratch:     0x60000001'00000000 - 0x60000002'00000000 (4GB)
3664	 * GPUVM:       0x60010000'00000000 - 0x60020000'00000000 (1TB)
3665	 */
3666	sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16);
3667
3668	sh_mem_config = SH_MEM_ADDRESS_MODE_HSA64 <<
3669			SH_MEM_CONFIG__ADDRESS_MODE__SHIFT |
3670			SH_MEM_ALIGNMENT_MODE_UNALIGNED <<
3671			SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT |
3672			MTYPE_CC << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT |
3673			SH_MEM_CONFIG__PRIVATE_ATC_MASK;
3674
3675	mutex_lock(&adev->srbm_mutex);
3676	for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) {
3677		vi_srbm_select(adev, 0, 0, 0, i);
3678		/* CP and shaders */
3679		WREG32(mmSH_MEM_CONFIG, sh_mem_config);
3680		WREG32(mmSH_MEM_APE1_BASE, 1);
3681		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3682		WREG32(mmSH_MEM_BASES, sh_mem_bases);
3683	}
3684	vi_srbm_select(adev, 0, 0, 0, 0);
3685	mutex_unlock(&adev->srbm_mutex);
3686
3687	/* Initialize all compute VMIDs to have no GDS, GWS, or OA
3688	   access. These should be enabled by FW for target VMIDs. */
3689	for (i = adev->vm_manager.first_kfd_vmid; i < AMDGPU_NUM_VMID; i++) {
3690		WREG32(amdgpu_gds_reg_offset[i].mem_base, 0);
3691		WREG32(amdgpu_gds_reg_offset[i].mem_size, 0);
3692		WREG32(amdgpu_gds_reg_offset[i].gws, 0);
3693		WREG32(amdgpu_gds_reg_offset[i].oa, 0);
3694	}
3695}
3696
3697static void gfx_v8_0_init_gds_vmid(struct amdgpu_device *adev)
3698{
3699	int vmid;
3700
3701	/*
3702	 * Initialize all compute and user-gfx VMIDs to have no GDS, GWS, or OA
3703	 * access. Compute VMIDs should be enabled by FW for target VMIDs,
3704	 * the driver can enable them for graphics. VMID0 should maintain
3705	 * access so that HWS firmware can save/restore entries.
3706	 */
3707	for (vmid = 1; vmid < AMDGPU_NUM_VMID; vmid++) {
3708		WREG32(amdgpu_gds_reg_offset[vmid].mem_base, 0);
3709		WREG32(amdgpu_gds_reg_offset[vmid].mem_size, 0);
3710		WREG32(amdgpu_gds_reg_offset[vmid].gws, 0);
3711		WREG32(amdgpu_gds_reg_offset[vmid].oa, 0);
3712	}
3713}
3714
3715static void gfx_v8_0_config_init(struct amdgpu_device *adev)
3716{
3717	switch (adev->asic_type) {
3718	default:
3719		adev->gfx.config.double_offchip_lds_buf = 1;
3720		break;
3721	case CHIP_CARRIZO:
3722	case CHIP_STONEY:
3723		adev->gfx.config.double_offchip_lds_buf = 0;
3724		break;
3725	}
3726}
3727
3728static void gfx_v8_0_constants_init(struct amdgpu_device *adev)
3729{
3730	u32 tmp, sh_static_mem_cfg;
3731	int i;
3732
3733	WREG32_FIELD(GRBM_CNTL, READ_TIMEOUT, 0xFF);
3734	WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
3735	WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
3736	WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
3737
3738	gfx_v8_0_tiling_mode_table_init(adev);
3739	gfx_v8_0_setup_rb(adev);
3740	gfx_v8_0_get_cu_info(adev);
3741	gfx_v8_0_config_init(adev);
3742
3743	/* XXX SH_MEM regs */
3744	/* where to put LDS, scratch, GPUVM in FSA64 space */
3745	sh_static_mem_cfg = REG_SET_FIELD(0, SH_STATIC_MEM_CONFIG,
3746				   SWIZZLE_ENABLE, 1);
3747	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
3748				   ELEMENT_SIZE, 1);
3749	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
3750				   INDEX_STRIDE, 3);
3751	WREG32(mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg);
3752
3753	mutex_lock(&adev->srbm_mutex);
3754	for (i = 0; i < adev->vm_manager.id_mgr[0].num_ids; i++) {
3755		vi_srbm_select(adev, 0, 0, 0, i);
3756		/* CP and shaders */
3757		if (i == 0) {
3758			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_UC);
3759			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
3760			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
3761					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3762			WREG32(mmSH_MEM_CONFIG, tmp);
3763			WREG32(mmSH_MEM_BASES, 0);
3764		} else {
3765			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_NC);
3766			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
3767			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
3768					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3769			WREG32(mmSH_MEM_CONFIG, tmp);
3770			tmp = adev->gmc.shared_aperture_start >> 48;
3771			WREG32(mmSH_MEM_BASES, tmp);
3772		}
3773
3774		WREG32(mmSH_MEM_APE1_BASE, 1);
3775		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3776	}
3777	vi_srbm_select(adev, 0, 0, 0, 0);
3778	mutex_unlock(&adev->srbm_mutex);
3779
3780	gfx_v8_0_init_compute_vmid(adev);
3781	gfx_v8_0_init_gds_vmid(adev);
3782
3783	mutex_lock(&adev->grbm_idx_mutex);
3784	/*
3785	 * making sure that the following register writes will be broadcasted
3786	 * to all the shaders
3787	 */
3788	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3789
3790	WREG32(mmPA_SC_FIFO_SIZE,
3791		   (adev->gfx.config.sc_prim_fifo_size_frontend <<
3792			PA_SC_FIFO_SIZE__SC_FRONTEND_PRIM_FIFO_SIZE__SHIFT) |
3793		   (adev->gfx.config.sc_prim_fifo_size_backend <<
3794			PA_SC_FIFO_SIZE__SC_BACKEND_PRIM_FIFO_SIZE__SHIFT) |
3795		   (adev->gfx.config.sc_hiz_tile_fifo_size <<
3796			PA_SC_FIFO_SIZE__SC_HIZ_TILE_FIFO_SIZE__SHIFT) |
3797		   (adev->gfx.config.sc_earlyz_tile_fifo_size <<
3798			PA_SC_FIFO_SIZE__SC_EARLYZ_TILE_FIFO_SIZE__SHIFT));
3799
3800	tmp = RREG32(mmSPI_ARB_PRIORITY);
3801	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS0, 2);
3802	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS1, 2);
3803	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS2, 2);
3804	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS3, 2);
3805	WREG32(mmSPI_ARB_PRIORITY, tmp);
3806
3807	mutex_unlock(&adev->grbm_idx_mutex);
3808
3809}
3810
3811static void gfx_v8_0_wait_for_rlc_serdes(struct amdgpu_device *adev)
3812{
3813	u32 i, j, k;
3814	u32 mask;
3815
3816	mutex_lock(&adev->grbm_idx_mutex);
3817	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3818		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3819			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
3820			for (k = 0; k < adev->usec_timeout; k++) {
3821				if (RREG32(mmRLC_SERDES_CU_MASTER_BUSY) == 0)
3822					break;
3823				udelay(1);
3824			}
3825			if (k == adev->usec_timeout) {
3826				gfx_v8_0_select_se_sh(adev, 0xffffffff,
3827						      0xffffffff, 0xffffffff, 0);
3828				mutex_unlock(&adev->grbm_idx_mutex);
3829				DRM_INFO("Timeout wait for RLC serdes %u,%u\n",
3830					 i, j);
3831				return;
3832			}
3833		}
3834	}
3835	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
3836	mutex_unlock(&adev->grbm_idx_mutex);
3837
3838	mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
3839		RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
3840		RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
3841		RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
3842	for (k = 0; k < adev->usec_timeout; k++) {
3843		if ((RREG32(mmRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
3844			break;
3845		udelay(1);
3846	}
3847}
3848
3849static void gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
3850					       bool enable)
3851{
3852	u32 tmp = RREG32(mmCP_INT_CNTL_RING0);
3853
3854	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE, enable ? 1 : 0);
3855	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_EMPTY_INT_ENABLE, enable ? 1 : 0);
3856	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CMP_BUSY_INT_ENABLE, enable ? 1 : 0);
3857	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, GFX_IDLE_INT_ENABLE, enable ? 1 : 0);
3858
3859	WREG32(mmCP_INT_CNTL_RING0, tmp);
3860}
3861
3862static void gfx_v8_0_init_csb(struct amdgpu_device *adev)
3863{
3864	adev->gfx.rlc.funcs->get_csb_buffer(adev, adev->gfx.rlc.cs_ptr);
3865	/* csib */
3866	WREG32(mmRLC_CSIB_ADDR_HI,
3867			adev->gfx.rlc.clear_state_gpu_addr >> 32);
3868	WREG32(mmRLC_CSIB_ADDR_LO,
3869			adev->gfx.rlc.clear_state_gpu_addr & 0xfffffffc);
3870	WREG32(mmRLC_CSIB_LENGTH,
3871			adev->gfx.rlc.clear_state_size);
3872}
3873
3874static void gfx_v8_0_parse_ind_reg_list(int *register_list_format,
3875				int ind_offset,
3876				int list_size,
3877				int *unique_indices,
3878				int *indices_count,
3879				int max_indices,
3880				int *ind_start_offsets,
3881				int *offset_count,
3882				int max_offset)
3883{
3884	int indices;
3885	bool new_entry = true;
3886
3887	for (; ind_offset < list_size; ind_offset++) {
3888
3889		if (new_entry) {
3890			new_entry = false;
3891			ind_start_offsets[*offset_count] = ind_offset;
3892			*offset_count = *offset_count + 1;
3893			BUG_ON(*offset_count >= max_offset);
3894		}
3895
3896		if (register_list_format[ind_offset] == 0xFFFFFFFF) {
3897			new_entry = true;
3898			continue;
3899		}
3900
3901		ind_offset += 2;
3902
3903		/* look for the matching indice */
3904		for (indices = 0;
3905			indices < *indices_count;
3906			indices++) {
3907			if (unique_indices[indices] ==
3908				register_list_format[ind_offset])
3909				break;
3910		}
3911
3912		if (indices >= *indices_count) {
3913			unique_indices[*indices_count] =
3914				register_list_format[ind_offset];
3915			indices = *indices_count;
3916			*indices_count = *indices_count + 1;
3917			BUG_ON(*indices_count >= max_indices);
3918		}
3919
3920		register_list_format[ind_offset] = indices;
3921	}
3922}
3923
3924static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
3925{
3926	int i, temp, data;
3927	int unique_indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
3928	int indices_count = 0;
3929	int indirect_start_offsets[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3930	int offset_count = 0;
3931
3932	int list_size;
3933	unsigned int *register_list_format =
3934		kmemdup(adev->gfx.rlc.register_list_format,
3935			adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
3936	if (!register_list_format)
3937		return -ENOMEM;
 
 
3938
3939	gfx_v8_0_parse_ind_reg_list(register_list_format,
3940				RLC_FormatDirectRegListLength,
3941				adev->gfx.rlc.reg_list_format_size_bytes >> 2,
3942				unique_indices,
3943				&indices_count,
3944				ARRAY_SIZE(unique_indices),
3945				indirect_start_offsets,
3946				&offset_count,
3947				ARRAY_SIZE(indirect_start_offsets));
3948
3949	/* save and restore list */
3950	WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
3951
3952	WREG32(mmRLC_SRM_ARAM_ADDR, 0);
3953	for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
3954		WREG32(mmRLC_SRM_ARAM_DATA, adev->gfx.rlc.register_restore[i]);
3955
3956	/* indirect list */
3957	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_list_format_start);
3958	for (i = 0; i < adev->gfx.rlc.reg_list_format_size_bytes >> 2; i++)
3959		WREG32(mmRLC_GPM_SCRATCH_DATA, register_list_format[i]);
3960
3961	list_size = adev->gfx.rlc.reg_list_size_bytes >> 2;
3962	list_size = list_size >> 1;
3963	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_restore_list_size);
3964	WREG32(mmRLC_GPM_SCRATCH_DATA, list_size);
3965
3966	/* starting offsets starts */
3967	WREG32(mmRLC_GPM_SCRATCH_ADDR,
3968		adev->gfx.rlc.starting_offsets_start);
3969	for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
3970		WREG32(mmRLC_GPM_SCRATCH_DATA,
3971				indirect_start_offsets[i]);
3972
3973	/* unique indices */
3974	temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
3975	data = mmRLC_SRM_INDEX_CNTL_DATA_0;
3976	for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
3977		if (unique_indices[i] != 0) {
3978			WREG32(temp + i, unique_indices[i] & 0x3FFFF);
3979			WREG32(data + i, unique_indices[i] >> 20);
3980		}
3981	}
3982	kfree(register_list_format);
3983
3984	return 0;
3985}
3986
3987static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
3988{
3989	WREG32_FIELD(RLC_SRM_CNTL, SRM_ENABLE, 1);
3990}
3991
3992static void gfx_v8_0_init_power_gating(struct amdgpu_device *adev)
3993{
3994	uint32_t data;
3995
3996	WREG32_FIELD(CP_RB_WPTR_POLL_CNTL, IDLE_POLL_COUNT, 0x60);
3997
3998	data = REG_SET_FIELD(0, RLC_PG_DELAY, POWER_UP_DELAY, 0x10);
3999	data = REG_SET_FIELD(data, RLC_PG_DELAY, POWER_DOWN_DELAY, 0x10);
4000	data = REG_SET_FIELD(data, RLC_PG_DELAY, CMD_PROPAGATE_DELAY, 0x10);
4001	data = REG_SET_FIELD(data, RLC_PG_DELAY, MEM_SLEEP_DELAY, 0x10);
4002	WREG32(mmRLC_PG_DELAY, data);
4003
4004	WREG32_FIELD(RLC_PG_DELAY_2, SERDES_CMD_DELAY, 0x3);
4005	WREG32_FIELD(RLC_AUTO_PG_CTRL, GRBM_REG_SAVE_GFX_IDLE_THRESHOLD, 0x55f0);
4006
4007}
4008
4009static void cz_enable_sck_slow_down_on_power_up(struct amdgpu_device *adev,
4010						bool enable)
4011{
4012	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PU_ENABLE, enable ? 1 : 0);
4013}
4014
4015static void cz_enable_sck_slow_down_on_power_down(struct amdgpu_device *adev,
4016						  bool enable)
4017{
4018	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PD_ENABLE, enable ? 1 : 0);
4019}
4020
4021static void cz_enable_cp_power_gating(struct amdgpu_device *adev, bool enable)
4022{
4023	WREG32_FIELD(RLC_PG_CNTL, CP_PG_DISABLE, enable ? 0 : 1);
4024}
4025
4026static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
4027{
4028	if ((adev->asic_type == CHIP_CARRIZO) ||
4029	    (adev->asic_type == CHIP_STONEY)) {
4030		gfx_v8_0_init_csb(adev);
4031		gfx_v8_0_init_save_restore_list(adev);
4032		gfx_v8_0_enable_save_restore_machine(adev);
4033		WREG32(mmRLC_JUMP_TABLE_RESTORE, adev->gfx.rlc.cp_table_gpu_addr >> 8);
4034		gfx_v8_0_init_power_gating(adev);
4035		WREG32(mmRLC_PG_ALWAYS_ON_CU_MASK, adev->gfx.cu_info.ao_cu_mask);
4036	} else if ((adev->asic_type == CHIP_POLARIS11) ||
4037		   (adev->asic_type == CHIP_POLARIS12) ||
4038		   (adev->asic_type == CHIP_VEGAM)) {
4039		gfx_v8_0_init_csb(adev);
4040		gfx_v8_0_init_save_restore_list(adev);
4041		gfx_v8_0_enable_save_restore_machine(adev);
4042		gfx_v8_0_init_power_gating(adev);
4043	}
4044
4045}
4046
4047static void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
4048{
4049	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 0);
4050
4051	gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4052	gfx_v8_0_wait_for_rlc_serdes(adev);
4053}
4054
4055static void gfx_v8_0_rlc_reset(struct amdgpu_device *adev)
4056{
4057	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
4058	udelay(50);
4059
4060	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
4061	udelay(50);
4062}
4063
4064static void gfx_v8_0_rlc_start(struct amdgpu_device *adev)
4065{
4066	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 1);
4067
4068	/* carrizo do enable cp interrupt after cp inited */
4069	if (!(adev->flags & AMD_IS_APU))
4070		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4071
4072	udelay(50);
4073}
4074
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4075static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
4076{
4077	if (amdgpu_sriov_vf(adev)) {
4078		gfx_v8_0_init_csb(adev);
4079		return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
4080	}
4081
4082	adev->gfx.rlc.funcs->stop(adev);
4083	adev->gfx.rlc.funcs->reset(adev);
 
 
4084	gfx_v8_0_init_pg(adev);
4085	adev->gfx.rlc.funcs->start(adev);
 
 
 
 
 
 
 
 
 
4086
4087	return 0;
4088}
4089
4090static void gfx_v8_0_cp_gfx_enable(struct amdgpu_device *adev, bool enable)
4091{
 
4092	u32 tmp = RREG32(mmCP_ME_CNTL);
4093
4094	if (enable) {
4095		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 0);
4096		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 0);
4097		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 0);
4098	} else {
4099		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
4100		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
4101		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
 
 
4102	}
4103	WREG32(mmCP_ME_CNTL, tmp);
4104	udelay(50);
4105}
4106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4107static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev)
4108{
4109	u32 count = 0;
4110	const struct cs_section_def *sect = NULL;
4111	const struct cs_extent_def *ext = NULL;
4112
4113	/* begin clear state */
4114	count += 2;
4115	/* context control state */
4116	count += 3;
4117
4118	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4119		for (ext = sect->section; ext->extent != NULL; ++ext) {
4120			if (sect->id == SECT_CONTEXT)
4121				count += 2 + ext->reg_count;
4122			else
4123				return 0;
4124		}
4125	}
4126	/* pa_sc_raster_config/pa_sc_raster_config1 */
4127	count += 4;
4128	/* end clear state */
4129	count += 2;
4130	/* clear state */
4131	count += 2;
4132
4133	return count;
4134}
4135
4136static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
4137{
4138	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
4139	const struct cs_section_def *sect = NULL;
4140	const struct cs_extent_def *ext = NULL;
4141	int r, i;
4142
4143	/* init the CP */
4144	WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
4145	WREG32(mmCP_ENDIAN_SWAP, 0);
4146	WREG32(mmCP_DEVICE_ID, 1);
4147
4148	gfx_v8_0_cp_gfx_enable(adev, true);
4149
4150	r = amdgpu_ring_alloc(ring, gfx_v8_0_get_csb_size(adev) + 4);
4151	if (r) {
4152		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
4153		return r;
4154	}
4155
4156	/* clear state buffer */
4157	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4158	amdgpu_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4159
4160	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4161	amdgpu_ring_write(ring, 0x80000000);
4162	amdgpu_ring_write(ring, 0x80000000);
4163
4164	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4165		for (ext = sect->section; ext->extent != NULL; ++ext) {
4166			if (sect->id == SECT_CONTEXT) {
4167				amdgpu_ring_write(ring,
4168				       PACKET3(PACKET3_SET_CONTEXT_REG,
4169					       ext->reg_count));
4170				amdgpu_ring_write(ring,
4171				       ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
4172				for (i = 0; i < ext->reg_count; i++)
4173					amdgpu_ring_write(ring, ext->extent[i]);
4174			}
4175		}
4176	}
4177
4178	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4179	amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
4180	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config);
4181	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config_1);
4182
4183	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4184	amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4185
4186	amdgpu_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4187	amdgpu_ring_write(ring, 0);
4188
4189	/* init the CE partitions */
4190	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4191	amdgpu_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4192	amdgpu_ring_write(ring, 0x8000);
4193	amdgpu_ring_write(ring, 0x8000);
4194
4195	amdgpu_ring_commit(ring);
4196
4197	return 0;
4198}
4199static void gfx_v8_0_set_cpg_door_bell(struct amdgpu_device *adev, struct amdgpu_ring *ring)
4200{
4201	u32 tmp;
4202	/* no gfx doorbells on iceland */
4203	if (adev->asic_type == CHIP_TOPAZ)
4204		return;
4205
4206	tmp = RREG32(mmCP_RB_DOORBELL_CONTROL);
4207
4208	if (ring->use_doorbell) {
4209		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4210				DOORBELL_OFFSET, ring->doorbell_index);
4211		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4212						DOORBELL_HIT, 0);
4213		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4214					    DOORBELL_EN, 1);
4215	} else {
4216		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, DOORBELL_EN, 0);
4217	}
4218
4219	WREG32(mmCP_RB_DOORBELL_CONTROL, tmp);
4220
4221	if (adev->flags & AMD_IS_APU)
4222		return;
4223
4224	tmp = REG_SET_FIELD(0, CP_RB_DOORBELL_RANGE_LOWER,
4225					DOORBELL_RANGE_LOWER,
4226					adev->doorbell_index.gfx_ring0);
4227	WREG32(mmCP_RB_DOORBELL_RANGE_LOWER, tmp);
4228
4229	WREG32(mmCP_RB_DOORBELL_RANGE_UPPER,
4230		CP_RB_DOORBELL_RANGE_UPPER__DOORBELL_RANGE_UPPER_MASK);
4231}
4232
4233static int gfx_v8_0_cp_gfx_resume(struct amdgpu_device *adev)
4234{
4235	struct amdgpu_ring *ring;
4236	u32 tmp;
4237	u32 rb_bufsz;
4238	u64 rb_addr, rptr_addr, wptr_gpu_addr;
 
4239
4240	/* Set the write pointer delay */
4241	WREG32(mmCP_RB_WPTR_DELAY, 0);
4242
4243	/* set the RB to use vmid 0 */
4244	WREG32(mmCP_RB_VMID, 0);
4245
4246	/* Set ring buffer size */
4247	ring = &adev->gfx.gfx_ring[0];
4248	rb_bufsz = order_base_2(ring->ring_size / 8);
4249	tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
4250	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
4251	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MTYPE, 3);
4252	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MIN_IB_AVAILSZ, 1);
4253#ifdef __BIG_ENDIAN
4254	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, BUF_SWAP, 1);
4255#endif
4256	WREG32(mmCP_RB0_CNTL, tmp);
4257
4258	/* Initialize the ring buffer's read and write pointers */
4259	WREG32(mmCP_RB0_CNTL, tmp | CP_RB0_CNTL__RB_RPTR_WR_ENA_MASK);
4260	ring->wptr = 0;
4261	WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
4262
4263	/* set the wb address whether it's enabled or not */
4264	rptr_addr = ring->rptr_gpu_addr;
4265	WREG32(mmCP_RB0_RPTR_ADDR, lower_32_bits(rptr_addr));
4266	WREG32(mmCP_RB0_RPTR_ADDR_HI, upper_32_bits(rptr_addr) & 0xFF);
4267
4268	wptr_gpu_addr = ring->wptr_gpu_addr;
4269	WREG32(mmCP_RB_WPTR_POLL_ADDR_LO, lower_32_bits(wptr_gpu_addr));
4270	WREG32(mmCP_RB_WPTR_POLL_ADDR_HI, upper_32_bits(wptr_gpu_addr));
4271	mdelay(1);
4272	WREG32(mmCP_RB0_CNTL, tmp);
4273
4274	rb_addr = ring->gpu_addr >> 8;
4275	WREG32(mmCP_RB0_BASE, rb_addr);
4276	WREG32(mmCP_RB0_BASE_HI, upper_32_bits(rb_addr));
4277
4278	gfx_v8_0_set_cpg_door_bell(adev, ring);
4279	/* start the ring */
4280	amdgpu_ring_clear_ring(ring);
4281	gfx_v8_0_cp_gfx_start(adev);
 
 
 
 
4282
4283	return 0;
4284}
4285
4286static void gfx_v8_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
4287{
 
 
4288	if (enable) {
4289		WREG32(mmCP_MEC_CNTL, 0);
4290	} else {
4291		WREG32(mmCP_MEC_CNTL, (CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK));
4292		adev->gfx.kiq[0].ring.sched.ready = false;
 
 
4293	}
4294	udelay(50);
4295}
4296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4297/* KIQ functions */
4298static void gfx_v8_0_kiq_setting(struct amdgpu_ring *ring)
4299{
4300	uint32_t tmp;
4301	struct amdgpu_device *adev = ring->adev;
4302
4303	/* tell RLC which is KIQ queue */
4304	tmp = RREG32(mmRLC_CP_SCHEDULERS);
4305	tmp &= 0xffffff00;
4306	tmp |= (ring->me << 5) | (ring->pipe << 3) | (ring->queue);
4307	WREG32(mmRLC_CP_SCHEDULERS, tmp);
4308	tmp |= 0x80;
4309	WREG32(mmRLC_CP_SCHEDULERS, tmp);
4310}
4311
4312static int gfx_v8_0_kiq_kcq_enable(struct amdgpu_device *adev)
4313{
4314	struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
 
4315	uint64_t queue_mask = 0;
4316	int r, i;
4317
4318	for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
4319		if (!test_bit(i, adev->gfx.mec_bitmap[0].queue_bitmap))
4320			continue;
4321
4322		/* This situation may be hit in the future if a new HW
4323		 * generation exposes more than 64 queues. If so, the
4324		 * definition of queue_mask needs updating */
4325		if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
4326			DRM_ERROR("Invalid KCQ enabled: %d\n", i);
4327			break;
4328		}
4329
4330		queue_mask |= (1ull << i);
4331	}
4332
4333	r = amdgpu_ring_alloc(kiq_ring, (8 * adev->gfx.num_compute_rings) + 8);
 
 
 
 
 
 
 
4334	if (r) {
4335		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
 
4336		return r;
4337	}
4338	/* set resources */
4339	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6));
4340	amdgpu_ring_write(kiq_ring, 0);	/* vmid_mask:0 queue_type:0 (KIQ) */
4341	amdgpu_ring_write(kiq_ring, lower_32_bits(queue_mask));	/* queue mask lo */
4342	amdgpu_ring_write(kiq_ring, upper_32_bits(queue_mask));	/* queue mask hi */
4343	amdgpu_ring_write(kiq_ring, 0);	/* gws mask lo */
4344	amdgpu_ring_write(kiq_ring, 0);	/* gws mask hi */
4345	amdgpu_ring_write(kiq_ring, 0);	/* oac mask */
4346	amdgpu_ring_write(kiq_ring, 0);	/* gds heap base:0, gds heap size:0 */
4347	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4348		struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
4349		uint64_t mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
4350		uint64_t wptr_addr = ring->wptr_gpu_addr;
4351
4352		/* map queues */
4353		amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_MAP_QUEUES, 5));
4354		/* Q_sel:0, vmid:0, vidmem: 1, engine:0, num_Q:1*/
4355		amdgpu_ring_write(kiq_ring,
4356				  PACKET3_MAP_QUEUES_NUM_QUEUES(1));
4357		amdgpu_ring_write(kiq_ring,
4358				  PACKET3_MAP_QUEUES_DOORBELL_OFFSET(ring->doorbell_index) |
4359				  PACKET3_MAP_QUEUES_QUEUE(ring->queue) |
4360				  PACKET3_MAP_QUEUES_PIPE(ring->pipe) |
4361				  PACKET3_MAP_QUEUES_ME(ring->me == 1 ? 0 : 1)); /* doorbell */
4362		amdgpu_ring_write(kiq_ring, lower_32_bits(mqd_addr));
4363		amdgpu_ring_write(kiq_ring, upper_32_bits(mqd_addr));
4364		amdgpu_ring_write(kiq_ring, lower_32_bits(wptr_addr));
4365		amdgpu_ring_write(kiq_ring, upper_32_bits(wptr_addr));
4366	}
4367
 
 
 
4368	amdgpu_ring_commit(kiq_ring);
4369
4370	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
4371}
4372
4373static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
4374{
4375	int i, r = 0;
4376
4377	if (RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK) {
4378		WREG32_FIELD(CP_HQD_DEQUEUE_REQUEST, DEQUEUE_REQ, req);
4379		for (i = 0; i < adev->usec_timeout; i++) {
4380			if (!(RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
4381				break;
4382			udelay(1);
4383		}
4384		if (i == adev->usec_timeout)
4385			r = -ETIMEDOUT;
4386	}
4387	WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
4388	WREG32(mmCP_HQD_PQ_RPTR, 0);
4389	WREG32(mmCP_HQD_PQ_WPTR, 0);
4390
4391	return r;
4392}
4393
4394static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)
4395{
4396	struct amdgpu_device *adev = ring->adev;
4397
4398	if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {
4399		if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring)) {
4400			mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;
4401			mqd->cp_hqd_queue_priority =
4402				AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;
4403		}
4404	}
4405}
4406
4407static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
4408{
4409	struct amdgpu_device *adev = ring->adev;
4410	struct vi_mqd *mqd = ring->mqd_ptr;
4411	uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr;
4412	uint32_t tmp;
4413
4414	mqd->header = 0xC0310800;
4415	mqd->compute_pipelinestat_enable = 0x00000001;
4416	mqd->compute_static_thread_mgmt_se0 = 0xffffffff;
4417	mqd->compute_static_thread_mgmt_se1 = 0xffffffff;
4418	mqd->compute_static_thread_mgmt_se2 = 0xffffffff;
4419	mqd->compute_static_thread_mgmt_se3 = 0xffffffff;
4420	mqd->compute_misc_reserved = 0x00000003;
4421	mqd->dynamic_cu_mask_addr_lo = lower_32_bits(ring->mqd_gpu_addr
4422						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
4423	mqd->dynamic_cu_mask_addr_hi = upper_32_bits(ring->mqd_gpu_addr
4424						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
4425	eop_base_addr = ring->eop_gpu_addr >> 8;
4426	mqd->cp_hqd_eop_base_addr_lo = eop_base_addr;
4427	mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(eop_base_addr);
4428
4429	/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
4430	tmp = RREG32(mmCP_HQD_EOP_CONTROL);
4431	tmp = REG_SET_FIELD(tmp, CP_HQD_EOP_CONTROL, EOP_SIZE,
4432			(order_base_2(GFX8_MEC_HPD_SIZE / 4) - 1));
4433
4434	mqd->cp_hqd_eop_control = tmp;
4435
4436	/* enable doorbell? */
4437	tmp = REG_SET_FIELD(RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL),
4438			    CP_HQD_PQ_DOORBELL_CONTROL,
4439			    DOORBELL_EN,
4440			    ring->use_doorbell ? 1 : 0);
4441
4442	mqd->cp_hqd_pq_doorbell_control = tmp;
4443
4444	/* set the pointer to the MQD */
4445	mqd->cp_mqd_base_addr_lo = ring->mqd_gpu_addr & 0xfffffffc;
4446	mqd->cp_mqd_base_addr_hi = upper_32_bits(ring->mqd_gpu_addr);
4447
4448	/* set MQD vmid to 0 */
4449	tmp = RREG32(mmCP_MQD_CONTROL);
4450	tmp = REG_SET_FIELD(tmp, CP_MQD_CONTROL, VMID, 0);
4451	mqd->cp_mqd_control = tmp;
4452
4453	/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
4454	hqd_gpu_addr = ring->gpu_addr >> 8;
4455	mqd->cp_hqd_pq_base_lo = hqd_gpu_addr;
4456	mqd->cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
4457
4458	/* set up the HQD, this is similar to CP_RB0_CNTL */
4459	tmp = RREG32(mmCP_HQD_PQ_CONTROL);
4460	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, QUEUE_SIZE,
4461			    (order_base_2(ring->ring_size / 4) - 1));
4462	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE,
4463			(order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1));
4464#ifdef __BIG_ENDIAN
4465	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1);
4466#endif
4467	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
4468	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ROQ_PQ_IB_FLIP, 0);
4469	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
4470	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
4471	mqd->cp_hqd_pq_control = tmp;
4472
4473	/* set the wb address whether it's enabled or not */
4474	wb_gpu_addr = ring->rptr_gpu_addr;
4475	mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr & 0xfffffffc;
4476	mqd->cp_hqd_pq_rptr_report_addr_hi =
4477		upper_32_bits(wb_gpu_addr) & 0xffff;
4478
4479	/* only used if CP_PQ_WPTR_POLL_CNTL.CP_PQ_WPTR_POLL_CNTL__EN_MASK=1 */
4480	wb_gpu_addr = ring->wptr_gpu_addr;
4481	mqd->cp_hqd_pq_wptr_poll_addr_lo = wb_gpu_addr & 0xfffffffc;
4482	mqd->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
4483
4484	tmp = 0;
4485	/* enable the doorbell if requested */
4486	if (ring->use_doorbell) {
4487		tmp = RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
4488		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4489				DOORBELL_OFFSET, ring->doorbell_index);
4490
4491		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4492					 DOORBELL_EN, 1);
4493		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4494					 DOORBELL_SOURCE, 0);
4495		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4496					 DOORBELL_HIT, 0);
4497	}
4498
4499	mqd->cp_hqd_pq_doorbell_control = tmp;
4500
4501	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
4502	ring->wptr = 0;
4503	mqd->cp_hqd_pq_wptr = ring->wptr;
4504	mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
4505
4506	/* set the vmid for the queue */
4507	mqd->cp_hqd_vmid = 0;
4508
4509	tmp = RREG32(mmCP_HQD_PERSISTENT_STATE);
4510	tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53);
4511	mqd->cp_hqd_persistent_state = tmp;
4512
4513	/* set MTYPE */
4514	tmp = RREG32(mmCP_HQD_IB_CONTROL);
4515	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
4516	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MTYPE, 3);
4517	mqd->cp_hqd_ib_control = tmp;
4518
4519	tmp = RREG32(mmCP_HQD_IQ_TIMER);
4520	tmp = REG_SET_FIELD(tmp, CP_HQD_IQ_TIMER, MTYPE, 3);
4521	mqd->cp_hqd_iq_timer = tmp;
4522
4523	tmp = RREG32(mmCP_HQD_CTX_SAVE_CONTROL);
4524	tmp = REG_SET_FIELD(tmp, CP_HQD_CTX_SAVE_CONTROL, MTYPE, 3);
4525	mqd->cp_hqd_ctx_save_control = tmp;
4526
4527	/* defaults */
4528	mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
4529	mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
 
 
 
4530	mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
4531	mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
4532	mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
4533	mqd->cp_hqd_cntl_stack_size = RREG32(mmCP_HQD_CNTL_STACK_SIZE);
4534	mqd->cp_hqd_wg_state_offset = RREG32(mmCP_HQD_WG_STATE_OFFSET);
4535	mqd->cp_hqd_ctx_save_size = RREG32(mmCP_HQD_CTX_SAVE_SIZE);
4536	mqd->cp_hqd_eop_done_events = RREG32(mmCP_HQD_EOP_EVENTS);
4537	mqd->cp_hqd_error = RREG32(mmCP_HQD_ERROR);
4538	mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
4539	mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
4540
4541	/* set static priority for a queue/ring */
4542	gfx_v8_0_mqd_set_priority(ring, mqd);
4543	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
4544
4545	/* map_queues packet doesn't need activate the queue,
4546	 * so only kiq need set this field.
4547	 */
4548	if (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)
4549		mqd->cp_hqd_active = 1;
4550
4551	return 0;
4552}
4553
4554static int gfx_v8_0_mqd_commit(struct amdgpu_device *adev,
4555			struct vi_mqd *mqd)
4556{
4557	uint32_t mqd_reg;
4558	uint32_t *mqd_data;
4559
4560	/* HQD registers extend from mmCP_MQD_BASE_ADDR to mmCP_HQD_ERROR */
4561	mqd_data = &mqd->cp_mqd_base_addr_lo;
4562
4563	/* disable wptr polling */
4564	WREG32_FIELD(CP_PQ_WPTR_POLL_CNTL, EN, 0);
4565
4566	/* program all HQD registers */
4567	for (mqd_reg = mmCP_HQD_VMID; mqd_reg <= mmCP_HQD_EOP_CONTROL; mqd_reg++)
4568		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4569
4570	/* Tonga errata: EOP RPTR/WPTR should be left unmodified.
4571	 * This is safe since EOP RPTR==WPTR for any inactive HQD
4572	 * on ASICs that do not support context-save.
4573	 * EOP writes/reads can start anywhere in the ring.
4574	 */
4575	if (adev->asic_type != CHIP_TONGA) {
4576		WREG32(mmCP_HQD_EOP_RPTR, mqd->cp_hqd_eop_rptr);
4577		WREG32(mmCP_HQD_EOP_WPTR, mqd->cp_hqd_eop_wptr);
4578		WREG32(mmCP_HQD_EOP_WPTR_MEM, mqd->cp_hqd_eop_wptr_mem);
4579	}
4580
4581	for (mqd_reg = mmCP_HQD_EOP_EVENTS; mqd_reg <= mmCP_HQD_ERROR; mqd_reg++)
4582		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4583
4584	/* activate the HQD */
4585	for (mqd_reg = mmCP_MQD_BASE_ADDR; mqd_reg <= mmCP_HQD_ACTIVE; mqd_reg++)
4586		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4587
4588	return 0;
4589}
4590
4591static int gfx_v8_0_kiq_init_queue(struct amdgpu_ring *ring)
4592{
4593	struct amdgpu_device *adev = ring->adev;
4594	struct vi_mqd *mqd = ring->mqd_ptr;
 
4595
4596	gfx_v8_0_kiq_setting(ring);
4597
4598	if (amdgpu_in_reset(adev)) { /* for GPU_RESET case */
4599		/* reset MQD to a clean status */
4600		if (adev->gfx.kiq[0].mqd_backup)
4601			memcpy(mqd, adev->gfx.kiq[0].mqd_backup, sizeof(struct vi_mqd_allocation));
4602
4603		/* reset ring buffer */
4604		ring->wptr = 0;
4605		amdgpu_ring_clear_ring(ring);
4606		mutex_lock(&adev->srbm_mutex);
4607		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4608		gfx_v8_0_mqd_commit(adev, mqd);
4609		vi_srbm_select(adev, 0, 0, 0, 0);
4610		mutex_unlock(&adev->srbm_mutex);
4611	} else {
4612		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
4613		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
4614		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
4615		if (amdgpu_sriov_vf(adev) && adev->in_suspend)
4616			amdgpu_ring_clear_ring(ring);
4617		mutex_lock(&adev->srbm_mutex);
4618		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4619		gfx_v8_0_mqd_init(ring);
4620		gfx_v8_0_mqd_commit(adev, mqd);
4621		vi_srbm_select(adev, 0, 0, 0, 0);
4622		mutex_unlock(&adev->srbm_mutex);
4623
4624		if (adev->gfx.kiq[0].mqd_backup)
4625			memcpy(adev->gfx.kiq[0].mqd_backup, mqd, sizeof(struct vi_mqd_allocation));
4626	}
4627
4628	return 0;
4629}
4630
4631static int gfx_v8_0_kcq_init_queue(struct amdgpu_ring *ring)
4632{
4633	struct amdgpu_device *adev = ring->adev;
4634	struct vi_mqd *mqd = ring->mqd_ptr;
4635	int mqd_idx = ring - &adev->gfx.compute_ring[0];
4636
4637	if (!amdgpu_in_reset(adev) && !adev->in_suspend) {
4638		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
4639		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
4640		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
4641		mutex_lock(&adev->srbm_mutex);
4642		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4643		gfx_v8_0_mqd_init(ring);
4644		vi_srbm_select(adev, 0, 0, 0, 0);
4645		mutex_unlock(&adev->srbm_mutex);
4646
4647		if (adev->gfx.mec.mqd_backup[mqd_idx])
4648			memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
4649	} else {
4650		/* restore MQD to a clean status */
4651		if (adev->gfx.mec.mqd_backup[mqd_idx])
4652			memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
4653		/* reset ring buffer */
4654		ring->wptr = 0;
4655		amdgpu_ring_clear_ring(ring);
 
 
4656	}
4657	return 0;
4658}
4659
4660static void gfx_v8_0_set_mec_doorbell_range(struct amdgpu_device *adev)
4661{
4662	if (adev->asic_type > CHIP_TONGA) {
4663		WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER, adev->doorbell_index.kiq << 2);
4664		WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER, adev->doorbell_index.mec_ring7 << 2);
4665	}
4666	/* enable doorbells */
4667	WREG32_FIELD(CP_PQ_STATUS, DOORBELL_ENABLE, 1);
4668}
4669
4670static int gfx_v8_0_kiq_resume(struct amdgpu_device *adev)
4671{
4672	struct amdgpu_ring *ring;
4673	int r;
 
 
4674
4675	ring = &adev->gfx.kiq[0].ring;
4676
4677	r = amdgpu_bo_reserve(ring->mqd_obj, false);
4678	if (unlikely(r != 0))
4679		return r;
4680
4681	r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
4682	if (unlikely(r != 0)) {
4683		amdgpu_bo_unreserve(ring->mqd_obj);
4684		return r;
 
4685	}
4686
4687	gfx_v8_0_kiq_init_queue(ring);
4688	amdgpu_bo_kunmap(ring->mqd_obj);
4689	ring->mqd_ptr = NULL;
4690	amdgpu_bo_unreserve(ring->mqd_obj);
4691	return 0;
4692}
4693
4694static int gfx_v8_0_kcq_resume(struct amdgpu_device *adev)
4695{
4696	struct amdgpu_ring *ring = NULL;
4697	int r = 0, i;
4698
4699	gfx_v8_0_cp_compute_enable(adev, true);
4700
4701	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4702		ring = &adev->gfx.compute_ring[i];
4703
4704		r = amdgpu_bo_reserve(ring->mqd_obj, false);
4705		if (unlikely(r != 0))
4706			goto done;
4707		r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
4708		if (!r) {
4709			r = gfx_v8_0_kcq_init_queue(ring);
4710			amdgpu_bo_kunmap(ring->mqd_obj);
4711			ring->mqd_ptr = NULL;
4712		}
4713		amdgpu_bo_unreserve(ring->mqd_obj);
4714		if (r)
4715			goto done;
4716	}
4717
4718	gfx_v8_0_set_mec_doorbell_range(adev);
4719
4720	r = gfx_v8_0_kiq_kcq_enable(adev);
4721	if (r)
4722		goto done;
4723
4724done:
4725	return r;
4726}
4727
4728static int gfx_v8_0_cp_test_all_rings(struct amdgpu_device *adev)
4729{
4730	int r, i;
4731	struct amdgpu_ring *ring;
4732
4733	/* collect all the ring_tests here, gfx, kiq, compute */
4734	ring = &adev->gfx.gfx_ring[0];
4735	r = amdgpu_ring_test_helper(ring);
4736	if (r)
4737		return r;
4738
4739	ring = &adev->gfx.kiq[0].ring;
4740	r = amdgpu_ring_test_helper(ring);
4741	if (r)
4742		return r;
4743
 
4744	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4745		ring = &adev->gfx.compute_ring[i];
4746		amdgpu_ring_test_helper(ring);
 
 
 
4747	}
4748
4749	return 0;
 
4750}
4751
4752static int gfx_v8_0_cp_resume(struct amdgpu_device *adev)
4753{
4754	int r;
4755
4756	if (!(adev->flags & AMD_IS_APU))
4757		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4758
4759	r = gfx_v8_0_kiq_resume(adev);
4760	if (r)
4761		return r;
 
 
4762
4763	r = gfx_v8_0_cp_gfx_resume(adev);
4764	if (r)
4765		return r;
 
4766
4767	r = gfx_v8_0_kcq_resume(adev);
4768	if (r)
4769		return r;
4770
4771	r = gfx_v8_0_cp_test_all_rings(adev);
4772	if (r)
4773		return r;
4774
4775	gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4776
4777	return 0;
4778}
4779
4780static void gfx_v8_0_cp_enable(struct amdgpu_device *adev, bool enable)
4781{
4782	gfx_v8_0_cp_gfx_enable(adev, enable);
4783	gfx_v8_0_cp_compute_enable(adev, enable);
4784}
4785
4786static int gfx_v8_0_hw_init(struct amdgpu_ip_block *ip_block)
4787{
4788	int r;
4789	struct amdgpu_device *adev = ip_block->adev;
4790
4791	gfx_v8_0_init_golden_registers(adev);
4792	gfx_v8_0_constants_init(adev);
4793
4794	r = adev->gfx.rlc.funcs->resume(adev);
4795	if (r)
4796		return r;
4797
4798	r = gfx_v8_0_cp_resume(adev);
4799
4800	return r;
4801}
4802
4803static int gfx_v8_0_kcq_disable(struct amdgpu_device *adev)
4804{
 
 
4805	int r, i;
4806	struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[0].ring;
4807
4808	r = amdgpu_ring_alloc(kiq_ring, 6 * adev->gfx.num_compute_rings);
4809	if (r)
4810		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
 
 
 
4811
4812	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4813		struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
 
 
 
 
4814
4815		amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_UNMAP_QUEUES, 4));
4816		amdgpu_ring_write(kiq_ring, /* Q_sel: 0, vmid: 0, engine: 0, num_Q: 1 */
 
4817						PACKET3_UNMAP_QUEUES_ACTION(1) | /* RESET_QUEUES */
4818						PACKET3_UNMAP_QUEUES_QUEUE_SEL(0) |
4819						PACKET3_UNMAP_QUEUES_ENGINE_SEL(0) |
4820						PACKET3_UNMAP_QUEUES_NUM_QUEUES(1));
4821		amdgpu_ring_write(kiq_ring, PACKET3_UNMAP_QUEUES_DOORBELL_OFFSET0(ring->doorbell_index));
4822		amdgpu_ring_write(kiq_ring, 0);
4823		amdgpu_ring_write(kiq_ring, 0);
4824		amdgpu_ring_write(kiq_ring, 0);
4825	}
4826	/* Submit unmap queue packet */
 
 
4827	amdgpu_ring_commit(kiq_ring);
4828	/*
4829	 * Ring test will do a basic scratch register change check. Just run
4830	 * this to ensure that unmap queues that is submitted before got
4831	 * processed successfully before returning.
4832	 */
4833	r = amdgpu_ring_test_helper(kiq_ring);
4834	if (r)
4835		DRM_ERROR("KCQ disable failed\n");
4836
 
 
 
 
 
 
 
 
 
 
 
4837	return r;
4838}
4839
4840static bool gfx_v8_0_is_idle(void *handle)
4841{
4842	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
4843
4844	if (REG_GET_FIELD(RREG32(mmGRBM_STATUS), GRBM_STATUS, GUI_ACTIVE)
4845		|| RREG32(mmGRBM_STATUS2) != 0x8)
4846		return false;
4847	else
4848		return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4849}
4850
4851static bool gfx_v8_0_rlc_is_idle(void *handle)
4852{
4853	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4854
4855	if (RREG32(mmGRBM_STATUS2) != 0x8)
4856		return false;
4857	else
4858		return true;
4859}
4860
4861static int gfx_v8_0_wait_for_rlc_idle(void *handle)
4862{
4863	unsigned int i;
4864	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4865
4866	for (i = 0; i < adev->usec_timeout; i++) {
4867		if (gfx_v8_0_rlc_is_idle(handle))
4868			return 0;
 
4869
4870		udelay(1);
4871	}
4872	return -ETIMEDOUT;
 
 
 
 
 
4873}
4874
4875static int gfx_v8_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
4876{
4877	unsigned int i;
4878	struct amdgpu_device *adev = ip_block->adev;
4879
4880	for (i = 0; i < adev->usec_timeout; i++) {
4881		if (gfx_v8_0_is_idle(adev))
4882			return 0;
4883
4884		udelay(1);
4885	}
4886	return -ETIMEDOUT;
4887}
4888
4889static int gfx_v8_0_hw_fini(struct amdgpu_ip_block *ip_block)
4890{
4891	struct amdgpu_device *adev = ip_block->adev;
4892
4893	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
4894	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
4895
4896	amdgpu_irq_put(adev, &adev->gfx.cp_ecc_error_irq, 0);
4897
4898	amdgpu_irq_put(adev, &adev->gfx.sq_irq, 0);
4899
4900	/* disable KCQ to avoid CPC touch memory not valid anymore */
4901	gfx_v8_0_kcq_disable(adev);
4902
4903	if (amdgpu_sriov_vf(adev)) {
4904		pr_debug("For SRIOV client, shouldn't do anything.\n");
4905		return 0;
4906	}
4907
4908	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
4909	if (!gfx_v8_0_wait_for_idle(ip_block))
4910		gfx_v8_0_cp_enable(adev, false);
4911	else
4912		pr_err("cp is busy, skip halt cp\n");
4913	if (!gfx_v8_0_wait_for_rlc_idle(adev))
4914		adev->gfx.rlc.funcs->stop(adev);
4915	else
4916		pr_err("rlc is busy, skip halt rlc\n");
4917	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
4918
4919	return 0;
4920}
4921
4922static int gfx_v8_0_suspend(struct amdgpu_ip_block *ip_block)
4923{
4924	return gfx_v8_0_hw_fini(ip_block);
4925}
4926
4927static int gfx_v8_0_resume(struct amdgpu_ip_block *ip_block)
4928{
4929	return gfx_v8_0_hw_init(ip_block);
4930}
4931
4932static bool gfx_v8_0_check_soft_reset(struct amdgpu_ip_block *ip_block)
4933{
4934	struct amdgpu_device *adev = ip_block->adev;
4935	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
4936	u32 tmp;
4937
4938	/* GRBM_STATUS */
4939	tmp = RREG32(mmGRBM_STATUS);
4940	if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
4941		   GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
4942		   GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
4943		   GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
4944		   GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
4945		   GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK |
4946		   GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
4947		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4948						GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
4949		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4950						GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
4951		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
4952						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
4953	}
4954
4955	/* GRBM_STATUS2 */
4956	tmp = RREG32(mmGRBM_STATUS2);
4957	if (REG_GET_FIELD(tmp, GRBM_STATUS2, RLC_BUSY))
4958		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
4959						GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
4960
4961	if (REG_GET_FIELD(tmp, GRBM_STATUS2, CPF_BUSY) ||
4962	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPC_BUSY) ||
4963	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPG_BUSY)) {
4964		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
4965						SOFT_RESET_CPF, 1);
4966		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
4967						SOFT_RESET_CPC, 1);
4968		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
4969						SOFT_RESET_CPG, 1);
4970		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
4971						SOFT_RESET_GRBM, 1);
4972	}
4973
4974	/* SRBM_STATUS */
4975	tmp = RREG32(mmSRBM_STATUS);
4976	if (REG_GET_FIELD(tmp, SRBM_STATUS, GRBM_RQ_PENDING))
4977		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
4978						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
4979	if (REG_GET_FIELD(tmp, SRBM_STATUS, SEM_BUSY))
4980		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
4981						SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
4982
4983	if (grbm_soft_reset || srbm_soft_reset) {
4984		adev->gfx.grbm_soft_reset = grbm_soft_reset;
4985		adev->gfx.srbm_soft_reset = srbm_soft_reset;
4986		return true;
4987	} else {
4988		adev->gfx.grbm_soft_reset = 0;
4989		adev->gfx.srbm_soft_reset = 0;
4990		return false;
4991	}
4992}
4993
4994static int gfx_v8_0_pre_soft_reset(struct amdgpu_ip_block *ip_block)
4995{
4996	struct amdgpu_device *adev = ip_block->adev;
4997	u32 grbm_soft_reset = 0;
4998
4999	if ((!adev->gfx.grbm_soft_reset) &&
5000	    (!adev->gfx.srbm_soft_reset))
5001		return 0;
5002
5003	grbm_soft_reset = adev->gfx.grbm_soft_reset;
 
5004
5005	/* stop the rlc */
5006	adev->gfx.rlc.funcs->stop(adev);
5007
5008	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5009	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
5010		/* Disable GFX parsing/prefetching */
5011		gfx_v8_0_cp_gfx_enable(adev, false);
5012
5013	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5014	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
5015	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
5016	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
5017		int i;
5018
5019		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
5020			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
5021
5022			mutex_lock(&adev->srbm_mutex);
5023			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5024			gfx_v8_0_deactivate_hqd(adev, 2);
5025			vi_srbm_select(adev, 0, 0, 0, 0);
5026			mutex_unlock(&adev->srbm_mutex);
5027		}
5028		/* Disable MEC parsing/prefetching */
5029		gfx_v8_0_cp_compute_enable(adev, false);
5030	}
5031
5032	return 0;
5033}
5034
5035static int gfx_v8_0_soft_reset(struct amdgpu_ip_block *ip_block)
5036{
5037	struct amdgpu_device *adev = ip_block->adev;
5038	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5039	u32 tmp;
5040
5041	if ((!adev->gfx.grbm_soft_reset) &&
5042	    (!adev->gfx.srbm_soft_reset))
5043		return 0;
5044
5045	grbm_soft_reset = adev->gfx.grbm_soft_reset;
5046	srbm_soft_reset = adev->gfx.srbm_soft_reset;
5047
5048	if (grbm_soft_reset || srbm_soft_reset) {
5049		tmp = RREG32(mmGMCON_DEBUG);
5050		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 1);
5051		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 1);
5052		WREG32(mmGMCON_DEBUG, tmp);
5053		udelay(50);
5054	}
5055
5056	if (grbm_soft_reset) {
5057		tmp = RREG32(mmGRBM_SOFT_RESET);
5058		tmp |= grbm_soft_reset;
5059		dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5060		WREG32(mmGRBM_SOFT_RESET, tmp);
5061		tmp = RREG32(mmGRBM_SOFT_RESET);
5062
5063		udelay(50);
5064
5065		tmp &= ~grbm_soft_reset;
5066		WREG32(mmGRBM_SOFT_RESET, tmp);
5067		tmp = RREG32(mmGRBM_SOFT_RESET);
5068	}
5069
5070	if (srbm_soft_reset) {
5071		tmp = RREG32(mmSRBM_SOFT_RESET);
5072		tmp |= srbm_soft_reset;
5073		dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5074		WREG32(mmSRBM_SOFT_RESET, tmp);
5075		tmp = RREG32(mmSRBM_SOFT_RESET);
5076
5077		udelay(50);
5078
5079		tmp &= ~srbm_soft_reset;
5080		WREG32(mmSRBM_SOFT_RESET, tmp);
5081		tmp = RREG32(mmSRBM_SOFT_RESET);
5082	}
5083
5084	if (grbm_soft_reset || srbm_soft_reset) {
5085		tmp = RREG32(mmGMCON_DEBUG);
5086		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 0);
5087		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 0);
5088		WREG32(mmGMCON_DEBUG, tmp);
5089	}
5090
5091	/* Wait a little for things to settle down */
5092	udelay(50);
5093
5094	return 0;
5095}
5096
5097static int gfx_v8_0_post_soft_reset(struct amdgpu_ip_block *ip_block)
5098{
5099	struct amdgpu_device *adev = ip_block->adev;
5100	u32 grbm_soft_reset = 0;
5101
5102	if ((!adev->gfx.grbm_soft_reset) &&
5103	    (!adev->gfx.srbm_soft_reset))
5104		return 0;
5105
5106	grbm_soft_reset = adev->gfx.grbm_soft_reset;
 
 
 
 
 
5107
5108	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5109	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
5110	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
5111	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
5112		int i;
5113
5114		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
5115			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
5116
5117			mutex_lock(&adev->srbm_mutex);
5118			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5119			gfx_v8_0_deactivate_hqd(adev, 2);
5120			vi_srbm_select(adev, 0, 0, 0, 0);
5121			mutex_unlock(&adev->srbm_mutex);
5122		}
5123		gfx_v8_0_kiq_resume(adev);
5124		gfx_v8_0_kcq_resume(adev);
5125	}
5126
5127	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5128	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
5129		gfx_v8_0_cp_gfx_resume(adev);
5130
5131	gfx_v8_0_cp_test_all_rings(adev);
5132
5133	adev->gfx.rlc.funcs->start(adev);
5134
5135	return 0;
5136}
5137
5138/**
5139 * gfx_v8_0_get_gpu_clock_counter - return GPU clock counter snapshot
5140 *
5141 * @adev: amdgpu_device pointer
5142 *
5143 * Fetches a GPU clock counter snapshot.
5144 * Returns the 64 bit clock counter snapshot.
5145 */
5146static uint64_t gfx_v8_0_get_gpu_clock_counter(struct amdgpu_device *adev)
5147{
5148	uint64_t clock;
5149
5150	mutex_lock(&adev->gfx.gpu_clock_mutex);
5151	WREG32(mmRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
5152	clock = (uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_LSB) |
5153		((uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
5154	mutex_unlock(&adev->gfx.gpu_clock_mutex);
5155	return clock;
5156}
5157
5158static void gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring *ring,
5159					  uint32_t vmid,
5160					  uint32_t gds_base, uint32_t gds_size,
5161					  uint32_t gws_base, uint32_t gws_size,
5162					  uint32_t oa_base, uint32_t oa_size)
5163{
 
 
 
 
 
 
 
 
 
5164	/* GDS Base */
5165	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5166	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5167				WRITE_DATA_DST_SEL(0)));
5168	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_base);
5169	amdgpu_ring_write(ring, 0);
5170	amdgpu_ring_write(ring, gds_base);
5171
5172	/* GDS Size */
5173	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5174	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5175				WRITE_DATA_DST_SEL(0)));
5176	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_size);
5177	amdgpu_ring_write(ring, 0);
5178	amdgpu_ring_write(ring, gds_size);
5179
5180	/* GWS */
5181	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5182	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5183				WRITE_DATA_DST_SEL(0)));
5184	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].gws);
5185	amdgpu_ring_write(ring, 0);
5186	amdgpu_ring_write(ring, gws_size << GDS_GWS_VMID0__SIZE__SHIFT | gws_base);
5187
5188	/* OA */
5189	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5190	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5191				WRITE_DATA_DST_SEL(0)));
5192	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].oa);
5193	amdgpu_ring_write(ring, 0);
5194	amdgpu_ring_write(ring, (1 << (oa_size + oa_base)) - (1 << oa_base));
5195}
5196
5197static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t address)
5198{
5199	WREG32(mmSQ_IND_INDEX,
5200		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5201		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5202		(address << SQ_IND_INDEX__INDEX__SHIFT) |
5203		(SQ_IND_INDEX__FORCE_READ_MASK));
5204	return RREG32(mmSQ_IND_DATA);
5205}
5206
5207static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,
5208			   uint32_t wave, uint32_t thread,
5209			   uint32_t regno, uint32_t num, uint32_t *out)
5210{
5211	WREG32(mmSQ_IND_INDEX,
5212		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5213		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5214		(regno << SQ_IND_INDEX__INDEX__SHIFT) |
5215		(thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |
5216		(SQ_IND_INDEX__FORCE_READ_MASK) |
5217		(SQ_IND_INDEX__AUTO_INCR_MASK));
5218	while (num--)
5219		*(out++) = RREG32(mmSQ_IND_DATA);
5220}
5221
5222static 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)
5223{
5224	/* type 0 wave data */
5225	dst[(*no_fields)++] = 0;
5226	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_STATUS);
5227	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_LO);
5228	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_HI);
5229	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_LO);
5230	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_HI);
5231	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_HW_ID);
5232	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW0);
5233	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW1);
5234	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_GPR_ALLOC);
5235	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_LDS_ALLOC);
5236	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TRAPSTS);
5237	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_STS);
5238	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_LO);
5239	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_HI);
5240	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_LO);
5241	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_HI);
5242	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_DBG0);
5243	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);
5244	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_MODE);
5245}
5246
5247static void gfx_v8_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t xcc_id, uint32_t simd,
5248				     uint32_t wave, uint32_t start,
5249				     uint32_t size, uint32_t *dst)
5250{
5251	wave_read_regs(
5252		adev, simd, wave, 0,
5253		start + SQIND_WAVE_SGPRS_OFFSET, size, dst);
5254}
5255
5256
5257static const struct amdgpu_gfx_funcs gfx_v8_0_gfx_funcs = {
5258	.get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
5259	.select_se_sh = &gfx_v8_0_select_se_sh,
5260	.read_wave_data = &gfx_v8_0_read_wave_data,
5261	.read_wave_sgprs = &gfx_v8_0_read_wave_sgprs,
5262	.select_me_pipe_q = &gfx_v8_0_select_me_pipe_q
5263};
5264
5265static int gfx_v8_0_early_init(struct amdgpu_ip_block *ip_block)
5266{
5267	struct amdgpu_device *adev = ip_block->adev;
5268
5269	adev->gfx.xcc_mask = 1;
5270	adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
5271	adev->gfx.num_compute_rings = min(amdgpu_gfx_get_num_kcq(adev),
5272					  AMDGPU_MAX_COMPUTE_RINGS);
5273	adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
5274	gfx_v8_0_set_ring_funcs(adev);
5275	gfx_v8_0_set_irq_funcs(adev);
5276	gfx_v8_0_set_gds_init(adev);
5277	gfx_v8_0_set_rlc_funcs(adev);
5278
5279	return 0;
5280}
5281
5282static int gfx_v8_0_late_init(struct amdgpu_ip_block *ip_block)
5283{
5284	struct amdgpu_device *adev = ip_block->adev;
5285	int r;
5286
5287	r = amdgpu_irq_get(adev, &adev->gfx.priv_reg_irq, 0);
5288	if (r)
5289		return r;
5290
5291	r = amdgpu_irq_get(adev, &adev->gfx.priv_inst_irq, 0);
5292	if (r)
5293		return r;
5294
5295	/* requires IBs so do in late init after IB pool is initialized */
5296	r = gfx_v8_0_do_edc_gpr_workarounds(adev);
5297	if (r)
5298		return r;
5299
5300	r = amdgpu_irq_get(adev, &adev->gfx.cp_ecc_error_irq, 0);
5301	if (r) {
5302		DRM_ERROR("amdgpu_irq_get() failed to get IRQ for EDC, r: %d.\n", r);
5303		return r;
5304	}
5305
5306	r = amdgpu_irq_get(adev, &adev->gfx.sq_irq, 0);
5307	if (r) {
5308		DRM_ERROR(
5309			"amdgpu_irq_get() failed to get IRQ for SQ, r: %d.\n",
5310			r);
5311		return r;
5312	}
5313
5314	return 0;
5315}
5316
5317static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
5318						       bool enable)
5319{
5320	if ((adev->asic_type == CHIP_POLARIS11) ||
5321	    (adev->asic_type == CHIP_POLARIS12) ||
5322	    (adev->asic_type == CHIP_VEGAM))
5323		/* Send msg to SMU via Powerplay */
5324		amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, enable);
 
 
 
5325
5326	WREG32_FIELD(RLC_PG_CNTL, STATIC_PER_CU_PG_ENABLE, enable ? 1 : 0);
5327}
5328
5329static void gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
5330							bool enable)
5331{
5332	WREG32_FIELD(RLC_PG_CNTL, DYN_PER_CU_PG_ENABLE, enable ? 1 : 0);
5333}
5334
5335static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
5336		bool enable)
5337{
5338	WREG32_FIELD(RLC_PG_CNTL, QUICK_PG_ENABLE, enable ? 1 : 0);
5339}
5340
5341static void cz_enable_gfx_cg_power_gating(struct amdgpu_device *adev,
5342					  bool enable)
5343{
5344	WREG32_FIELD(RLC_PG_CNTL, GFX_POWER_GATING_ENABLE, enable ? 1 : 0);
5345}
5346
5347static void cz_enable_gfx_pipeline_power_gating(struct amdgpu_device *adev,
5348						bool enable)
5349{
5350	WREG32_FIELD(RLC_PG_CNTL, GFX_PIPELINE_PG_ENABLE, enable ? 1 : 0);
5351
5352	/* Read any GFX register to wake up GFX. */
5353	if (!enable)
5354		RREG32(mmDB_RENDER_CONTROL);
5355}
5356
5357static void cz_update_gfx_cg_power_gating(struct amdgpu_device *adev,
5358					  bool enable)
5359{
5360	if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) && enable) {
5361		cz_enable_gfx_cg_power_gating(adev, true);
5362		if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PIPELINE)
5363			cz_enable_gfx_pipeline_power_gating(adev, true);
5364	} else {
5365		cz_enable_gfx_cg_power_gating(adev, false);
5366		cz_enable_gfx_pipeline_power_gating(adev, false);
5367	}
5368}
5369
5370static int gfx_v8_0_set_powergating_state(void *handle,
5371					  enum amd_powergating_state state)
5372{
5373	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5374	bool enable = (state == AMD_PG_STATE_GATE);
5375
5376	if (amdgpu_sriov_vf(adev))
5377		return 0;
5378
5379	if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
5380				AMD_PG_SUPPORT_RLC_SMU_HS |
5381				AMD_PG_SUPPORT_CP |
5382				AMD_PG_SUPPORT_GFX_DMG))
5383		amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
5384	switch (adev->asic_type) {
5385	case CHIP_CARRIZO:
5386	case CHIP_STONEY:
5387
5388		if (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS) {
5389			cz_enable_sck_slow_down_on_power_up(adev, true);
5390			cz_enable_sck_slow_down_on_power_down(adev, true);
5391		} else {
5392			cz_enable_sck_slow_down_on_power_up(adev, false);
5393			cz_enable_sck_slow_down_on_power_down(adev, false);
5394		}
5395		if (adev->pg_flags & AMD_PG_SUPPORT_CP)
5396			cz_enable_cp_power_gating(adev, true);
5397		else
5398			cz_enable_cp_power_gating(adev, false);
5399
5400		cz_update_gfx_cg_power_gating(adev, enable);
5401
5402		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
5403			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
5404		else
5405			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
5406
5407		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
5408			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
5409		else
5410			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
5411		break;
5412	case CHIP_POLARIS11:
5413	case CHIP_POLARIS12:
5414	case CHIP_VEGAM:
5415		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
5416			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
5417		else
5418			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
5419
5420		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
5421			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
5422		else
5423			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
5424
5425		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_QUICK_MG) && enable)
5426			polaris11_enable_gfx_quick_mg_power_gating(adev, true);
5427		else
5428			polaris11_enable_gfx_quick_mg_power_gating(adev, false);
5429		break;
5430	default:
5431		break;
5432	}
5433	if (adev->pg_flags & (AMD_PG_SUPPORT_GFX_SMG |
5434				AMD_PG_SUPPORT_RLC_SMU_HS |
5435				AMD_PG_SUPPORT_CP |
5436				AMD_PG_SUPPORT_GFX_DMG))
5437		amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
5438	return 0;
5439}
5440
5441static void gfx_v8_0_get_clockgating_state(void *handle, u64 *flags)
5442{
5443	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5444	int data;
5445
5446	if (amdgpu_sriov_vf(adev))
5447		*flags = 0;
5448
5449	/* AMD_CG_SUPPORT_GFX_MGCG */
5450	data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5451	if (!(data & RLC_CGTT_MGCG_OVERRIDE__CPF_MASK))
5452		*flags |= AMD_CG_SUPPORT_GFX_MGCG;
5453
5454	/* AMD_CG_SUPPORT_GFX_CGLG */
5455	data = RREG32(mmRLC_CGCG_CGLS_CTRL);
5456	if (data & RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK)
5457		*flags |= AMD_CG_SUPPORT_GFX_CGCG;
5458
5459	/* AMD_CG_SUPPORT_GFX_CGLS */
5460	if (data & RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK)
5461		*flags |= AMD_CG_SUPPORT_GFX_CGLS;
5462
5463	/* AMD_CG_SUPPORT_GFX_CGTS */
5464	data = RREG32(mmCGTS_SM_CTRL_REG);
5465	if (!(data & CGTS_SM_CTRL_REG__OVERRIDE_MASK))
5466		*flags |= AMD_CG_SUPPORT_GFX_CGTS;
5467
5468	/* AMD_CG_SUPPORT_GFX_CGTS_LS */
5469	if (!(data & CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK))
5470		*flags |= AMD_CG_SUPPORT_GFX_CGTS_LS;
5471
5472	/* AMD_CG_SUPPORT_GFX_RLC_LS */
5473	data = RREG32(mmRLC_MEM_SLP_CNTL);
5474	if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK)
5475		*flags |= AMD_CG_SUPPORT_GFX_RLC_LS | AMD_CG_SUPPORT_GFX_MGLS;
5476
5477	/* AMD_CG_SUPPORT_GFX_CP_LS */
5478	data = RREG32(mmCP_MEM_SLP_CNTL);
5479	if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK)
5480		*flags |= AMD_CG_SUPPORT_GFX_CP_LS | AMD_CG_SUPPORT_GFX_MGLS;
5481}
5482
5483static void gfx_v8_0_send_serdes_cmd(struct amdgpu_device *adev,
5484				     uint32_t reg_addr, uint32_t cmd)
5485{
5486	uint32_t data;
5487
5488	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
5489
5490	WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
5491	WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
5492
5493	data = RREG32(mmRLC_SERDES_WR_CTRL);
5494	if (adev->asic_type == CHIP_STONEY)
5495		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5496			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5497			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5498			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5499			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5500			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5501			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5502			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5503			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5504	else
5505		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5506			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5507			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5508			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5509			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5510			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5511			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5512			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5513			  RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
5514			  RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
5515			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5516	data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK |
5517		 (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) |
5518		 (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) |
5519		 (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT));
5520
5521	WREG32(mmRLC_SERDES_WR_CTRL, data);
5522}
5523
5524#define MSG_ENTER_RLC_SAFE_MODE     1
5525#define MSG_EXIT_RLC_SAFE_MODE      0
5526#define RLC_GPR_REG2__REQ_MASK 0x00000001
5527#define RLC_GPR_REG2__REQ__SHIFT 0
5528#define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
5529#define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
5530
5531static bool gfx_v8_0_is_rlc_enabled(struct amdgpu_device *adev)
5532{
5533	uint32_t rlc_setting;
 
5534
5535	rlc_setting = RREG32(mmRLC_CNTL);
5536	if (!(rlc_setting & RLC_CNTL__RLC_ENABLE_F32_MASK))
5537		return false;
5538
5539	return true;
5540}
 
 
 
5541
5542static void gfx_v8_0_set_safe_mode(struct amdgpu_device *adev, int xcc_id)
5543{
5544	uint32_t data;
5545	unsigned i;
5546	data = RREG32(mmRLC_CNTL);
5547	data |= RLC_SAFE_MODE__CMD_MASK;
5548	data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5549	data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
5550	WREG32(mmRLC_SAFE_MODE, data);
5551
5552	/* wait for RLC_SAFE_MODE */
5553	for (i = 0; i < adev->usec_timeout; i++) {
5554		if ((RREG32(mmRLC_GPM_STAT) &
5555		     (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5556		      RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
5557		    (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5558		     RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
5559			break;
5560		udelay(1);
5561	}
5562	for (i = 0; i < adev->usec_timeout; i++) {
5563		if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5564			break;
5565		udelay(1);
5566	}
5567}
5568
5569static void gfx_v8_0_unset_safe_mode(struct amdgpu_device *adev, int xcc_id)
5570{
5571	uint32_t data;
5572	unsigned i;
5573
5574	data = RREG32(mmRLC_CNTL);
5575	data |= RLC_SAFE_MODE__CMD_MASK;
5576	data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5577	WREG32(mmRLC_SAFE_MODE, data);
 
 
 
 
 
 
 
 
5578
5579	for (i = 0; i < adev->usec_timeout; i++) {
5580		if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5581			break;
5582		udelay(1);
5583	}
5584}
5585
5586static void gfx_v8_0_update_spm_vmid(struct amdgpu_device *adev, struct amdgpu_ring *ring, unsigned vmid)
5587{
5588	u32 data;
5589
5590	amdgpu_gfx_off_ctrl(adev, false);
5591
5592	if (amdgpu_sriov_is_pp_one_vf(adev))
5593		data = RREG32_NO_KIQ(mmRLC_SPM_VMID);
5594	else
5595		data = RREG32(mmRLC_SPM_VMID);
5596
5597	data &= ~RLC_SPM_VMID__RLC_SPM_VMID_MASK;
5598	data |= (vmid & RLC_SPM_VMID__RLC_SPM_VMID_MASK) << RLC_SPM_VMID__RLC_SPM_VMID__SHIFT;
5599
5600	if (amdgpu_sriov_is_pp_one_vf(adev))
5601		WREG32_NO_KIQ(mmRLC_SPM_VMID, data);
5602	else
5603		WREG32(mmRLC_SPM_VMID, data);
5604
5605	amdgpu_gfx_off_ctrl(adev, true);
5606}
5607
5608static const struct amdgpu_rlc_funcs iceland_rlc_funcs = {
5609	.is_rlc_enabled = gfx_v8_0_is_rlc_enabled,
5610	.set_safe_mode = gfx_v8_0_set_safe_mode,
5611	.unset_safe_mode = gfx_v8_0_unset_safe_mode,
5612	.init = gfx_v8_0_rlc_init,
5613	.get_csb_size = gfx_v8_0_get_csb_size,
5614	.get_csb_buffer = gfx_v8_0_get_csb_buffer,
5615	.get_cp_table_num = gfx_v8_0_cp_jump_table_num,
5616	.resume = gfx_v8_0_rlc_resume,
5617	.stop = gfx_v8_0_rlc_stop,
5618	.reset = gfx_v8_0_rlc_reset,
5619	.start = gfx_v8_0_rlc_start,
5620	.update_spm_vmid = gfx_v8_0_update_spm_vmid
5621};
5622
5623static void gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
5624						      bool enable)
5625{
5626	uint32_t temp, data;
5627
5628	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
5629
5630	/* It is disabled by HW by default */
5631	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
5632		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
5633			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS)
5634				/* 1 - RLC memory Light sleep */
5635				WREG32_FIELD(RLC_MEM_SLP_CNTL, RLC_MEM_LS_EN, 1);
5636
5637			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS)
5638				WREG32_FIELD(CP_MEM_SLP_CNTL, CP_MEM_LS_EN, 1);
5639		}
5640
5641		/* 3 - RLC_CGTT_MGCG_OVERRIDE */
5642		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5643		if (adev->flags & AMD_IS_APU)
5644			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5645				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5646				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK);
5647		else
5648			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5649				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5650				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
5651				  RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
5652
5653		if (temp != data)
5654			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
5655
5656		/* 4 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5657		gfx_v8_0_wait_for_rlc_serdes(adev);
5658
5659		/* 5 - clear mgcg override */
5660		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
5661
5662		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
5663			/* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */
5664			temp = data = RREG32(mmCGTS_SM_CTRL_REG);
5665			data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK);
5666			data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
5667			data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
5668			data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
5669			if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
5670			    (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
5671				data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
5672			data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
5673			data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
5674			if (temp != data)
5675				WREG32(mmCGTS_SM_CTRL_REG, data);
5676		}
5677		udelay(50);
5678
5679		/* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5680		gfx_v8_0_wait_for_rlc_serdes(adev);
5681	} else {
5682		/* 1 - MGCG_OVERRIDE[0] for CP and MGCG_OVERRIDE[1] for RLC */
5683		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5684		data |= (RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5685				RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5686				RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
5687				RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
5688		if (temp != data)
5689			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
5690
5691		/* 2 - disable MGLS in RLC */
5692		data = RREG32(mmRLC_MEM_SLP_CNTL);
5693		if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK) {
5694			data &= ~RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
5695			WREG32(mmRLC_MEM_SLP_CNTL, data);
5696		}
5697
5698		/* 3 - disable MGLS in CP */
5699		data = RREG32(mmCP_MEM_SLP_CNTL);
5700		if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK) {
5701			data &= ~CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
5702			WREG32(mmCP_MEM_SLP_CNTL, data);
5703		}
5704
5705		/* 4 - Disable CGTS(Tree Shade) MGCG and MGLS */
5706		temp = data = RREG32(mmCGTS_SM_CTRL_REG);
5707		data |= (CGTS_SM_CTRL_REG__OVERRIDE_MASK |
5708				CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK);
5709		if (temp != data)
5710			WREG32(mmCGTS_SM_CTRL_REG, data);
5711
5712		/* 5 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5713		gfx_v8_0_wait_for_rlc_serdes(adev);
5714
5715		/* 6 - set mgcg override */
5716		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD);
5717
5718		udelay(50);
5719
5720		/* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5721		gfx_v8_0_wait_for_rlc_serdes(adev);
5722	}
5723
5724	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
5725}
5726
5727static void gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
5728						      bool enable)
5729{
5730	uint32_t temp, temp1, data, data1;
5731
5732	temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
5733
5734	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
5735
5736	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
5737		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5738		data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK;
5739		if (temp1 != data1)
5740			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5741
5742		/* : wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5743		gfx_v8_0_wait_for_rlc_serdes(adev);
5744
5745		/* 2 - clear cgcg override */
5746		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
5747
5748		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5749		gfx_v8_0_wait_for_rlc_serdes(adev);
5750
5751		/* 3 - write cmd to set CGLS */
5752		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD);
5753
5754		/* 4 - enable cgcg */
5755		data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK;
5756
5757		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
5758			/* enable cgls*/
5759			data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
5760
5761			temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5762			data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK;
5763
5764			if (temp1 != data1)
5765				WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5766		} else {
5767			data &= ~RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
5768		}
5769
5770		if (temp != data)
5771			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5772
5773		/* 5 enable cntx_empty_int_enable/cntx_busy_int_enable/
5774		 * Cmp_busy/GFX_Idle interrupts
5775		 */
5776		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
5777	} else {
5778		/* disable cntx_empty_int_enable & GFX Idle interrupt */
5779		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
5780
5781		/* TEST CGCG */
5782		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5783		data1 |= (RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK |
5784				RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK);
5785		if (temp1 != data1)
5786			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5787
5788		/* read gfx register to wake up cgcg */
5789		RREG32(mmCB_CGTT_SCLK_CTRL);
5790		RREG32(mmCB_CGTT_SCLK_CTRL);
5791		RREG32(mmCB_CGTT_SCLK_CTRL);
5792		RREG32(mmCB_CGTT_SCLK_CTRL);
5793
5794		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5795		gfx_v8_0_wait_for_rlc_serdes(adev);
5796
5797		/* write cmd to Set CGCG Override */
5798		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD);
5799
5800		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5801		gfx_v8_0_wait_for_rlc_serdes(adev);
5802
5803		/* write cmd to Clear CGLS */
5804		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD);
5805
5806		/* disable cgcg, cgls should be disabled too. */
5807		data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
5808			  RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
5809		if (temp != data)
5810			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5811		/* enable interrupts again for PG */
5812		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
5813	}
5814
5815	gfx_v8_0_wait_for_rlc_serdes(adev);
5816
5817	amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
5818}
5819static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev,
5820					    bool enable)
5821{
5822	if (enable) {
5823		/* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS)
5824		 * ===  MGCG + MGLS + TS(CG/LS) ===
5825		 */
5826		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
5827		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
5828	} else {
5829		/* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS)
5830		 * ===  CGCG + CGLS ===
5831		 */
5832		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
5833		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
5834	}
5835	return 0;
5836}
5837
5838static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,
5839					  enum amd_clockgating_state state)
5840{
5841	uint32_t msg_id, pp_state = 0;
5842	uint32_t pp_support_state = 0;
5843
5844	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
5845		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
5846			pp_support_state = PP_STATE_SUPPORT_LS;
5847			pp_state = PP_STATE_LS;
5848		}
5849		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
5850			pp_support_state |= PP_STATE_SUPPORT_CG;
5851			pp_state |= PP_STATE_CG;
5852		}
5853		if (state == AMD_CG_STATE_UNGATE)
5854			pp_state = 0;
5855
5856		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5857				PP_BLOCK_GFX_CG,
5858				pp_support_state,
5859				pp_state);
5860		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5861	}
5862
5863	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
5864		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
5865			pp_support_state = PP_STATE_SUPPORT_LS;
5866			pp_state = PP_STATE_LS;
5867		}
5868
5869		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
5870			pp_support_state |= PP_STATE_SUPPORT_CG;
5871			pp_state |= PP_STATE_CG;
5872		}
5873
5874		if (state == AMD_CG_STATE_UNGATE)
5875			pp_state = 0;
5876
5877		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5878				PP_BLOCK_GFX_MG,
5879				pp_support_state,
5880				pp_state);
5881		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5882	}
5883
5884	return 0;
5885}
5886
5887static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,
5888					  enum amd_clockgating_state state)
5889{
5890
5891	uint32_t msg_id, pp_state = 0;
5892	uint32_t pp_support_state = 0;
5893
5894	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
5895		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
5896			pp_support_state = PP_STATE_SUPPORT_LS;
5897			pp_state = PP_STATE_LS;
5898		}
5899		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
5900			pp_support_state |= PP_STATE_SUPPORT_CG;
5901			pp_state |= PP_STATE_CG;
5902		}
5903		if (state == AMD_CG_STATE_UNGATE)
5904			pp_state = 0;
5905
5906		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5907				PP_BLOCK_GFX_CG,
5908				pp_support_state,
5909				pp_state);
5910		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5911	}
5912
5913	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_3D_CGCG | AMD_CG_SUPPORT_GFX_3D_CGLS)) {
5914		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGLS) {
5915			pp_support_state = PP_STATE_SUPPORT_LS;
5916			pp_state = PP_STATE_LS;
5917		}
5918		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGCG) {
5919			pp_support_state |= PP_STATE_SUPPORT_CG;
5920			pp_state |= PP_STATE_CG;
5921		}
5922		if (state == AMD_CG_STATE_UNGATE)
5923			pp_state = 0;
5924
5925		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5926				PP_BLOCK_GFX_3D,
5927				pp_support_state,
5928				pp_state);
5929		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5930	}
5931
5932	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
5933		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
5934			pp_support_state = PP_STATE_SUPPORT_LS;
5935			pp_state = PP_STATE_LS;
5936		}
5937
5938		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
5939			pp_support_state |= PP_STATE_SUPPORT_CG;
5940			pp_state |= PP_STATE_CG;
5941		}
5942
5943		if (state == AMD_CG_STATE_UNGATE)
5944			pp_state = 0;
5945
5946		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5947				PP_BLOCK_GFX_MG,
5948				pp_support_state,
5949				pp_state);
5950		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5951	}
5952
5953	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
5954		pp_support_state = PP_STATE_SUPPORT_LS;
5955
5956		if (state == AMD_CG_STATE_UNGATE)
5957			pp_state = 0;
5958		else
5959			pp_state = PP_STATE_LS;
5960
5961		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5962				PP_BLOCK_GFX_RLC,
5963				pp_support_state,
5964				pp_state);
5965		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5966	}
5967
5968	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
5969		pp_support_state = PP_STATE_SUPPORT_LS;
5970
5971		if (state == AMD_CG_STATE_UNGATE)
5972			pp_state = 0;
5973		else
5974			pp_state = PP_STATE_LS;
5975		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
5976			PP_BLOCK_GFX_CP,
5977			pp_support_state,
5978			pp_state);
5979		amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
 
5980	}
5981
5982	return 0;
5983}
5984
5985static int gfx_v8_0_set_clockgating_state(void *handle,
5986					  enum amd_clockgating_state state)
5987{
5988	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5989
5990	if (amdgpu_sriov_vf(adev))
5991		return 0;
5992
5993	switch (adev->asic_type) {
5994	case CHIP_FIJI:
5995	case CHIP_CARRIZO:
5996	case CHIP_STONEY:
5997		gfx_v8_0_update_gfx_clock_gating(adev,
5998						 state == AMD_CG_STATE_GATE);
5999		break;
6000	case CHIP_TONGA:
6001		gfx_v8_0_tonga_update_gfx_clock_gating(adev, state);
6002		break;
6003	case CHIP_POLARIS10:
6004	case CHIP_POLARIS11:
6005	case CHIP_POLARIS12:
6006	case CHIP_VEGAM:
6007		gfx_v8_0_polaris_update_gfx_clock_gating(adev, state);
6008		break;
6009	default:
6010		break;
6011	}
6012	return 0;
6013}
6014
6015static u64 gfx_v8_0_ring_get_rptr(struct amdgpu_ring *ring)
6016{
6017	return *ring->rptr_cpu_addr;
6018}
6019
6020static u64 gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
6021{
6022	struct amdgpu_device *adev = ring->adev;
6023
6024	if (ring->use_doorbell)
6025		/* XXX check if swapping is necessary on BE */
6026		return *ring->wptr_cpu_addr;
6027	else
6028		return RREG32(mmCP_RB0_WPTR);
6029}
6030
6031static void gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
6032{
6033	struct amdgpu_device *adev = ring->adev;
6034
6035	if (ring->use_doorbell) {
6036		/* XXX check if swapping is necessary on BE */
6037		*ring->wptr_cpu_addr = lower_32_bits(ring->wptr);
6038		WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6039	} else {
6040		WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
6041		(void)RREG32(mmCP_RB0_WPTR);
6042	}
6043}
6044
6045static void gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
6046{
6047	u32 ref_and_mask, reg_mem_engine;
6048
6049	if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) ||
6050	    (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)) {
6051		switch (ring->me) {
6052		case 1:
6053			ref_and_mask = GPU_HDP_FLUSH_DONE__CP2_MASK << ring->pipe;
6054			break;
6055		case 2:
6056			ref_and_mask = GPU_HDP_FLUSH_DONE__CP6_MASK << ring->pipe;
6057			break;
6058		default:
6059			return;
6060		}
6061		reg_mem_engine = 0;
6062	} else {
6063		ref_and_mask = GPU_HDP_FLUSH_DONE__CP0_MASK;
6064		reg_mem_engine = WAIT_REG_MEM_ENGINE(1); /* pfp */
6065	}
6066
6067	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6068	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
6069				 WAIT_REG_MEM_FUNCTION(3) |  /* == */
6070				 reg_mem_engine));
6071	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ);
6072	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE);
6073	amdgpu_ring_write(ring, ref_and_mask);
6074	amdgpu_ring_write(ring, ref_and_mask);
6075	amdgpu_ring_write(ring, 0x20); /* poll interval */
6076}
6077
6078static void gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)
6079{
6080	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
6081	amdgpu_ring_write(ring, EVENT_TYPE(VS_PARTIAL_FLUSH) |
6082		EVENT_INDEX(4));
6083
6084	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
6085	amdgpu_ring_write(ring, EVENT_TYPE(VGT_FLUSH) |
6086		EVENT_INDEX(0));
6087}
6088
6089static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
6090					struct amdgpu_job *job,
6091					struct amdgpu_ib *ib,
6092					uint32_t flags)
6093{
6094	unsigned vmid = AMDGPU_JOB_GET_VMID(job);
6095	u32 header, control = 0;
6096
6097	if (ib->flags & AMDGPU_IB_FLAG_CE)
6098		header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
6099	else
6100		header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
6101
6102	control |= ib->length_dw | (vmid << 24);
6103
6104	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
6105		control |= INDIRECT_BUFFER_PRE_ENB(1);
6106
6107		if (!(ib->flags & AMDGPU_IB_FLAG_CE) && vmid)
6108			gfx_v8_0_ring_emit_de_meta(ring);
6109	}
6110
6111	amdgpu_ring_write(ring, header);
6112	amdgpu_ring_write(ring,
6113#ifdef __BIG_ENDIAN
6114			  (2 << 0) |
6115#endif
6116			  (ib->gpu_addr & 0xFFFFFFFC));
6117	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
6118	amdgpu_ring_write(ring, control);
6119}
6120
6121static void gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
6122					  struct amdgpu_job *job,
6123					  struct amdgpu_ib *ib,
6124					  uint32_t flags)
6125{
6126	unsigned vmid = AMDGPU_JOB_GET_VMID(job);
6127	u32 control = INDIRECT_BUFFER_VALID | ib->length_dw | (vmid << 24);
6128
6129	/* Currently, there is a high possibility to get wave ID mismatch
6130	 * between ME and GDS, leading to a hw deadlock, because ME generates
6131	 * different wave IDs than the GDS expects. This situation happens
6132	 * randomly when at least 5 compute pipes use GDS ordered append.
6133	 * The wave IDs generated by ME are also wrong after suspend/resume.
6134	 * Those are probably bugs somewhere else in the kernel driver.
6135	 *
6136	 * Writing GDS_COMPUTE_MAX_WAVE_ID resets wave ID counters in ME and
6137	 * GDS to 0 for this ring (me/pipe).
6138	 */
6139	if (ib->flags & AMDGPU_IB_FLAG_RESET_GDS_MAX_WAVE_ID) {
6140		amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
6141		amdgpu_ring_write(ring, mmGDS_COMPUTE_MAX_WAVE_ID - PACKET3_SET_CONFIG_REG_START);
6142		amdgpu_ring_write(ring, ring->adev->gds.gds_compute_max_wave_id);
6143	}
6144
6145	amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
6146	amdgpu_ring_write(ring,
6147#ifdef __BIG_ENDIAN
6148				(2 << 0) |
6149#endif
6150				(ib->gpu_addr & 0xFFFFFFFC));
6151	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
6152	amdgpu_ring_write(ring, control);
6153}
6154
6155static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr,
6156					 u64 seq, unsigned flags)
6157{
6158	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6159	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
6160	bool exec = flags & AMDGPU_FENCE_FLAG_EXEC;
6161
6162	/* Workaround for cache flush problems. First send a dummy EOP
6163	 * event down the pipe with seq one below.
6164	 */
6165	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
6166	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6167				 EOP_TC_ACTION_EN |
6168				 EOP_TC_WB_ACTION_EN |
6169				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6170				 EVENT_INDEX(5)));
6171	amdgpu_ring_write(ring, addr & 0xfffffffc);
6172	amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
6173				DATA_SEL(1) | INT_SEL(0));
6174	amdgpu_ring_write(ring, lower_32_bits(seq - 1));
6175	amdgpu_ring_write(ring, upper_32_bits(seq - 1));
6176
6177	/* Then send the real EOP event down the pipe:
6178	 * EVENT_WRITE_EOP - flush caches, send int */
6179	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
6180	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6181				 EOP_TC_ACTION_EN |
6182				 EOP_TC_WB_ACTION_EN |
6183				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6184				 EVENT_INDEX(5) |
6185				 (exec ? EOP_EXEC : 0)));
6186	amdgpu_ring_write(ring, addr & 0xfffffffc);
6187	amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
6188			  DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6189	amdgpu_ring_write(ring, lower_32_bits(seq));
6190	amdgpu_ring_write(ring, upper_32_bits(seq));
6191
6192}
6193
6194static void gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
6195{
6196	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
6197	uint32_t seq = ring->fence_drv.sync_seq;
6198	uint64_t addr = ring->fence_drv.gpu_addr;
6199
6200	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6201	amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
6202				 WAIT_REG_MEM_FUNCTION(3) | /* equal */
6203				 WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
6204	amdgpu_ring_write(ring, addr & 0xfffffffc);
6205	amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
6206	amdgpu_ring_write(ring, seq);
6207	amdgpu_ring_write(ring, 0xffffffff);
6208	amdgpu_ring_write(ring, 4); /* poll interval */
6209}
6210
6211static void gfx_v8_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
6212					unsigned vmid, uint64_t pd_addr)
6213{
6214	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
6215
6216	amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
6217
6218	/* wait for the invalidate to complete */
6219	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6220	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
6221				 WAIT_REG_MEM_FUNCTION(0) |  /* always */
6222				 WAIT_REG_MEM_ENGINE(0))); /* me */
6223	amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
6224	amdgpu_ring_write(ring, 0);
6225	amdgpu_ring_write(ring, 0); /* ref */
6226	amdgpu_ring_write(ring, 0); /* mask */
6227	amdgpu_ring_write(ring, 0x20); /* poll interval */
6228
6229	/* compute doesn't have PFP */
6230	if (usepfp) {
6231		/* sync PFP to ME, otherwise we might get invalid PFP reads */
6232		amdgpu_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
6233		amdgpu_ring_write(ring, 0x0);
6234	}
6235}
6236
6237static u64 gfx_v8_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
6238{
6239	return *ring->wptr_cpu_addr;
6240}
6241
6242static void gfx_v8_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
6243{
6244	struct amdgpu_device *adev = ring->adev;
6245
6246	/* XXX check if swapping is necessary on BE */
6247	*ring->wptr_cpu_addr = lower_32_bits(ring->wptr);
6248	WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6249}
6250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6251static void gfx_v8_0_ring_emit_fence_compute(struct amdgpu_ring *ring,
6252					     u64 addr, u64 seq,
6253					     unsigned flags)
6254{
6255	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6256	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
6257
6258	/* RELEASE_MEM - flush caches, send int */
6259	amdgpu_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
6260	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6261				 EOP_TC_ACTION_EN |
6262				 EOP_TC_WB_ACTION_EN |
6263				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6264				 EVENT_INDEX(5)));
6265	amdgpu_ring_write(ring, DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6266	amdgpu_ring_write(ring, addr & 0xfffffffc);
6267	amdgpu_ring_write(ring, upper_32_bits(addr));
6268	amdgpu_ring_write(ring, lower_32_bits(seq));
6269	amdgpu_ring_write(ring, upper_32_bits(seq));
6270}
6271
6272static void gfx_v8_0_ring_emit_fence_kiq(struct amdgpu_ring *ring, u64 addr,
6273					 u64 seq, unsigned int flags)
6274{
6275	/* we only allocate 32bit for each seq wb address */
6276	BUG_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
6277
6278	/* write fence seq to the "addr" */
6279	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6280	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
6281				 WRITE_DATA_DST_SEL(5) | WR_CONFIRM));
6282	amdgpu_ring_write(ring, lower_32_bits(addr));
6283	amdgpu_ring_write(ring, upper_32_bits(addr));
6284	amdgpu_ring_write(ring, lower_32_bits(seq));
6285
6286	if (flags & AMDGPU_FENCE_FLAG_INT) {
6287		/* set register to trigger INT */
6288		amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6289		amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
6290					 WRITE_DATA_DST_SEL(0) | WR_CONFIRM));
6291		amdgpu_ring_write(ring, mmCPC_INT_STATUS);
6292		amdgpu_ring_write(ring, 0);
6293		amdgpu_ring_write(ring, 0x20000000); /* src_id is 178 */
6294	}
6295}
6296
6297static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
6298{
6299	amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
6300	amdgpu_ring_write(ring, 0);
6301}
6302
6303static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
6304{
6305	uint32_t dw2 = 0;
6306
6307	if (amdgpu_sriov_vf(ring->adev))
6308		gfx_v8_0_ring_emit_ce_meta(ring);
6309
6310	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
6311	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
6312		gfx_v8_0_ring_emit_vgt_flush(ring);
6313		/* set load_global_config & load_global_uconfig */
6314		dw2 |= 0x8001;
6315		/* set load_cs_sh_regs */
6316		dw2 |= 0x01000000;
6317		/* set load_per_context_state & load_gfx_sh_regs for GFX */
6318		dw2 |= 0x10002;
6319
6320		/* set load_ce_ram if preamble presented */
6321		if (AMDGPU_PREAMBLE_IB_PRESENT & flags)
6322			dw2 |= 0x10000000;
6323	} else {
6324		/* still load_ce_ram if this is the first time preamble presented
6325		 * although there is no context switch happens.
6326		 */
6327		if (AMDGPU_PREAMBLE_IB_PRESENT_FIRST & flags)
6328			dw2 |= 0x10000000;
6329	}
6330
6331	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
6332	amdgpu_ring_write(ring, dw2);
6333	amdgpu_ring_write(ring, 0);
6334}
6335
6336static unsigned gfx_v8_0_ring_emit_init_cond_exec(struct amdgpu_ring *ring,
6337						  uint64_t addr)
6338{
6339	unsigned ret;
6340
6341	amdgpu_ring_write(ring, PACKET3(PACKET3_COND_EXEC, 3));
6342	amdgpu_ring_write(ring, lower_32_bits(addr));
6343	amdgpu_ring_write(ring, upper_32_bits(addr));
6344	/* discard following DWs if *cond_exec_gpu_addr==0 */
6345	amdgpu_ring_write(ring, 0);
6346	ret = ring->wptr & ring->buf_mask;
6347	/* patch dummy value later */
6348	amdgpu_ring_write(ring, 0);
6349	return ret;
6350}
6351
6352static void gfx_v8_0_ring_emit_rreg(struct amdgpu_ring *ring, uint32_t reg,
6353				    uint32_t reg_val_offs)
 
 
 
 
 
 
 
 
 
 
 
 
 
6354{
6355	struct amdgpu_device *adev = ring->adev;
6356
6357	amdgpu_ring_write(ring, PACKET3(PACKET3_COPY_DATA, 4));
6358	amdgpu_ring_write(ring, 0 |	/* src: register*/
6359				(5 << 8) |	/* dst: memory */
6360				(1 << 20));	/* write confirm */
6361	amdgpu_ring_write(ring, reg);
6362	amdgpu_ring_write(ring, 0);
6363	amdgpu_ring_write(ring, lower_32_bits(adev->wb.gpu_addr +
6364				reg_val_offs * 4));
6365	amdgpu_ring_write(ring, upper_32_bits(adev->wb.gpu_addr +
6366				reg_val_offs * 4));
6367}
6368
6369static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
6370				  uint32_t val)
6371{
6372	uint32_t cmd;
6373
6374	switch (ring->funcs->type) {
6375	case AMDGPU_RING_TYPE_GFX:
6376		cmd = WRITE_DATA_ENGINE_SEL(1) | WR_CONFIRM;
6377		break;
6378	case AMDGPU_RING_TYPE_KIQ:
6379		cmd = 1 << 16; /* no inc addr */
6380		break;
6381	default:
6382		cmd = WR_CONFIRM;
6383		break;
6384	}
6385
6386	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6387	amdgpu_ring_write(ring, cmd);
6388	amdgpu_ring_write(ring, reg);
6389	amdgpu_ring_write(ring, 0);
6390	amdgpu_ring_write(ring, val);
6391}
6392
6393static void gfx_v8_0_wait_reg_mem(struct amdgpu_ring *ring, int eng_sel,
6394				  int mem_space, int opt, uint32_t addr0,
6395				  uint32_t addr1, uint32_t ref, uint32_t mask,
6396				  uint32_t inv)
6397{
6398	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6399	amdgpu_ring_write(ring,
6400			  /* memory (1) or register (0) */
6401			  (WAIT_REG_MEM_MEM_SPACE(mem_space) |
6402			   WAIT_REG_MEM_OPERATION(opt) | /* wait */
6403			   WAIT_REG_MEM_FUNCTION(3) |  /* equal */
6404			   WAIT_REG_MEM_ENGINE(eng_sel)));
6405
6406	if (mem_space)
6407		BUG_ON(addr0 & 0x3); /* Dword align */
6408	amdgpu_ring_write(ring, addr0);
6409	amdgpu_ring_write(ring, addr1);
6410	amdgpu_ring_write(ring, ref);
6411	amdgpu_ring_write(ring, mask);
6412	amdgpu_ring_write(ring, inv); /* poll interval */
6413}
6414
6415static void gfx_v8_0_ring_emit_reg_wait(struct amdgpu_ring *ring, uint32_t reg,
6416					uint32_t val, uint32_t mask)
6417{
6418	gfx_v8_0_wait_reg_mem(ring, 0, 0, 0, reg, 0, val, mask, 0x20);
6419}
6420
6421static void gfx_v8_0_ring_soft_recovery(struct amdgpu_ring *ring, unsigned vmid)
6422{
6423	struct amdgpu_device *adev = ring->adev;
6424	uint32_t value = 0;
6425
6426	value = REG_SET_FIELD(value, SQ_CMD, CMD, 0x03);
6427	value = REG_SET_FIELD(value, SQ_CMD, MODE, 0x01);
6428	value = REG_SET_FIELD(value, SQ_CMD, CHECK_VMID, 1);
6429	value = REG_SET_FIELD(value, SQ_CMD, VM_ID, vmid);
6430	WREG32(mmSQ_CMD, value);
6431}
6432
6433static void gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
6434						 enum amdgpu_interrupt_state state)
6435{
6436	WREG32_FIELD(CP_INT_CNTL_RING0, TIME_STAMP_INT_ENABLE,
6437		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6438}
6439
6440static void gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
6441						     int me, int pipe,
6442						     enum amdgpu_interrupt_state state)
6443{
6444	u32 mec_int_cntl, mec_int_cntl_reg;
6445
6446	/*
6447	 * amdgpu controls only the first MEC. That's why this function only
6448	 * handles the setting of interrupts for this specific MEC. All other
6449	 * pipes' interrupts are set by amdkfd.
6450	 */
6451
6452	if (me == 1) {
6453		switch (pipe) {
6454		case 0:
6455			mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
6456			break;
6457		case 1:
6458			mec_int_cntl_reg = mmCP_ME1_PIPE1_INT_CNTL;
6459			break;
6460		case 2:
6461			mec_int_cntl_reg = mmCP_ME1_PIPE2_INT_CNTL;
6462			break;
6463		case 3:
6464			mec_int_cntl_reg = mmCP_ME1_PIPE3_INT_CNTL;
6465			break;
6466		default:
6467			DRM_DEBUG("invalid pipe %d\n", pipe);
6468			return;
6469		}
6470	} else {
6471		DRM_DEBUG("invalid me %d\n", me);
6472		return;
6473	}
6474
6475	switch (state) {
6476	case AMDGPU_IRQ_STATE_DISABLE:
6477		mec_int_cntl = RREG32(mec_int_cntl_reg);
6478		mec_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6479		WREG32(mec_int_cntl_reg, mec_int_cntl);
6480		break;
6481	case AMDGPU_IRQ_STATE_ENABLE:
6482		mec_int_cntl = RREG32(mec_int_cntl_reg);
6483		mec_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6484		WREG32(mec_int_cntl_reg, mec_int_cntl);
6485		break;
6486	default:
6487		break;
6488	}
6489}
6490
6491static int gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
6492					     struct amdgpu_irq_src *source,
6493					     unsigned type,
6494					     enum amdgpu_interrupt_state state)
6495{
6496	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_REG_INT_ENABLE,
6497		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6498
6499	return 0;
6500}
6501
6502static int gfx_v8_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
6503					      struct amdgpu_irq_src *source,
6504					      unsigned type,
6505					      enum amdgpu_interrupt_state state)
6506{
6507	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_INSTR_INT_ENABLE,
6508		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6509
6510	return 0;
6511}
6512
6513static int gfx_v8_0_set_eop_interrupt_state(struct amdgpu_device *adev,
6514					    struct amdgpu_irq_src *src,
6515					    unsigned type,
6516					    enum amdgpu_interrupt_state state)
6517{
6518	switch (type) {
6519	case AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP:
6520		gfx_v8_0_set_gfx_eop_interrupt_state(adev, state);
6521		break;
6522	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP:
6523		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 0, state);
6524		break;
6525	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP:
6526		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 1, state);
6527		break;
6528	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP:
6529		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 2, state);
6530		break;
6531	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP:
6532		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 3, state);
6533		break;
6534	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP:
6535		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 0, state);
6536		break;
6537	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP:
6538		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 1, state);
6539		break;
6540	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP:
6541		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 2, state);
6542		break;
6543	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP:
6544		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 3, state);
6545		break;
6546	default:
6547		break;
6548	}
6549	return 0;
6550}
6551
6552static int gfx_v8_0_set_cp_ecc_int_state(struct amdgpu_device *adev,
6553					 struct amdgpu_irq_src *source,
6554					 unsigned int type,
6555					 enum amdgpu_interrupt_state state)
6556{
6557	int enable_flag;
6558
6559	switch (state) {
6560	case AMDGPU_IRQ_STATE_DISABLE:
6561		enable_flag = 0;
6562		break;
6563
6564	case AMDGPU_IRQ_STATE_ENABLE:
6565		enable_flag = 1;
6566		break;
6567
6568	default:
6569		return -EINVAL;
6570	}
6571
6572	WREG32_FIELD(CP_INT_CNTL, CP_ECC_ERROR_INT_ENABLE, enable_flag);
6573	WREG32_FIELD(CP_INT_CNTL_RING0, CP_ECC_ERROR_INT_ENABLE, enable_flag);
6574	WREG32_FIELD(CP_INT_CNTL_RING1, CP_ECC_ERROR_INT_ENABLE, enable_flag);
6575	WREG32_FIELD(CP_INT_CNTL_RING2, CP_ECC_ERROR_INT_ENABLE, enable_flag);
6576	WREG32_FIELD(CPC_INT_CNTL, CP_ECC_ERROR_INT_ENABLE, enable_flag);
6577	WREG32_FIELD(CP_ME1_PIPE0_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6578		     enable_flag);
6579	WREG32_FIELD(CP_ME1_PIPE1_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6580		     enable_flag);
6581	WREG32_FIELD(CP_ME1_PIPE2_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6582		     enable_flag);
6583	WREG32_FIELD(CP_ME1_PIPE3_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6584		     enable_flag);
6585	WREG32_FIELD(CP_ME2_PIPE0_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6586		     enable_flag);
6587	WREG32_FIELD(CP_ME2_PIPE1_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6588		     enable_flag);
6589	WREG32_FIELD(CP_ME2_PIPE2_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6590		     enable_flag);
6591	WREG32_FIELD(CP_ME2_PIPE3_INT_CNTL, CP_ECC_ERROR_INT_ENABLE,
6592		     enable_flag);
6593
6594	return 0;
6595}
6596
6597static int gfx_v8_0_set_sq_int_state(struct amdgpu_device *adev,
6598				     struct amdgpu_irq_src *source,
6599				     unsigned int type,
6600				     enum amdgpu_interrupt_state state)
6601{
6602	int enable_flag;
6603
6604	switch (state) {
6605	case AMDGPU_IRQ_STATE_DISABLE:
6606		enable_flag = 1;
6607		break;
6608
6609	case AMDGPU_IRQ_STATE_ENABLE:
6610		enable_flag = 0;
6611		break;
6612
6613	default:
6614		return -EINVAL;
6615	}
6616
6617	WREG32_FIELD(SQ_INTERRUPT_MSG_CTRL, STALL,
6618		     enable_flag);
6619
6620	return 0;
6621}
6622
6623static int gfx_v8_0_eop_irq(struct amdgpu_device *adev,
6624			    struct amdgpu_irq_src *source,
6625			    struct amdgpu_iv_entry *entry)
6626{
6627	int i;
6628	u8 me_id, pipe_id, queue_id;
6629	struct amdgpu_ring *ring;
6630
6631	DRM_DEBUG("IH: CP EOP\n");
6632	me_id = (entry->ring_id & 0x0c) >> 2;
6633	pipe_id = (entry->ring_id & 0x03) >> 0;
6634	queue_id = (entry->ring_id & 0x70) >> 4;
6635
6636	switch (me_id) {
6637	case 0:
6638		amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
6639		break;
6640	case 1:
6641	case 2:
6642		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
6643			ring = &adev->gfx.compute_ring[i];
6644			/* Per-queue interrupt is supported for MEC starting from VI.
6645			  * The interrupt can only be enabled/disabled per pipe instead of per queue.
6646			  */
6647			if ((ring->me == me_id) && (ring->pipe == pipe_id) && (ring->queue == queue_id))
6648				amdgpu_fence_process(ring);
6649		}
6650		break;
6651	}
6652	return 0;
6653}
6654
6655static void gfx_v8_0_fault(struct amdgpu_device *adev,
6656			   struct amdgpu_iv_entry *entry)
6657{
6658	u8 me_id, pipe_id, queue_id;
6659	struct amdgpu_ring *ring;
6660	int i;
6661
6662	me_id = (entry->ring_id & 0x0c) >> 2;
6663	pipe_id = (entry->ring_id & 0x03) >> 0;
6664	queue_id = (entry->ring_id & 0x70) >> 4;
6665
6666	switch (me_id) {
6667	case 0:
6668		drm_sched_fault(&adev->gfx.gfx_ring[0].sched);
6669		break;
6670	case 1:
6671	case 2:
6672		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
6673			ring = &adev->gfx.compute_ring[i];
6674			if (ring->me == me_id && ring->pipe == pipe_id &&
6675			    ring->queue == queue_id)
6676				drm_sched_fault(&ring->sched);
6677		}
6678		break;
6679	}
6680}
6681
6682static int gfx_v8_0_priv_reg_irq(struct amdgpu_device *adev,
6683				 struct amdgpu_irq_src *source,
6684				 struct amdgpu_iv_entry *entry)
6685{
6686	DRM_ERROR("Illegal register access in command stream\n");
6687	gfx_v8_0_fault(adev, entry);
6688	return 0;
6689}
6690
6691static int gfx_v8_0_priv_inst_irq(struct amdgpu_device *adev,
6692				  struct amdgpu_irq_src *source,
6693				  struct amdgpu_iv_entry *entry)
6694{
6695	DRM_ERROR("Illegal instruction in command stream\n");
6696	gfx_v8_0_fault(adev, entry);
6697	return 0;
6698}
6699
6700static int gfx_v8_0_cp_ecc_error_irq(struct amdgpu_device *adev,
6701				     struct amdgpu_irq_src *source,
6702				     struct amdgpu_iv_entry *entry)
6703{
6704	DRM_ERROR("CP EDC/ECC error detected.");
6705	return 0;
6706}
6707
6708static void gfx_v8_0_parse_sq_irq(struct amdgpu_device *adev, unsigned ih_data,
6709				  bool from_wq)
6710{
6711	u32 enc, se_id, sh_id, cu_id;
6712	char type[20];
6713	int sq_edc_source = -1;
6714
6715	enc = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_CMN, ENCODING);
6716	se_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_CMN, SE_ID);
6717
6718	switch (enc) {
6719		case 0:
6720			DRM_INFO("SQ general purpose intr detected:"
6721					"se_id %d, immed_overflow %d, host_reg_overflow %d,"
6722					"host_cmd_overflow %d, cmd_timestamp %d,"
6723					"reg_timestamp %d, thread_trace_buff_full %d,"
6724					"wlt %d, thread_trace %d.\n",
6725					se_id,
6726					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, IMMED_OVERFLOW),
6727					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, HOST_REG_OVERFLOW),
6728					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, HOST_CMD_OVERFLOW),
6729					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, CMD_TIMESTAMP),
6730					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, REG_TIMESTAMP),
6731					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, THREAD_TRACE_BUF_FULL),
6732					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, WLT),
6733					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_AUTO, THREAD_TRACE)
6734					);
6735			break;
6736		case 1:
6737		case 2:
6738
6739			cu_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, CU_ID);
6740			sh_id = REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, SH_ID);
6741
6742			/*
6743			 * This function can be called either directly from ISR
6744			 * or from BH in which case we can access SQ_EDC_INFO
6745			 * instance
6746			 */
6747			if (from_wq) {
6748				mutex_lock(&adev->grbm_idx_mutex);
6749				gfx_v8_0_select_se_sh(adev, se_id, sh_id, cu_id, 0);
6750
6751				sq_edc_source = REG_GET_FIELD(RREG32(mmSQ_EDC_INFO), SQ_EDC_INFO, SOURCE);
6752
6753				gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
6754				mutex_unlock(&adev->grbm_idx_mutex);
6755			}
6756
6757			if (enc == 1)
6758				sprintf(type, "instruction intr");
6759			else
6760				sprintf(type, "EDC/ECC error");
6761
6762			DRM_INFO(
6763				"SQ %s detected: "
6764					"se_id %d, sh_id %d, cu_id %d, simd_id %d, wave_id %d, vm_id %d "
6765					"trap %s, sq_ed_info.source %s.\n",
6766					type, se_id, sh_id, cu_id,
6767					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, SIMD_ID),
6768					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, WAVE_ID),
6769					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, VM_ID),
6770					REG_GET_FIELD(ih_data, SQ_INTERRUPT_WORD_WAVE, PRIV) ? "true" : "false",
6771					(sq_edc_source != -1) ? sq_edc_source_names[sq_edc_source] : "unavailable"
6772				);
6773			break;
6774		default:
6775			DRM_ERROR("SQ invalid encoding type\n.");
6776	}
6777}
6778
6779static void gfx_v8_0_sq_irq_work_func(struct work_struct *work)
6780{
6781
6782	struct amdgpu_device *adev = container_of(work, struct amdgpu_device, gfx.sq_work.work);
6783	struct sq_work *sq_work = container_of(work, struct sq_work, work);
6784
6785	gfx_v8_0_parse_sq_irq(adev, sq_work->ih_data, true);
6786}
6787
6788static int gfx_v8_0_sq_irq(struct amdgpu_device *adev,
6789			   struct amdgpu_irq_src *source,
6790			   struct amdgpu_iv_entry *entry)
6791{
6792	unsigned ih_data = entry->src_data[0];
6793
6794	/*
6795	 * Try to submit work so SQ_EDC_INFO can be accessed from
6796	 * BH. If previous work submission hasn't finished yet
6797	 * just print whatever info is possible directly from the ISR.
6798	 */
6799	if (work_pending(&adev->gfx.sq_work.work)) {
6800		gfx_v8_0_parse_sq_irq(adev, ih_data, false);
6801	} else {
6802		adev->gfx.sq_work.ih_data = ih_data;
6803		schedule_work(&adev->gfx.sq_work.work);
6804	}
6805
6806	return 0;
6807}
6808
6809static void gfx_v8_0_emit_mem_sync(struct amdgpu_ring *ring)
6810{
6811	amdgpu_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
6812	amdgpu_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
6813			  PACKET3_TC_ACTION_ENA |
6814			  PACKET3_SH_KCACHE_ACTION_ENA |
6815			  PACKET3_SH_ICACHE_ACTION_ENA |
6816			  PACKET3_TC_WB_ACTION_ENA);  /* CP_COHER_CNTL */
6817	amdgpu_ring_write(ring, 0xffffffff);  /* CP_COHER_SIZE */
6818	amdgpu_ring_write(ring, 0);  /* CP_COHER_BASE */
6819	amdgpu_ring_write(ring, 0x0000000A); /* poll interval */
6820}
6821
6822static void gfx_v8_0_emit_mem_sync_compute(struct amdgpu_ring *ring)
6823{
6824	amdgpu_ring_write(ring, PACKET3(PACKET3_ACQUIRE_MEM, 5));
6825	amdgpu_ring_write(ring, PACKET3_TCL1_ACTION_ENA |
6826			  PACKET3_TC_ACTION_ENA |
6827			  PACKET3_SH_KCACHE_ACTION_ENA |
6828			  PACKET3_SH_ICACHE_ACTION_ENA |
6829			  PACKET3_TC_WB_ACTION_ENA);  /* CP_COHER_CNTL */
6830	amdgpu_ring_write(ring, 0xffffffff);	/* CP_COHER_SIZE */
6831	amdgpu_ring_write(ring, 0xff);		/* CP_COHER_SIZE_HI */
6832	amdgpu_ring_write(ring, 0);		/* CP_COHER_BASE */
6833	amdgpu_ring_write(ring, 0);		/* CP_COHER_BASE_HI */
6834	amdgpu_ring_write(ring, 0x0000000A);	/* poll interval */
6835}
6836
6837
6838/* mmSPI_WCL_PIPE_PERCENT_CS[0-7]_DEFAULT values are same */
6839#define mmSPI_WCL_PIPE_PERCENT_CS_DEFAULT	0x0000007f
6840static void gfx_v8_0_emit_wave_limit_cs(struct amdgpu_ring *ring,
6841					uint32_t pipe, bool enable)
6842{
6843	uint32_t val;
6844	uint32_t wcl_cs_reg;
6845
6846	val = enable ? 0x1 : mmSPI_WCL_PIPE_PERCENT_CS_DEFAULT;
6847
6848	switch (pipe) {
6849	case 0:
6850		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS0;
6851		break;
6852	case 1:
6853		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS1;
6854		break;
6855	case 2:
6856		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS2;
6857		break;
6858	case 3:
6859		wcl_cs_reg = mmSPI_WCL_PIPE_PERCENT_CS3;
6860		break;
6861	default:
6862		DRM_DEBUG("invalid pipe %d\n", pipe);
6863		return;
6864	}
6865
6866	amdgpu_ring_emit_wreg(ring, wcl_cs_reg, val);
6867
6868}
6869
6870#define mmSPI_WCL_PIPE_PERCENT_GFX_DEFAULT	0x07ffffff
6871static void gfx_v8_0_emit_wave_limit(struct amdgpu_ring *ring, bool enable)
6872{
6873	struct amdgpu_device *adev = ring->adev;
6874	uint32_t val;
6875	int i;
6876
6877	/* mmSPI_WCL_PIPE_PERCENT_GFX is 7 bit multiplier register to limit
6878	 * number of gfx waves. Setting 5 bit will make sure gfx only gets
6879	 * around 25% of gpu resources.
6880	 */
6881	val = enable ? 0x1f : mmSPI_WCL_PIPE_PERCENT_GFX_DEFAULT;
6882	amdgpu_ring_emit_wreg(ring, mmSPI_WCL_PIPE_PERCENT_GFX, val);
6883
6884	/* Restrict waves for normal/low priority compute queues as well
6885	 * to get best QoS for high priority compute jobs.
6886	 *
6887	 * amdgpu controls only 1st ME(0-3 CS pipes).
6888	 */
6889	for (i = 0; i < adev->gfx.mec.num_pipe_per_mec; i++) {
6890		if (i != ring->pipe)
6891			gfx_v8_0_emit_wave_limit_cs(ring, i, enable);
6892
6893	}
6894
6895}
6896
6897static int gfx_v8_0_reset_kgq(struct amdgpu_ring *ring, unsigned int vmid)
 
 
6898{
6899	struct amdgpu_device *adev = ring->adev;
6900	struct amdgpu_kiq *kiq = &adev->gfx.kiq[0];
6901	struct amdgpu_ring *kiq_ring = &kiq->ring;
6902	unsigned long flags;
6903	u32 tmp;
6904	int r;
6905
6906	if (amdgpu_sriov_vf(adev))
6907		return -EINVAL;
6908
6909	if (!kiq->pmf || !kiq->pmf->kiq_unmap_queues)
6910		return -EINVAL;
6911
6912	spin_lock_irqsave(&kiq->ring_lock, flags);
6913
6914	if (amdgpu_ring_alloc(kiq_ring, 5)) {
6915		spin_unlock_irqrestore(&kiq->ring_lock, flags);
6916		return -ENOMEM;
6917	}
6918
6919	tmp = REG_SET_FIELD(0, CP_VMID_RESET, RESET_REQUEST, 1 << vmid);
6920	gfx_v8_0_ring_emit_wreg(kiq_ring, mmCP_VMID_RESET, tmp);
6921	amdgpu_ring_commit(kiq_ring);
6922
6923	spin_unlock_irqrestore(&kiq->ring_lock, flags);
6924
6925	r = amdgpu_ring_test_ring(kiq_ring);
6926	if (r)
6927		return r;
6928
6929	if (amdgpu_ring_alloc(ring, 7 + 12 + 5))
6930		return -ENOMEM;
6931	gfx_v8_0_ring_emit_fence_gfx(ring, ring->fence_drv.gpu_addr,
6932				     ring->fence_drv.sync_seq, AMDGPU_FENCE_FLAG_EXEC);
6933	gfx_v8_0_ring_emit_reg_wait(ring, mmCP_VMID_RESET, 0, 0xffff);
6934	gfx_v8_0_ring_emit_wreg(ring, mmCP_VMID_RESET, 0);
6935
6936	return amdgpu_ring_test_ring(ring);
 
6937}
6938
6939static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
6940	.name = "gfx_v8_0",
6941	.early_init = gfx_v8_0_early_init,
6942	.late_init = gfx_v8_0_late_init,
6943	.sw_init = gfx_v8_0_sw_init,
6944	.sw_fini = gfx_v8_0_sw_fini,
6945	.hw_init = gfx_v8_0_hw_init,
6946	.hw_fini = gfx_v8_0_hw_fini,
6947	.suspend = gfx_v8_0_suspend,
6948	.resume = gfx_v8_0_resume,
6949	.is_idle = gfx_v8_0_is_idle,
6950	.wait_for_idle = gfx_v8_0_wait_for_idle,
6951	.check_soft_reset = gfx_v8_0_check_soft_reset,
6952	.pre_soft_reset = gfx_v8_0_pre_soft_reset,
6953	.soft_reset = gfx_v8_0_soft_reset,
6954	.post_soft_reset = gfx_v8_0_post_soft_reset,
6955	.set_clockgating_state = gfx_v8_0_set_clockgating_state,
6956	.set_powergating_state = gfx_v8_0_set_powergating_state,
6957	.get_clockgating_state = gfx_v8_0_get_clockgating_state,
6958};
6959
6960static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = {
6961	.type = AMDGPU_RING_TYPE_GFX,
6962	.align_mask = 0xff,
6963	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
6964	.support_64bit_ptrs = false,
6965	.get_rptr = gfx_v8_0_ring_get_rptr,
6966	.get_wptr = gfx_v8_0_ring_get_wptr_gfx,
6967	.set_wptr = gfx_v8_0_ring_set_wptr_gfx,
6968	.emit_frame_size = /* maximum 215dw if count 16 IBs in */
6969		5 +  /* COND_EXEC */
6970		7 +  /* PIPELINE_SYNC */
6971		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 9 + /* VM_FLUSH */
6972		12 +  /* FENCE for VM_FLUSH */
6973		20 + /* GDS switch */
6974		4 + /* double SWITCH_BUFFER,
6975		       the first COND_EXEC jump to the place just
6976			   prior to this double SWITCH_BUFFER  */
6977		5 + /* COND_EXEC */
6978		7 +	 /*	HDP_flush */
6979		4 +	 /*	VGT_flush */
6980		14 + /*	CE_META */
6981		31 + /*	DE_META */
6982		3 + /* CNTX_CTRL */
6983		5 + /* HDP_INVL */
6984		12 + 12 + /* FENCE x2 */
6985		2 + /* SWITCH_BUFFER */
6986		5, /* SURFACE_SYNC */
6987	.emit_ib_size =	4, /* gfx_v8_0_ring_emit_ib_gfx */
6988	.emit_ib = gfx_v8_0_ring_emit_ib_gfx,
6989	.emit_fence = gfx_v8_0_ring_emit_fence_gfx,
6990	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
6991	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
6992	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
6993	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
6994	.test_ring = gfx_v8_0_ring_test_ring,
6995	.test_ib = gfx_v8_0_ring_test_ib,
6996	.insert_nop = amdgpu_ring_insert_nop,
6997	.pad_ib = amdgpu_ring_generic_pad_ib,
6998	.emit_switch_buffer = gfx_v8_ring_emit_sb,
6999	.emit_cntxcntl = gfx_v8_ring_emit_cntxcntl,
7000	.init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec,
 
7001	.emit_wreg = gfx_v8_0_ring_emit_wreg,
7002	.soft_recovery = gfx_v8_0_ring_soft_recovery,
7003	.emit_mem_sync = gfx_v8_0_emit_mem_sync,
7004	.reset = gfx_v8_0_reset_kgq,
7005};
7006
7007static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = {
7008	.type = AMDGPU_RING_TYPE_COMPUTE,
7009	.align_mask = 0xff,
7010	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
7011	.support_64bit_ptrs = false,
7012	.get_rptr = gfx_v8_0_ring_get_rptr,
7013	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
7014	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
7015	.emit_frame_size =
7016		20 + /* gfx_v8_0_ring_emit_gds_switch */
7017		7 + /* gfx_v8_0_ring_emit_hdp_flush */
7018		5 + /* hdp_invalidate */
7019		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
7020		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 7 + /* gfx_v8_0_ring_emit_vm_flush */
7021		7 + 7 + 7 + /* gfx_v8_0_ring_emit_fence_compute x3 for user fence, vm fence */
7022		7 + /* gfx_v8_0_emit_mem_sync_compute */
7023		5 + /* gfx_v8_0_emit_wave_limit for updating mmSPI_WCL_PIPE_PERCENT_GFX register */
7024		15, /* for updating 3 mmSPI_WCL_PIPE_PERCENT_CS registers */
7025	.emit_ib_size =	7, /* gfx_v8_0_ring_emit_ib_compute */
7026	.emit_ib = gfx_v8_0_ring_emit_ib_compute,
7027	.emit_fence = gfx_v8_0_ring_emit_fence_compute,
7028	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
7029	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
7030	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
7031	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
7032	.test_ring = gfx_v8_0_ring_test_ring,
7033	.test_ib = gfx_v8_0_ring_test_ib,
7034	.insert_nop = amdgpu_ring_insert_nop,
7035	.pad_ib = amdgpu_ring_generic_pad_ib,
 
7036	.emit_wreg = gfx_v8_0_ring_emit_wreg,
7037	.soft_recovery = gfx_v8_0_ring_soft_recovery,
7038	.emit_mem_sync = gfx_v8_0_emit_mem_sync_compute,
7039	.emit_wave_limit = gfx_v8_0_emit_wave_limit,
7040};
7041
7042static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_kiq = {
7043	.type = AMDGPU_RING_TYPE_KIQ,
7044	.align_mask = 0xff,
7045	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
7046	.support_64bit_ptrs = false,
7047	.get_rptr = gfx_v8_0_ring_get_rptr,
7048	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
7049	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
7050	.emit_frame_size =
7051		20 + /* gfx_v8_0_ring_emit_gds_switch */
7052		7 + /* gfx_v8_0_ring_emit_hdp_flush */
7053		5 + /* hdp_invalidate */
7054		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
7055		17 + /* gfx_v8_0_ring_emit_vm_flush */
7056		7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_kiq x3 for user fence, vm fence */
7057	.emit_ib_size =	7, /* gfx_v8_0_ring_emit_ib_compute */
 
7058	.emit_fence = gfx_v8_0_ring_emit_fence_kiq,
7059	.test_ring = gfx_v8_0_ring_test_ring,
 
7060	.insert_nop = amdgpu_ring_insert_nop,
7061	.pad_ib = amdgpu_ring_generic_pad_ib,
7062	.emit_rreg = gfx_v8_0_ring_emit_rreg,
7063	.emit_wreg = gfx_v8_0_ring_emit_wreg,
7064};
7065
7066static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev)
7067{
7068	int i;
7069
7070	adev->gfx.kiq[0].ring.funcs = &gfx_v8_0_ring_funcs_kiq;
7071
7072	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
7073		adev->gfx.gfx_ring[i].funcs = &gfx_v8_0_ring_funcs_gfx;
7074
7075	for (i = 0; i < adev->gfx.num_compute_rings; i++)
7076		adev->gfx.compute_ring[i].funcs = &gfx_v8_0_ring_funcs_compute;
7077}
7078
7079static const struct amdgpu_irq_src_funcs gfx_v8_0_eop_irq_funcs = {
7080	.set = gfx_v8_0_set_eop_interrupt_state,
7081	.process = gfx_v8_0_eop_irq,
7082};
7083
7084static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_reg_irq_funcs = {
7085	.set = gfx_v8_0_set_priv_reg_fault_state,
7086	.process = gfx_v8_0_priv_reg_irq,
7087};
7088
7089static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_inst_irq_funcs = {
7090	.set = gfx_v8_0_set_priv_inst_fault_state,
7091	.process = gfx_v8_0_priv_inst_irq,
7092};
7093
7094static const struct amdgpu_irq_src_funcs gfx_v8_0_cp_ecc_error_irq_funcs = {
7095	.set = gfx_v8_0_set_cp_ecc_int_state,
7096	.process = gfx_v8_0_cp_ecc_error_irq,
7097};
7098
7099static const struct amdgpu_irq_src_funcs gfx_v8_0_sq_irq_funcs = {
7100	.set = gfx_v8_0_set_sq_int_state,
7101	.process = gfx_v8_0_sq_irq,
7102};
7103
7104static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev)
7105{
7106	adev->gfx.eop_irq.num_types = AMDGPU_CP_IRQ_LAST;
7107	adev->gfx.eop_irq.funcs = &gfx_v8_0_eop_irq_funcs;
7108
7109	adev->gfx.priv_reg_irq.num_types = 1;
7110	adev->gfx.priv_reg_irq.funcs = &gfx_v8_0_priv_reg_irq_funcs;
7111
7112	adev->gfx.priv_inst_irq.num_types = 1;
7113	adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs;
7114
7115	adev->gfx.cp_ecc_error_irq.num_types = 1;
7116	adev->gfx.cp_ecc_error_irq.funcs = &gfx_v8_0_cp_ecc_error_irq_funcs;
7117
7118	adev->gfx.sq_irq.num_types = 1;
7119	adev->gfx.sq_irq.funcs = &gfx_v8_0_sq_irq_funcs;
7120}
7121
7122static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev)
7123{
7124	adev->gfx.rlc.funcs = &iceland_rlc_funcs;
7125}
7126
7127static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev)
7128{
7129	/* init asci gds info */
7130	adev->gds.gds_size = RREG32(mmGDS_VMID0_SIZE);
7131	adev->gds.gws_size = 64;
7132	adev->gds.oa_size = 16;
7133	adev->gds.gds_compute_max_wave_id = RREG32(mmGDS_COMPUTE_MAX_WAVE_ID);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7134}
7135
7136static void gfx_v8_0_set_user_cu_inactive_bitmap(struct amdgpu_device *adev,
7137						 u32 bitmap)
7138{
7139	u32 data;
7140
7141	if (!bitmap)
7142		return;
7143
7144	data = bitmap << GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
7145	data &= GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
7146
7147	WREG32(mmGC_USER_SHADER_ARRAY_CONFIG, data);
7148}
7149
7150static u32 gfx_v8_0_get_cu_active_bitmap(struct amdgpu_device *adev)
7151{
7152	u32 data, mask;
7153
7154	data =  RREG32(mmCC_GC_SHADER_ARRAY_CONFIG) |
7155		RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
7156
7157	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_cu_per_sh);
7158
7159	return ~REG_GET_FIELD(data, CC_GC_SHADER_ARRAY_CONFIG, INACTIVE_CUS) & mask;
7160}
7161
7162static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
7163{
7164	int i, j, k, counter, active_cu_number = 0;
7165	u32 mask, bitmap, ao_bitmap, ao_cu_mask = 0;
7166	struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info;
7167	unsigned disable_masks[4 * 2];
7168	u32 ao_cu_num;
7169
7170	memset(cu_info, 0, sizeof(*cu_info));
7171
7172	if (adev->flags & AMD_IS_APU)
7173		ao_cu_num = 2;
7174	else
7175		ao_cu_num = adev->gfx.config.max_cu_per_sh;
7176
7177	amdgpu_gfx_parse_disable_cu(disable_masks, 4, 2);
7178
7179	mutex_lock(&adev->grbm_idx_mutex);
7180	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
7181		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
7182			mask = 1;
7183			ao_bitmap = 0;
7184			counter = 0;
7185			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff, 0);
7186			if (i < 4 && j < 2)
7187				gfx_v8_0_set_user_cu_inactive_bitmap(
7188					adev, disable_masks[i * 2 + j]);
7189			bitmap = gfx_v8_0_get_cu_active_bitmap(adev);
7190			cu_info->bitmap[0][i][j] = bitmap;
7191
7192			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
7193				if (bitmap & mask) {
7194					if (counter < ao_cu_num)
7195						ao_bitmap |= mask;
7196					counter ++;
7197				}
7198				mask <<= 1;
7199			}
7200			active_cu_number += counter;
7201			if (i < 2 && j < 2)
7202				ao_cu_mask |= (ao_bitmap << (i * 16 + j * 8));
7203			cu_info->ao_cu_bitmap[i][j] = ao_bitmap;
7204		}
7205	}
7206	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
7207	mutex_unlock(&adev->grbm_idx_mutex);
7208
7209	cu_info->number = active_cu_number;
7210	cu_info->ao_cu_mask = ao_cu_mask;
7211	cu_info->simd_per_cu = NUM_SIMD_PER_CU;
7212	cu_info->max_waves_per_simd = 10;
7213	cu_info->max_scratch_slots_per_cu = 32;
7214	cu_info->wave_front_size = 64;
7215	cu_info->lds_size = 64;
7216}
7217
7218const struct amdgpu_ip_block_version gfx_v8_0_ip_block =
7219{
7220	.type = AMD_IP_BLOCK_TYPE_GFX,
7221	.major = 8,
7222	.minor = 0,
7223	.rev = 0,
7224	.funcs = &gfx_v8_0_ip_funcs,
7225};
7226
7227const struct amdgpu_ip_block_version gfx_v8_1_ip_block =
7228{
7229	.type = AMD_IP_BLOCK_TYPE_GFX,
7230	.major = 8,
7231	.minor = 1,
7232	.rev = 0,
7233	.funcs = &gfx_v8_0_ip_funcs,
7234};
7235
7236static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
7237{
7238	uint64_t ce_payload_addr;
7239	int cnt_ce;
7240	union {
7241		struct vi_ce_ib_state regular;
7242		struct vi_ce_ib_state_chained_ib chained;
7243	} ce_payload = {};
7244
7245	if (ring->adev->virt.chained_ib_support) {
7246		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
7247			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
7248		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
7249	} else {
7250		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
7251			offsetof(struct vi_gfx_meta_data, ce_payload);
7252		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
7253	}
7254
7255	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_ce));
7256	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
7257				WRITE_DATA_DST_SEL(8) |
7258				WR_CONFIRM) |
7259				WRITE_DATA_CACHE_POLICY(0));
7260	amdgpu_ring_write(ring, lower_32_bits(ce_payload_addr));
7261	amdgpu_ring_write(ring, upper_32_bits(ce_payload_addr));
7262	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
7263}
7264
7265static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
7266{
7267	uint64_t de_payload_addr, gds_addr, csa_addr;
7268	int cnt_de;
7269	union {
7270		struct vi_de_ib_state regular;
7271		struct vi_de_ib_state_chained_ib chained;
7272	} de_payload = {};
7273
7274	csa_addr = amdgpu_csa_vaddr(ring->adev);
7275	gds_addr = csa_addr + 4096;
7276	if (ring->adev->virt.chained_ib_support) {
7277		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
7278		de_payload.chained.gds_backup_addrhi = upper_32_bits(gds_addr);
7279		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data_chained_ib, de_payload);
7280		cnt_de = (sizeof(de_payload.chained) >> 2) + 4 - 2;
7281	} else {
7282		de_payload.regular.gds_backup_addrlo = lower_32_bits(gds_addr);
7283		de_payload.regular.gds_backup_addrhi = upper_32_bits(gds_addr);
7284		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data, de_payload);
7285		cnt_de = (sizeof(de_payload.regular) >> 2) + 4 - 2;
7286	}
7287
7288	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_de));
7289	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(1) |
7290				WRITE_DATA_DST_SEL(8) |
7291				WR_CONFIRM) |
7292				WRITE_DATA_CACHE_POLICY(0));
7293	amdgpu_ring_write(ring, lower_32_bits(de_payload_addr));
7294	amdgpu_ring_write(ring, upper_32_bits(de_payload_addr));
7295	amdgpu_ring_write_multiple(ring, (void *)&de_payload, cnt_de - 2);
7296}
v4.17
   1/*
   2 * Copyright 2014 Advanced Micro Devices, Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 */
 
 
  23#include <linux/kernel.h>
  24#include <linux/firmware.h>
  25#include <drm/drmP.h>
 
 
  26#include "amdgpu.h"
  27#include "amdgpu_gfx.h"
 
  28#include "vi.h"
  29#include "vi_structs.h"
  30#include "vid.h"
  31#include "amdgpu_ucode.h"
  32#include "amdgpu_atombios.h"
  33#include "atombios_i2c.h"
  34#include "clearstate_vi.h"
  35
  36#include "gmc/gmc_8_2_d.h"
  37#include "gmc/gmc_8_2_sh_mask.h"
  38
  39#include "oss/oss_3_0_d.h"
  40#include "oss/oss_3_0_sh_mask.h"
  41
  42#include "bif/bif_5_0_d.h"
  43#include "bif/bif_5_0_sh_mask.h"
  44#include "gca/gfx_8_0_d.h"
  45#include "gca/gfx_8_0_enum.h"
  46#include "gca/gfx_8_0_sh_mask.h"
  47#include "gca/gfx_8_0_enum.h"
  48
  49#include "dce/dce_10_0_d.h"
  50#include "dce/dce_10_0_sh_mask.h"
  51
  52#include "smu/smu_7_1_3_d.h"
  53
 
 
  54#define GFX8_NUM_GFX_RINGS     1
  55#define GFX8_MEC_HPD_SIZE 2048
  56
  57#define TOPAZ_GB_ADDR_CONFIG_GOLDEN 0x22010001
  58#define CARRIZO_GB_ADDR_CONFIG_GOLDEN 0x22010001
  59#define POLARIS11_GB_ADDR_CONFIG_GOLDEN 0x22011002
  60#define TONGA_GB_ADDR_CONFIG_GOLDEN 0x22011003
  61
  62#define ARRAY_MODE(x)					((x) << GB_TILE_MODE0__ARRAY_MODE__SHIFT)
  63#define PIPE_CONFIG(x)					((x) << GB_TILE_MODE0__PIPE_CONFIG__SHIFT)
  64#define TILE_SPLIT(x)					((x) << GB_TILE_MODE0__TILE_SPLIT__SHIFT)
  65#define MICRO_TILE_MODE_NEW(x)				((x) << GB_TILE_MODE0__MICRO_TILE_MODE_NEW__SHIFT)
  66#define SAMPLE_SPLIT(x)					((x) << GB_TILE_MODE0__SAMPLE_SPLIT__SHIFT)
  67#define BANK_WIDTH(x)					((x) << GB_MACROTILE_MODE0__BANK_WIDTH__SHIFT)
  68#define BANK_HEIGHT(x)					((x) << GB_MACROTILE_MODE0__BANK_HEIGHT__SHIFT)
  69#define MACRO_TILE_ASPECT(x)				((x) << GB_MACROTILE_MODE0__MACRO_TILE_ASPECT__SHIFT)
  70#define NUM_BANKS(x)					((x) << GB_MACROTILE_MODE0__NUM_BANKS__SHIFT)
  71
  72#define RLC_CGTT_MGCG_OVERRIDE__CPF_MASK            0x00000001L
  73#define RLC_CGTT_MGCG_OVERRIDE__RLC_MASK            0x00000002L
  74#define RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK           0x00000004L
  75#define RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK           0x00000008L
  76#define RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK           0x00000010L
  77#define RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK           0x00000020L
  78
  79/* BPM SERDES CMD */
  80#define SET_BPM_SERDES_CMD    1
  81#define CLE_BPM_SERDES_CMD    0
  82
  83/* BPM Register Address*/
  84enum {
  85	BPM_REG_CGLS_EN = 0,        /* Enable/Disable CGLS */
  86	BPM_REG_CGLS_ON,            /* ON/OFF CGLS: shall be controlled by RLC FW */
  87	BPM_REG_CGCG_OVERRIDE,      /* Set/Clear CGCG Override */
  88	BPM_REG_MGCG_OVERRIDE,      /* Set/Clear MGCG Override */
  89	BPM_REG_FGCG_OVERRIDE,      /* Set/Clear FGCG Override */
  90	BPM_REG_FGCG_MAX
  91};
  92
  93#define RLC_FormatDirectRegListLength        14
  94
  95MODULE_FIRMWARE("amdgpu/carrizo_ce.bin");
  96MODULE_FIRMWARE("amdgpu/carrizo_pfp.bin");
  97MODULE_FIRMWARE("amdgpu/carrizo_me.bin");
  98MODULE_FIRMWARE("amdgpu/carrizo_mec.bin");
  99MODULE_FIRMWARE("amdgpu/carrizo_mec2.bin");
 100MODULE_FIRMWARE("amdgpu/carrizo_rlc.bin");
 101
 102MODULE_FIRMWARE("amdgpu/stoney_ce.bin");
 103MODULE_FIRMWARE("amdgpu/stoney_pfp.bin");
 104MODULE_FIRMWARE("amdgpu/stoney_me.bin");
 105MODULE_FIRMWARE("amdgpu/stoney_mec.bin");
 106MODULE_FIRMWARE("amdgpu/stoney_rlc.bin");
 107
 108MODULE_FIRMWARE("amdgpu/tonga_ce.bin");
 109MODULE_FIRMWARE("amdgpu/tonga_pfp.bin");
 110MODULE_FIRMWARE("amdgpu/tonga_me.bin");
 111MODULE_FIRMWARE("amdgpu/tonga_mec.bin");
 112MODULE_FIRMWARE("amdgpu/tonga_mec2.bin");
 113MODULE_FIRMWARE("amdgpu/tonga_rlc.bin");
 114
 115MODULE_FIRMWARE("amdgpu/topaz_ce.bin");
 116MODULE_FIRMWARE("amdgpu/topaz_pfp.bin");
 117MODULE_FIRMWARE("amdgpu/topaz_me.bin");
 118MODULE_FIRMWARE("amdgpu/topaz_mec.bin");
 119MODULE_FIRMWARE("amdgpu/topaz_rlc.bin");
 120
 121MODULE_FIRMWARE("amdgpu/fiji_ce.bin");
 122MODULE_FIRMWARE("amdgpu/fiji_pfp.bin");
 123MODULE_FIRMWARE("amdgpu/fiji_me.bin");
 124MODULE_FIRMWARE("amdgpu/fiji_mec.bin");
 125MODULE_FIRMWARE("amdgpu/fiji_mec2.bin");
 126MODULE_FIRMWARE("amdgpu/fiji_rlc.bin");
 127
 
 
 
 
 
 
 
 
 
 
 
 
 128MODULE_FIRMWARE("amdgpu/polaris11_ce.bin");
 129MODULE_FIRMWARE("amdgpu/polaris11_ce_2.bin");
 130MODULE_FIRMWARE("amdgpu/polaris11_pfp.bin");
 131MODULE_FIRMWARE("amdgpu/polaris11_pfp_2.bin");
 132MODULE_FIRMWARE("amdgpu/polaris11_me.bin");
 133MODULE_FIRMWARE("amdgpu/polaris11_me_2.bin");
 134MODULE_FIRMWARE("amdgpu/polaris11_mec.bin");
 135MODULE_FIRMWARE("amdgpu/polaris11_mec_2.bin");
 136MODULE_FIRMWARE("amdgpu/polaris11_mec2.bin");
 137MODULE_FIRMWARE("amdgpu/polaris11_mec2_2.bin");
 138MODULE_FIRMWARE("amdgpu/polaris11_rlc.bin");
 139
 140MODULE_FIRMWARE("amdgpu/polaris10_ce.bin");
 141MODULE_FIRMWARE("amdgpu/polaris10_ce_2.bin");
 142MODULE_FIRMWARE("amdgpu/polaris10_pfp.bin");
 143MODULE_FIRMWARE("amdgpu/polaris10_pfp_2.bin");
 144MODULE_FIRMWARE("amdgpu/polaris10_me.bin");
 145MODULE_FIRMWARE("amdgpu/polaris10_me_2.bin");
 146MODULE_FIRMWARE("amdgpu/polaris10_mec.bin");
 147MODULE_FIRMWARE("amdgpu/polaris10_mec_2.bin");
 148MODULE_FIRMWARE("amdgpu/polaris10_mec2.bin");
 149MODULE_FIRMWARE("amdgpu/polaris10_mec2_2.bin");
 150MODULE_FIRMWARE("amdgpu/polaris10_rlc.bin");
 151
 152MODULE_FIRMWARE("amdgpu/polaris12_ce.bin");
 153MODULE_FIRMWARE("amdgpu/polaris12_ce_2.bin");
 154MODULE_FIRMWARE("amdgpu/polaris12_pfp.bin");
 155MODULE_FIRMWARE("amdgpu/polaris12_pfp_2.bin");
 156MODULE_FIRMWARE("amdgpu/polaris12_me.bin");
 157MODULE_FIRMWARE("amdgpu/polaris12_me_2.bin");
 158MODULE_FIRMWARE("amdgpu/polaris12_mec.bin");
 159MODULE_FIRMWARE("amdgpu/polaris12_mec_2.bin");
 160MODULE_FIRMWARE("amdgpu/polaris12_mec2.bin");
 161MODULE_FIRMWARE("amdgpu/polaris12_mec2_2.bin");
 162MODULE_FIRMWARE("amdgpu/polaris12_rlc.bin");
 163
 
 
 
 
 
 
 
 164static const struct amdgpu_gds_reg_offset amdgpu_gds_reg_offset[] =
 165{
 166	{mmGDS_VMID0_BASE, mmGDS_VMID0_SIZE, mmGDS_GWS_VMID0, mmGDS_OA_VMID0},
 167	{mmGDS_VMID1_BASE, mmGDS_VMID1_SIZE, mmGDS_GWS_VMID1, mmGDS_OA_VMID1},
 168	{mmGDS_VMID2_BASE, mmGDS_VMID2_SIZE, mmGDS_GWS_VMID2, mmGDS_OA_VMID2},
 169	{mmGDS_VMID3_BASE, mmGDS_VMID3_SIZE, mmGDS_GWS_VMID3, mmGDS_OA_VMID3},
 170	{mmGDS_VMID4_BASE, mmGDS_VMID4_SIZE, mmGDS_GWS_VMID4, mmGDS_OA_VMID4},
 171	{mmGDS_VMID5_BASE, mmGDS_VMID5_SIZE, mmGDS_GWS_VMID5, mmGDS_OA_VMID5},
 172	{mmGDS_VMID6_BASE, mmGDS_VMID6_SIZE, mmGDS_GWS_VMID6, mmGDS_OA_VMID6},
 173	{mmGDS_VMID7_BASE, mmGDS_VMID7_SIZE, mmGDS_GWS_VMID7, mmGDS_OA_VMID7},
 174	{mmGDS_VMID8_BASE, mmGDS_VMID8_SIZE, mmGDS_GWS_VMID8, mmGDS_OA_VMID8},
 175	{mmGDS_VMID9_BASE, mmGDS_VMID9_SIZE, mmGDS_GWS_VMID9, mmGDS_OA_VMID9},
 176	{mmGDS_VMID10_BASE, mmGDS_VMID10_SIZE, mmGDS_GWS_VMID10, mmGDS_OA_VMID10},
 177	{mmGDS_VMID11_BASE, mmGDS_VMID11_SIZE, mmGDS_GWS_VMID11, mmGDS_OA_VMID11},
 178	{mmGDS_VMID12_BASE, mmGDS_VMID12_SIZE, mmGDS_GWS_VMID12, mmGDS_OA_VMID12},
 179	{mmGDS_VMID13_BASE, mmGDS_VMID13_SIZE, mmGDS_GWS_VMID13, mmGDS_OA_VMID13},
 180	{mmGDS_VMID14_BASE, mmGDS_VMID14_SIZE, mmGDS_GWS_VMID14, mmGDS_OA_VMID14},
 181	{mmGDS_VMID15_BASE, mmGDS_VMID15_SIZE, mmGDS_GWS_VMID15, mmGDS_OA_VMID15}
 182};
 183
 184static const u32 golden_settings_tonga_a11[] =
 185{
 186	mmCB_HW_CONTROL, 0xfffdf3cf, 0x00007208,
 187	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 188	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 189	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 190	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 191	mmPA_SC_FIFO_DEPTH_CNTL, 0x000003ff, 0x000000fc,
 192	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 193	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 194	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 195	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 196	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 197	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 198	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000002fb,
 199	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x0000543b,
 200	mmTCP_CHAN_STEER_LO, 0xffffffff, 0xa9210876,
 201	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 202};
 203
 204static const u32 tonga_golden_common_all[] =
 205{
 206	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 207	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
 208	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
 209	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 210	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 211	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 212	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 213	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 214};
 215
 216static const u32 tonga_mgcg_cgcg_init[] =
 217{
 218	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 219	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 220	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 221	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 222	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 223	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 224	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
 225	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 226	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 227	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 228	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 229	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 230	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 231	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 232	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 233	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 234	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 235	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 236	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 237	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 238	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 239	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 240	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 241	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 242	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 243	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 244	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 245	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 246	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 247	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 248	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 249	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 250	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 251	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 252	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 253	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 254	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 255	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 256	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 257	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 258	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 259	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 260	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 261	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 262	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 263	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 264	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 265	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 266	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 267	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 268	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 269	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 270	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 271	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 272	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 273	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 274	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 275	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 276	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 277	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 278	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 279	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 280	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 281	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
 282	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 283	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 284	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 285	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 286	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
 287	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 288	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 289	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 290	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 291	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 292	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 293};
 294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 295static const u32 golden_settings_polaris11_a11[] =
 296{
 297	mmCB_HW_CONTROL, 0x0000f3cf, 0x00007208,
 298	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
 299	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 300	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 301	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 302	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 303	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
 304	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
 305	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 306	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 307	mmSQ_CONFIG, 0x07f80000, 0x01180000,
 308	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 309	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 310	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f3,
 311	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 312	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00003210,
 313	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 314};
 315
 316static const u32 polaris11_golden_common_all[] =
 317{
 318	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 319	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011002,
 320	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 321	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 322	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 323	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 324};
 325
 326static const u32 golden_settings_polaris10_a11[] =
 327{
 328	mmATC_MISC_CG, 0x000c0fc0, 0x000c0200,
 329	mmCB_HW_CONTROL, 0x0001f3cf, 0x00007208,
 330	mmCB_HW_CONTROL_2, 0x0f000000, 0x0f000000,
 331	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 332	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 333	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 334	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 335	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x16000012,
 336	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x0000002a,
 337	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 338	mmRLC_CGCG_CGLS_CTRL_3D, 0xffffffff, 0x0001003c,
 339	mmSQ_CONFIG, 0x07f80000, 0x07180000,
 340	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 341	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 342	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f7,
 343	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 344	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 345};
 346
 347static const u32 polaris10_golden_common_all[] =
 348{
 349	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 350	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x16000012,
 351	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002A,
 352	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 353	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 354	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 355	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 356	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 357};
 358
 359static const u32 fiji_golden_common_all[] =
 360{
 361	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 362	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x3a00161a,
 363	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x0000002e,
 364	mmGB_ADDR_CONFIG, 0xffffffff, 0x22011003,
 365	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 366	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 367	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 368	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 369	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 370	mmSPI_CONFIG_CNTL_1, 0x0000000f, 0x00000009,
 371};
 372
 373static const u32 golden_settings_fiji_a10[] =
 374{
 375	mmCB_HW_CONTROL_3, 0x000001ff, 0x00000040,
 376	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 377	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 378	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 379	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 380	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 381	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 382	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 383	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 384	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000ff,
 385	mmVGT_RESET_DEBUG, 0x00000004, 0x00000004,
 386};
 387
 388static const u32 fiji_mgcg_cgcg_init[] =
 389{
 390	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 391	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 392	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 393	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 394	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 395	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 396	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x40000100,
 397	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 398	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 399	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 400	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 401	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 402	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 403	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 404	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 405	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 406	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 407	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 408	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 409	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 410	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 411	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 412	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 413	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 414	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 415	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 416	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 417	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 418	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 419	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 420	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 421	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 422	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 423	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 424	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 425};
 426
 427static const u32 golden_settings_iceland_a11[] =
 428{
 429	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 430	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 431	mmDB_DEBUG3, 0xc0000000, 0xc0000000,
 432	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 433	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 434	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 435	mmPA_SC_RASTER_CONFIG, 0x3f3fffff, 0x00000002,
 436	mmPA_SC_RASTER_CONFIG_1, 0x0000003f, 0x00000000,
 437	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 438	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 439	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 440	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 441	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 442	mmTCP_ADDR_CONFIG, 0x000003ff, 0x000000f1,
 443	mmTCP_CHAN_STEER_HI, 0xffffffff, 0x00000000,
 444	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00000010,
 445};
 446
 447static const u32 iceland_golden_common_all[] =
 448{
 449	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 450	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
 451	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 452	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
 453	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 454	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 455	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 456	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 457};
 458
 459static const u32 iceland_mgcg_cgcg_init[] =
 460{
 461	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 462	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 463	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 464	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 465	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0xc0000100,
 466	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0xc0000100,
 467	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0xc0000100,
 468	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 469	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 470	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 471	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 472	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 473	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 474	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 475	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 476	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 477	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 478	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 479	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 480	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 481	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 482	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 483	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0xff000100,
 484	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 485	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 486	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 487	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 488	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 489	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 490	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 491	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 492	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 493	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 494	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
 495	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 496	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 497	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 498	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 499	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 500	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 501	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 502	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 503	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 504	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 505	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 506	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 507	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 508	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 509	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 510	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 511	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 512	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 513	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 514	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x0f840f87,
 515	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 516	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 517	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 518	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 519	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 520	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 521	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 522	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 523	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 524	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003c,
 525};
 526
 527static const u32 cz_golden_settings_a11[] =
 528{
 529	mmCB_HW_CONTROL_3, 0x00000040, 0x00000040,
 530	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 531	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 532	mmPA_SC_ENHANCE, 0xffffffff, 0x00000001,
 533	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 534	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0000003c,
 535	mmSQ_RANDOM_WAVE_PRI, 0x001fffff, 0x000006fd,
 536	mmTA_CNTL_AUX, 0x000f000f, 0x00010000,
 537	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 538	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 539	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f3,
 540	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x00001302
 541};
 542
 543static const u32 cz_golden_common_all[] =
 544{
 545	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 546	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000002,
 547	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 548	mmGB_ADDR_CONFIG, 0xffffffff, 0x22010001,
 549	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 550	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 551	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 552	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF
 553};
 554
 555static const u32 cz_mgcg_cgcg_init[] =
 556{
 557	mmRLC_CGTT_MGCG_OVERRIDE, 0xffffffff, 0xffffffff,
 558	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 559	mmCB_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 560	mmCGTT_BCI_CLK_CTRL, 0xffffffff, 0x00000100,
 561	mmCGTT_CP_CLK_CTRL, 0xffffffff, 0x00000100,
 562	mmCGTT_CPC_CLK_CTRL, 0xffffffff, 0x00000100,
 563	mmCGTT_CPF_CLK_CTRL, 0xffffffff, 0x00000100,
 564	mmCGTT_GDS_CLK_CTRL, 0xffffffff, 0x00000100,
 565	mmCGTT_IA_CLK_CTRL, 0xffffffff, 0x06000100,
 566	mmCGTT_PA_CLK_CTRL, 0xffffffff, 0x00000100,
 567	mmCGTT_WD_CLK_CTRL, 0xffffffff, 0x06000100,
 568	mmCGTT_PC_CLK_CTRL, 0xffffffff, 0x00000100,
 569	mmCGTT_RLC_CLK_CTRL, 0xffffffff, 0x00000100,
 570	mmCGTT_SC_CLK_CTRL, 0xffffffff, 0x00000100,
 571	mmCGTT_SPI_CLK_CTRL, 0xffffffff, 0x00000100,
 572	mmCGTT_SQ_CLK_CTRL, 0xffffffff, 0x00000100,
 573	mmCGTT_SQG_CLK_CTRL, 0xffffffff, 0x00000100,
 574	mmCGTT_SX_CLK_CTRL0, 0xffffffff, 0x00000100,
 575	mmCGTT_SX_CLK_CTRL1, 0xffffffff, 0x00000100,
 576	mmCGTT_SX_CLK_CTRL2, 0xffffffff, 0x00000100,
 577	mmCGTT_SX_CLK_CTRL3, 0xffffffff, 0x00000100,
 578	mmCGTT_SX_CLK_CTRL4, 0xffffffff, 0x00000100,
 579	mmCGTT_TCI_CLK_CTRL, 0xffffffff, 0x00000100,
 580	mmCGTT_TCP_CLK_CTRL, 0xffffffff, 0x00000100,
 581	mmCGTT_VGT_CLK_CTRL, 0xffffffff, 0x06000100,
 582	mmDB_CGTT_CLK_CTRL_0, 0xffffffff, 0x00000100,
 583	mmTA_CGTT_CTRL, 0xffffffff, 0x00000100,
 584	mmTCA_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 585	mmTCC_CGTT_SCLK_CTRL, 0xffffffff, 0x00000100,
 586	mmTD_CGTT_CTRL, 0xffffffff, 0x00000100,
 587	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 588	mmCGTS_CU0_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 589	mmCGTS_CU0_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 590	mmCGTS_CU0_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 591	mmCGTS_CU0_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 592	mmCGTS_CU0_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 593	mmCGTS_CU1_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 594	mmCGTS_CU1_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 595	mmCGTS_CU1_TA_CTRL_REG, 0xffffffff, 0x00040007,
 596	mmCGTS_CU1_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 597	mmCGTS_CU1_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 598	mmCGTS_CU2_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 599	mmCGTS_CU2_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 600	mmCGTS_CU2_TA_CTRL_REG, 0xffffffff, 0x00040007,
 601	mmCGTS_CU2_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 602	mmCGTS_CU2_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 603	mmCGTS_CU3_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 604	mmCGTS_CU3_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 605	mmCGTS_CU3_TA_CTRL_REG, 0xffffffff, 0x00040007,
 606	mmCGTS_CU3_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 607	mmCGTS_CU3_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 608	mmCGTS_CU4_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 609	mmCGTS_CU4_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 610	mmCGTS_CU4_TA_SQC_CTRL_REG, 0xffffffff, 0x00040007,
 611	mmCGTS_CU4_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 612	mmCGTS_CU4_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 613	mmCGTS_CU5_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 614	mmCGTS_CU5_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 615	mmCGTS_CU5_TA_CTRL_REG, 0xffffffff, 0x00040007,
 616	mmCGTS_CU5_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 617	mmCGTS_CU5_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 618	mmCGTS_CU6_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 619	mmCGTS_CU6_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 620	mmCGTS_CU6_TA_CTRL_REG, 0xffffffff, 0x00040007,
 621	mmCGTS_CU6_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 622	mmCGTS_CU6_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 623	mmCGTS_CU7_SP0_CTRL_REG, 0xffffffff, 0x00010000,
 624	mmCGTS_CU7_LDS_SQ_CTRL_REG, 0xffffffff, 0x00030002,
 625	mmCGTS_CU7_TA_CTRL_REG, 0xffffffff, 0x00040007,
 626	mmCGTS_CU7_SP1_CTRL_REG, 0xffffffff, 0x00060005,
 627	mmCGTS_CU7_TD_TCP_CTRL_REG, 0xffffffff, 0x00090008,
 628	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96e00200,
 629	mmCP_RB_WPTR_POLL_CNTL, 0xffffffff, 0x00900100,
 630	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
 631	mmCP_MEM_SLP_CNTL, 0x00000001, 0x00000001,
 632};
 633
 634static const u32 stoney_golden_settings_a11[] =
 635{
 636	mmDB_DEBUG2, 0xf00fffff, 0x00000400,
 637	mmGB_GPU_ID, 0x0000000f, 0x00000000,
 638	mmPA_SC_ENHANCE, 0xffffffff, 0x20000001,
 639	mmPA_SC_LINE_STIPPLE_STATE, 0x0000ff0f, 0x00000000,
 640	mmRLC_CGCG_CGLS_CTRL, 0x00000003, 0x0001003c,
 641	mmTA_CNTL_AUX, 0x000f000f, 0x000b0000,
 642	mmTCC_CTRL, 0x00100000, 0xf31fff7f,
 643	mmTCC_EXE_DISABLE, 0x00000002, 0x00000002,
 644	mmTCP_ADDR_CONFIG, 0x0000000f, 0x000000f1,
 645	mmTCP_CHAN_STEER_LO, 0xffffffff, 0x10101010,
 646};
 647
 648static const u32 stoney_golden_common_all[] =
 649{
 650	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 651	mmPA_SC_RASTER_CONFIG, 0xffffffff, 0x00000000,
 652	mmPA_SC_RASTER_CONFIG_1, 0xffffffff, 0x00000000,
 653	mmGB_ADDR_CONFIG, 0xffffffff, 0x12010001,
 654	mmSPI_RESOURCE_RESERVE_CU_0, 0xffffffff, 0x00000800,
 655	mmSPI_RESOURCE_RESERVE_CU_1, 0xffffffff, 0x00000800,
 656	mmSPI_RESOURCE_RESERVE_EN_CU_0, 0xffffffff, 0x00FF7FBF,
 657	mmSPI_RESOURCE_RESERVE_EN_CU_1, 0xffffffff, 0x00FF7FAF,
 658};
 659
 660static const u32 stoney_mgcg_cgcg_init[] =
 661{
 662	mmGRBM_GFX_INDEX, 0xffffffff, 0xe0000000,
 663	mmRLC_CGCG_CGLS_CTRL, 0xffffffff, 0x0020003f,
 664	mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
 665	mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
 666	mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200,
 667};
 668
 
 
 
 
 
 
 
 
 
 
 
 669static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
 670static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev);
 671static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev);
 672static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
 673static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
 674static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
 675static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
 676static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
 677
 
 
 
 678static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
 679{
 
 
 680	switch (adev->asic_type) {
 681	case CHIP_TOPAZ:
 682		amdgpu_device_program_register_sequence(adev,
 683							iceland_mgcg_cgcg_init,
 684							ARRAY_SIZE(iceland_mgcg_cgcg_init));
 685		amdgpu_device_program_register_sequence(adev,
 686							golden_settings_iceland_a11,
 687							ARRAY_SIZE(golden_settings_iceland_a11));
 688		amdgpu_device_program_register_sequence(adev,
 689							iceland_golden_common_all,
 690							ARRAY_SIZE(iceland_golden_common_all));
 691		break;
 692	case CHIP_FIJI:
 693		amdgpu_device_program_register_sequence(adev,
 694							fiji_mgcg_cgcg_init,
 695							ARRAY_SIZE(fiji_mgcg_cgcg_init));
 696		amdgpu_device_program_register_sequence(adev,
 697							golden_settings_fiji_a10,
 698							ARRAY_SIZE(golden_settings_fiji_a10));
 699		amdgpu_device_program_register_sequence(adev,
 700							fiji_golden_common_all,
 701							ARRAY_SIZE(fiji_golden_common_all));
 702		break;
 703
 704	case CHIP_TONGA:
 705		amdgpu_device_program_register_sequence(adev,
 706							tonga_mgcg_cgcg_init,
 707							ARRAY_SIZE(tonga_mgcg_cgcg_init));
 708		amdgpu_device_program_register_sequence(adev,
 709							golden_settings_tonga_a11,
 710							ARRAY_SIZE(golden_settings_tonga_a11));
 711		amdgpu_device_program_register_sequence(adev,
 712							tonga_golden_common_all,
 713							ARRAY_SIZE(tonga_golden_common_all));
 714		break;
 
 
 
 
 
 
 
 
 715	case CHIP_POLARIS11:
 716	case CHIP_POLARIS12:
 717		amdgpu_device_program_register_sequence(adev,
 718							golden_settings_polaris11_a11,
 719							ARRAY_SIZE(golden_settings_polaris11_a11));
 720		amdgpu_device_program_register_sequence(adev,
 721							polaris11_golden_common_all,
 722							ARRAY_SIZE(polaris11_golden_common_all));
 723		break;
 724	case CHIP_POLARIS10:
 725		amdgpu_device_program_register_sequence(adev,
 726							golden_settings_polaris10_a11,
 727							ARRAY_SIZE(golden_settings_polaris10_a11));
 728		amdgpu_device_program_register_sequence(adev,
 729							polaris10_golden_common_all,
 730							ARRAY_SIZE(polaris10_golden_common_all));
 731		WREG32_SMC(ixCG_ACLK_CNTL, 0x0000001C);
 732		if (adev->pdev->revision == 0xc7 &&
 
 
 
 733		    ((adev->pdev->subsystem_device == 0xb37 && adev->pdev->subsystem_vendor == 0x1002) ||
 734		     (adev->pdev->subsystem_device == 0x4a8 && adev->pdev->subsystem_vendor == 0x1043) ||
 735		     (adev->pdev->subsystem_device == 0x9480 && adev->pdev->subsystem_vendor == 0x1682))) {
 736			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1E, 0xDD);
 737			amdgpu_atombios_i2c_channel_trans(adev, 0x10, 0x96, 0x1F, 0xD0);
 738		}
 739		break;
 740	case CHIP_CARRIZO:
 741		amdgpu_device_program_register_sequence(adev,
 742							cz_mgcg_cgcg_init,
 743							ARRAY_SIZE(cz_mgcg_cgcg_init));
 744		amdgpu_device_program_register_sequence(adev,
 745							cz_golden_settings_a11,
 746							ARRAY_SIZE(cz_golden_settings_a11));
 747		amdgpu_device_program_register_sequence(adev,
 748							cz_golden_common_all,
 749							ARRAY_SIZE(cz_golden_common_all));
 750		break;
 751	case CHIP_STONEY:
 752		amdgpu_device_program_register_sequence(adev,
 753							stoney_mgcg_cgcg_init,
 754							ARRAY_SIZE(stoney_mgcg_cgcg_init));
 755		amdgpu_device_program_register_sequence(adev,
 756							stoney_golden_settings_a11,
 757							ARRAY_SIZE(stoney_golden_settings_a11));
 758		amdgpu_device_program_register_sequence(adev,
 759							stoney_golden_common_all,
 760							ARRAY_SIZE(stoney_golden_common_all));
 761		break;
 762	default:
 763		break;
 764	}
 765}
 766
 767static void gfx_v8_0_scratch_init(struct amdgpu_device *adev)
 768{
 769	adev->gfx.scratch.num_reg = 8;
 770	adev->gfx.scratch.reg_base = mmSCRATCH_REG0;
 771	adev->gfx.scratch.free_mask = (1u << adev->gfx.scratch.num_reg) - 1;
 772}
 773
 774static int gfx_v8_0_ring_test_ring(struct amdgpu_ring *ring)
 775{
 776	struct amdgpu_device *adev = ring->adev;
 777	uint32_t scratch;
 778	uint32_t tmp = 0;
 779	unsigned i;
 780	int r;
 781
 782	r = amdgpu_gfx_scratch_get(adev, &scratch);
 783	if (r) {
 784		DRM_ERROR("amdgpu: cp failed to get scratch reg (%d).\n", r);
 785		return r;
 786	}
 787	WREG32(scratch, 0xCAFEDEAD);
 788	r = amdgpu_ring_alloc(ring, 3);
 789	if (r) {
 790		DRM_ERROR("amdgpu: cp failed to lock ring %d (%d).\n",
 791			  ring->idx, r);
 792		amdgpu_gfx_scratch_free(adev, scratch);
 793		return r;
 794	}
 795	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
 796	amdgpu_ring_write(ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
 797	amdgpu_ring_write(ring, 0xDEADBEEF);
 798	amdgpu_ring_commit(ring);
 799
 800	for (i = 0; i < adev->usec_timeout; i++) {
 801		tmp = RREG32(scratch);
 802		if (tmp == 0xDEADBEEF)
 803			break;
 804		DRM_UDELAY(1);
 805	}
 806	if (i < adev->usec_timeout) {
 807		DRM_DEBUG("ring test on %d succeeded in %d usecs\n",
 808			 ring->idx, i);
 809	} else {
 810		DRM_ERROR("amdgpu: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
 811			  ring->idx, scratch, tmp);
 812		r = -EINVAL;
 813	}
 814	amdgpu_gfx_scratch_free(adev, scratch);
 815	return r;
 816}
 817
 818static int gfx_v8_0_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 819{
 820	struct amdgpu_device *adev = ring->adev;
 821	struct amdgpu_ib ib;
 822	struct dma_fence *f = NULL;
 823	uint32_t scratch;
 824	uint32_t tmp = 0;
 
 
 825	long r;
 826
 827	r = amdgpu_gfx_scratch_get(adev, &scratch);
 828	if (r) {
 829		DRM_ERROR("amdgpu: failed to get scratch reg (%ld).\n", r);
 830		return r;
 831	}
 832	WREG32(scratch, 0xCAFEDEAD);
 
 833	memset(&ib, 0, sizeof(ib));
 834	r = amdgpu_ib_get(adev, NULL, 256, &ib);
 835	if (r) {
 836		DRM_ERROR("amdgpu: failed to get ib (%ld).\n", r);
 837		goto err1;
 838	}
 839	ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
 840	ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START));
 841	ib.ptr[2] = 0xDEADBEEF;
 842	ib.length_dw = 3;
 
 
 843
 844	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
 845	if (r)
 846		goto err2;
 847
 848	r = dma_fence_wait_timeout(f, false, timeout);
 849	if (r == 0) {
 850		DRM_ERROR("amdgpu: IB test timed out.\n");
 851		r = -ETIMEDOUT;
 852		goto err2;
 853	} else if (r < 0) {
 854		DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
 855		goto err2;
 856	}
 857	tmp = RREG32(scratch);
 858	if (tmp == 0xDEADBEEF) {
 859		DRM_DEBUG("ib test on ring %d succeeded\n", ring->idx);
 860		r = 0;
 861	} else {
 862		DRM_ERROR("amdgpu: ib test failed (scratch(0x%04X)=0x%08X)\n",
 863			  scratch, tmp);
 864		r = -EINVAL;
 865	}
 866err2:
 867	amdgpu_ib_free(adev, &ib, NULL);
 868	dma_fence_put(f);
 869err1:
 870	amdgpu_gfx_scratch_free(adev, scratch);
 871	return r;
 872}
 873
 874
 875static void gfx_v8_0_free_microcode(struct amdgpu_device *adev)
 876{
 877	release_firmware(adev->gfx.pfp_fw);
 878	adev->gfx.pfp_fw = NULL;
 879	release_firmware(adev->gfx.me_fw);
 880	adev->gfx.me_fw = NULL;
 881	release_firmware(adev->gfx.ce_fw);
 882	adev->gfx.ce_fw = NULL;
 883	release_firmware(adev->gfx.rlc_fw);
 884	adev->gfx.rlc_fw = NULL;
 885	release_firmware(adev->gfx.mec_fw);
 886	adev->gfx.mec_fw = NULL;
 887	if ((adev->asic_type != CHIP_STONEY) &&
 888	    (adev->asic_type != CHIP_TOPAZ))
 889		release_firmware(adev->gfx.mec2_fw);
 890	adev->gfx.mec2_fw = NULL;
 891
 892	kfree(adev->gfx.rlc.register_list_format);
 893}
 894
 895static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
 896{
 897	const char *chip_name;
 898	char fw_name[30];
 899	int err;
 900	struct amdgpu_firmware_info *info = NULL;
 901	const struct common_firmware_header *header = NULL;
 902	const struct gfx_firmware_header_v1_0 *cp_hdr;
 903	const struct rlc_firmware_header_v2_0 *rlc_hdr;
 904	unsigned int *tmp = NULL, i;
 905
 906	DRM_DEBUG("\n");
 907
 908	switch (adev->asic_type) {
 909	case CHIP_TOPAZ:
 910		chip_name = "topaz";
 911		break;
 912	case CHIP_TONGA:
 913		chip_name = "tonga";
 914		break;
 915	case CHIP_CARRIZO:
 916		chip_name = "carrizo";
 917		break;
 918	case CHIP_FIJI:
 919		chip_name = "fiji";
 920		break;
 921	case CHIP_POLARIS11:
 922		chip_name = "polaris11";
 923		break;
 924	case CHIP_POLARIS10:
 925		chip_name = "polaris10";
 926		break;
 
 
 
 927	case CHIP_POLARIS12:
 928		chip_name = "polaris12";
 929		break;
 930	case CHIP_STONEY:
 931		chip_name = "stoney";
 932		break;
 933	default:
 934		BUG();
 935	}
 936
 937	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
 938		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp_2.bin", chip_name);
 939		err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
 940		if (err == -ENOENT) {
 941			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp.bin", chip_name);
 942			err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
 943		}
 944	} else {
 945		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_pfp.bin", chip_name);
 946		err = request_firmware(&adev->gfx.pfp_fw, fw_name, adev->dev);
 947	}
 948	if (err)
 949		goto out;
 950	err = amdgpu_ucode_validate(adev->gfx.pfp_fw);
 951	if (err)
 952		goto out;
 953	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
 954	adev->gfx.pfp_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
 955	adev->gfx.pfp_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
 956
 957	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
 958		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_me_2.bin", chip_name);
 959		err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
 960		if (err == -ENOENT) {
 961			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_me.bin", chip_name);
 962			err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
 963		}
 964	} else {
 965		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_me.bin", chip_name);
 966		err = request_firmware(&adev->gfx.me_fw, fw_name, adev->dev);
 967	}
 968	if (err)
 969		goto out;
 970	err = amdgpu_ucode_validate(adev->gfx.me_fw);
 971	if (err)
 972		goto out;
 973	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
 974	adev->gfx.me_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
 975
 976	adev->gfx.me_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
 977
 978	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
 979		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ce_2.bin", chip_name);
 980		err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
 981		if (err == -ENOENT) {
 982			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ce.bin", chip_name);
 983			err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
 984		}
 985	} else {
 986		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_ce.bin", chip_name);
 987		err = request_firmware(&adev->gfx.ce_fw, fw_name, adev->dev);
 988	}
 989	if (err)
 990		goto out;
 991	err = amdgpu_ucode_validate(adev->gfx.ce_fw);
 992	if (err)
 993		goto out;
 994	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
 995	adev->gfx.ce_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
 996	adev->gfx.ce_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
 997
 998	/*
 999	 * Support for MCBP/Virtualization in combination with chained IBs is
1000	 * formal released on feature version #46
1001	 */
1002	if (adev->gfx.ce_feature_version >= 46 &&
1003	    adev->gfx.pfp_feature_version >= 46) {
1004		adev->virt.chained_ib_support = true;
1005		DRM_INFO("Chained IB support enabled!\n");
1006	} else
1007		adev->virt.chained_ib_support = false;
1008
1009	snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", chip_name);
1010	err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev);
1011	if (err)
1012		goto out;
1013	err = amdgpu_ucode_validate(adev->gfx.rlc_fw);
1014	rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
1015	adev->gfx.rlc_fw_version = le32_to_cpu(rlc_hdr->header.ucode_version);
1016	adev->gfx.rlc_feature_version = le32_to_cpu(rlc_hdr->ucode_feature_version);
1017
1018	adev->gfx.rlc.save_and_restore_offset =
1019			le32_to_cpu(rlc_hdr->save_and_restore_offset);
1020	adev->gfx.rlc.clear_state_descriptor_offset =
1021			le32_to_cpu(rlc_hdr->clear_state_descriptor_offset);
1022	adev->gfx.rlc.avail_scratch_ram_locations =
1023			le32_to_cpu(rlc_hdr->avail_scratch_ram_locations);
1024	adev->gfx.rlc.reg_restore_list_size =
1025			le32_to_cpu(rlc_hdr->reg_restore_list_size);
1026	adev->gfx.rlc.reg_list_format_start =
1027			le32_to_cpu(rlc_hdr->reg_list_format_start);
1028	adev->gfx.rlc.reg_list_format_separate_start =
1029			le32_to_cpu(rlc_hdr->reg_list_format_separate_start);
1030	adev->gfx.rlc.starting_offsets_start =
1031			le32_to_cpu(rlc_hdr->starting_offsets_start);
1032	adev->gfx.rlc.reg_list_format_size_bytes =
1033			le32_to_cpu(rlc_hdr->reg_list_format_size_bytes);
1034	adev->gfx.rlc.reg_list_size_bytes =
1035			le32_to_cpu(rlc_hdr->reg_list_size_bytes);
1036
1037	adev->gfx.rlc.register_list_format =
1038			kmalloc(adev->gfx.rlc.reg_list_format_size_bytes +
1039					adev->gfx.rlc.reg_list_size_bytes, GFP_KERNEL);
1040
1041	if (!adev->gfx.rlc.register_list_format) {
1042		err = -ENOMEM;
1043		goto out;
1044	}
1045
1046	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
1047			le32_to_cpu(rlc_hdr->reg_list_format_array_offset_bytes));
1048	for (i = 0 ; i < (rlc_hdr->reg_list_format_size_bytes >> 2); i++)
1049		adev->gfx.rlc.register_list_format[i] =	le32_to_cpu(tmp[i]);
1050
1051	adev->gfx.rlc.register_restore = adev->gfx.rlc.register_list_format + i;
1052
1053	tmp = (unsigned int *)((uintptr_t)rlc_hdr +
1054			le32_to_cpu(rlc_hdr->reg_list_array_offset_bytes));
1055	for (i = 0 ; i < (rlc_hdr->reg_list_size_bytes >> 2); i++)
1056		adev->gfx.rlc.register_restore[i] = le32_to_cpu(tmp[i]);
1057
1058	if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1059		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec_2.bin", chip_name);
1060		err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
1061		if (err == -ENOENT) {
1062			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec.bin", chip_name);
1063			err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
1064		}
1065	} else {
1066		snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec.bin", chip_name);
1067		err = request_firmware(&adev->gfx.mec_fw, fw_name, adev->dev);
1068	}
1069	if (err)
1070		goto out;
1071	err = amdgpu_ucode_validate(adev->gfx.mec_fw);
1072	if (err)
1073		goto out;
1074	cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1075	adev->gfx.mec_fw_version = le32_to_cpu(cp_hdr->header.ucode_version);
1076	adev->gfx.mec_feature_version = le32_to_cpu(cp_hdr->ucode_feature_version);
1077
1078	if ((adev->asic_type != CHIP_STONEY) &&
1079	    (adev->asic_type != CHIP_TOPAZ)) {
1080		if (adev->asic_type >= CHIP_POLARIS10 && adev->asic_type <= CHIP_POLARIS12) {
1081			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec2_2.bin", chip_name);
1082			err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
1083			if (err == -ENOENT) {
1084				snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec2.bin", chip_name);
1085				err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
1086			}
1087		} else {
1088			snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_mec2.bin", chip_name);
1089			err = request_firmware(&adev->gfx.mec2_fw, fw_name, adev->dev);
1090		}
1091		if (!err) {
1092			err = amdgpu_ucode_validate(adev->gfx.mec2_fw);
1093			if (err)
1094				goto out;
1095			cp_hdr = (const struct gfx_firmware_header_v1_0 *)
1096				adev->gfx.mec2_fw->data;
1097			adev->gfx.mec2_fw_version =
1098				le32_to_cpu(cp_hdr->header.ucode_version);
1099			adev->gfx.mec2_feature_version =
1100				le32_to_cpu(cp_hdr->ucode_feature_version);
1101		} else {
1102			err = 0;
1103			adev->gfx.mec2_fw = NULL;
1104		}
1105	}
1106
1107	if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU) {
1108		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_PFP];
1109		info->ucode_id = AMDGPU_UCODE_ID_CP_PFP;
1110		info->fw = adev->gfx.pfp_fw;
1111		header = (const struct common_firmware_header *)info->fw->data;
1112		adev->firmware.fw_size +=
1113			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1114
1115		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_ME];
1116		info->ucode_id = AMDGPU_UCODE_ID_CP_ME;
1117		info->fw = adev->gfx.me_fw;
1118		header = (const struct common_firmware_header *)info->fw->data;
1119		adev->firmware.fw_size +=
1120			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1121
1122		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_CE];
1123		info->ucode_id = AMDGPU_UCODE_ID_CP_CE;
1124		info->fw = adev->gfx.ce_fw;
1125		header = (const struct common_firmware_header *)info->fw->data;
1126		adev->firmware.fw_size +=
1127			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
 
1128
1129		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_RLC_G];
1130		info->ucode_id = AMDGPU_UCODE_ID_RLC_G;
1131		info->fw = adev->gfx.rlc_fw;
 
1132		header = (const struct common_firmware_header *)info->fw->data;
1133		adev->firmware.fw_size +=
1134			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1135
1136		info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC1];
1137		info->ucode_id = AMDGPU_UCODE_ID_CP_MEC1;
1138		info->fw = adev->gfx.mec_fw;
1139		header = (const struct common_firmware_header *)info->fw->data;
1140		adev->firmware.fw_size +=
1141			ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1142
1143		/* we need account JT in */
1144		cp_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1145		adev->firmware.fw_size +=
1146			ALIGN(le32_to_cpu(cp_hdr->jt_size) << 2, PAGE_SIZE);
1147
1148		if (amdgpu_sriov_vf(adev)) {
1149			info = &adev->firmware.ucode[AMDGPU_UCODE_ID_STORAGE];
1150			info->ucode_id = AMDGPU_UCODE_ID_STORAGE;
1151			info->fw = adev->gfx.mec_fw;
1152			adev->firmware.fw_size +=
1153				ALIGN(le32_to_cpu(64 * PAGE_SIZE), PAGE_SIZE);
1154		}
1155
1156		if (adev->gfx.mec2_fw) {
1157			info = &adev->firmware.ucode[AMDGPU_UCODE_ID_CP_MEC2];
1158			info->ucode_id = AMDGPU_UCODE_ID_CP_MEC2;
1159			info->fw = adev->gfx.mec2_fw;
1160			header = (const struct common_firmware_header *)info->fw->data;
1161			adev->firmware.fw_size +=
1162				ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
1163		}
1164
1165	}
1166
1167out:
1168	if (err) {
1169		dev_err(adev->dev,
1170			"gfx8: Failed to load firmware \"%s\"\n",
1171			fw_name);
1172		release_firmware(adev->gfx.pfp_fw);
1173		adev->gfx.pfp_fw = NULL;
1174		release_firmware(adev->gfx.me_fw);
1175		adev->gfx.me_fw = NULL;
1176		release_firmware(adev->gfx.ce_fw);
1177		adev->gfx.ce_fw = NULL;
1178		release_firmware(adev->gfx.rlc_fw);
1179		adev->gfx.rlc_fw = NULL;
1180		release_firmware(adev->gfx.mec_fw);
1181		adev->gfx.mec_fw = NULL;
1182		release_firmware(adev->gfx.mec2_fw);
1183		adev->gfx.mec2_fw = NULL;
1184	}
1185	return err;
1186}
1187
1188static void gfx_v8_0_get_csb_buffer(struct amdgpu_device *adev,
1189				    volatile u32 *buffer)
1190{
1191	u32 count = 0, i;
1192	const struct cs_section_def *sect = NULL;
1193	const struct cs_extent_def *ext = NULL;
1194
1195	if (adev->gfx.rlc.cs_data == NULL)
1196		return;
1197	if (buffer == NULL)
1198		return;
1199
1200	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1201	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
1202
1203	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
1204	buffer[count++] = cpu_to_le32(0x80000000);
1205	buffer[count++] = cpu_to_le32(0x80000000);
1206
1207	for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
1208		for (ext = sect->section; ext->extent != NULL; ++ext) {
1209			if (sect->id == SECT_CONTEXT) {
1210				buffer[count++] =
1211					cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
1212				buffer[count++] = cpu_to_le32(ext->reg_index -
1213						PACKET3_SET_CONTEXT_REG_START);
1214				for (i = 0; i < ext->reg_count; i++)
1215					buffer[count++] = cpu_to_le32(ext->extent[i]);
1216			} else {
1217				return;
1218			}
1219		}
1220	}
1221
1222	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
1223	buffer[count++] = cpu_to_le32(mmPA_SC_RASTER_CONFIG -
1224			PACKET3_SET_CONTEXT_REG_START);
1225	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config);
1226	buffer[count++] = cpu_to_le32(adev->gfx.config.rb_config[0][0].raster_config_1);
1227
1228	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
1229	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
1230
1231	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
1232	buffer[count++] = cpu_to_le32(0);
1233}
1234
1235static void cz_init_cp_jump_table(struct amdgpu_device *adev)
1236{
1237	const __le32 *fw_data;
1238	volatile u32 *dst_ptr;
1239	int me, i, max_me = 4;
1240	u32 bo_offset = 0;
1241	u32 table_offset, table_size;
1242
1243	if (adev->asic_type == CHIP_CARRIZO)
1244		max_me = 5;
1245
1246	/* write the cp table buffer */
1247	dst_ptr = adev->gfx.rlc.cp_table_ptr;
1248	for (me = 0; me < max_me; me++) {
1249		if (me == 0) {
1250			const struct gfx_firmware_header_v1_0 *hdr =
1251				(const struct gfx_firmware_header_v1_0 *)adev->gfx.ce_fw->data;
1252			fw_data = (const __le32 *)
1253				(adev->gfx.ce_fw->data +
1254				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1255			table_offset = le32_to_cpu(hdr->jt_offset);
1256			table_size = le32_to_cpu(hdr->jt_size);
1257		} else if (me == 1) {
1258			const struct gfx_firmware_header_v1_0 *hdr =
1259				(const struct gfx_firmware_header_v1_0 *)adev->gfx.pfp_fw->data;
1260			fw_data = (const __le32 *)
1261				(adev->gfx.pfp_fw->data +
1262				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1263			table_offset = le32_to_cpu(hdr->jt_offset);
1264			table_size = le32_to_cpu(hdr->jt_size);
1265		} else if (me == 2) {
1266			const struct gfx_firmware_header_v1_0 *hdr =
1267				(const struct gfx_firmware_header_v1_0 *)adev->gfx.me_fw->data;
1268			fw_data = (const __le32 *)
1269				(adev->gfx.me_fw->data +
1270				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1271			table_offset = le32_to_cpu(hdr->jt_offset);
1272			table_size = le32_to_cpu(hdr->jt_size);
1273		} else if (me == 3) {
1274			const struct gfx_firmware_header_v1_0 *hdr =
1275				(const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
1276			fw_data = (const __le32 *)
1277				(adev->gfx.mec_fw->data +
1278				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1279			table_offset = le32_to_cpu(hdr->jt_offset);
1280			table_size = le32_to_cpu(hdr->jt_size);
1281		} else  if (me == 4) {
1282			const struct gfx_firmware_header_v1_0 *hdr =
1283				(const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
1284			fw_data = (const __le32 *)
1285				(adev->gfx.mec2_fw->data +
1286				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
1287			table_offset = le32_to_cpu(hdr->jt_offset);
1288			table_size = le32_to_cpu(hdr->jt_size);
1289		}
1290
1291		for (i = 0; i < table_size; i ++) {
1292			dst_ptr[bo_offset + i] =
1293				cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
1294		}
1295
1296		bo_offset += table_size;
1297	}
1298}
1299
1300static void gfx_v8_0_rlc_fini(struct amdgpu_device *adev)
1301{
1302	amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj, NULL, NULL);
1303	amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj, NULL, NULL);
1304}
1305
1306static int gfx_v8_0_rlc_init(struct amdgpu_device *adev)
1307{
1308	volatile u32 *dst_ptr;
1309	u32 dws;
1310	const struct cs_section_def *cs_data;
1311	int r;
1312
1313	adev->gfx.rlc.cs_data = vi_cs_data;
1314
1315	cs_data = adev->gfx.rlc.cs_data;
1316
1317	if (cs_data) {
1318		/* clear state block */
1319		adev->gfx.rlc.clear_state_size = dws = gfx_v8_0_get_csb_size(adev);
1320
1321		r = amdgpu_bo_create_reserved(adev, dws * 4, PAGE_SIZE,
1322					      AMDGPU_GEM_DOMAIN_VRAM,
1323					      &adev->gfx.rlc.clear_state_obj,
1324					      &adev->gfx.rlc.clear_state_gpu_addr,
1325					      (void **)&adev->gfx.rlc.cs_ptr);
1326		if (r) {
1327			dev_warn(adev->dev, "(%d) create RLC c bo failed\n", r);
1328			gfx_v8_0_rlc_fini(adev);
1329			return r;
1330		}
1331
1332		/* set up the cs buffer */
1333		dst_ptr = adev->gfx.rlc.cs_ptr;
1334		gfx_v8_0_get_csb_buffer(adev, dst_ptr);
1335		amdgpu_bo_kunmap(adev->gfx.rlc.clear_state_obj);
1336		amdgpu_bo_unreserve(adev->gfx.rlc.clear_state_obj);
1337	}
1338
1339	if ((adev->asic_type == CHIP_CARRIZO) ||
1340	    (adev->asic_type == CHIP_STONEY)) {
1341		adev->gfx.rlc.cp_table_size = ALIGN(96 * 5 * 4, 2048) + (64 * 1024); /* JT + GDS */
1342		r = amdgpu_bo_create_reserved(adev, adev->gfx.rlc.cp_table_size,
1343					      PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
1344					      &adev->gfx.rlc.cp_table_obj,
1345					      &adev->gfx.rlc.cp_table_gpu_addr,
1346					      (void **)&adev->gfx.rlc.cp_table_ptr);
1347		if (r) {
1348			dev_warn(adev->dev, "(%d) create RLC cp table bo failed\n", r);
1349			return r;
1350		}
1351
1352		cz_init_cp_jump_table(adev);
1353
1354		amdgpu_bo_kunmap(adev->gfx.rlc.cp_table_obj);
1355		amdgpu_bo_unreserve(adev->gfx.rlc.cp_table_obj);
1356	}
1357
1358	return 0;
1359}
1360
1361static void gfx_v8_0_mec_fini(struct amdgpu_device *adev)
1362{
1363	amdgpu_bo_free_kernel(&adev->gfx.mec.hpd_eop_obj, NULL, NULL);
1364}
1365
1366static int gfx_v8_0_mec_init(struct amdgpu_device *adev)
1367{
1368	int r;
1369	u32 *hpd;
1370	size_t mec_hpd_size;
1371
1372	bitmap_zero(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
1373
1374	/* take ownership of the relevant compute queues */
1375	amdgpu_gfx_compute_queue_acquire(adev);
1376
1377	mec_hpd_size = adev->gfx.num_compute_rings * GFX8_MEC_HPD_SIZE;
 
 
 
 
 
 
 
 
 
 
 
 
 
1378
1379	r = amdgpu_bo_create_reserved(adev, mec_hpd_size, PAGE_SIZE,
1380				      AMDGPU_GEM_DOMAIN_GTT,
1381				      &adev->gfx.mec.hpd_eop_obj,
1382				      &adev->gfx.mec.hpd_eop_gpu_addr,
1383				      (void **)&hpd);
1384	if (r) {
1385		dev_warn(adev->dev, "(%d) create HDP EOP bo failed\n", r);
1386		return r;
1387	}
1388
1389	memset(hpd, 0, mec_hpd_size);
1390
1391	amdgpu_bo_kunmap(adev->gfx.mec.hpd_eop_obj);
1392	amdgpu_bo_unreserve(adev->gfx.mec.hpd_eop_obj);
1393
1394	return 0;
1395}
1396
1397static const u32 vgpr_init_compute_shader[] =
1398{
1399	0x7e000209, 0x7e020208,
1400	0x7e040207, 0x7e060206,
1401	0x7e080205, 0x7e0a0204,
1402	0x7e0c0203, 0x7e0e0202,
1403	0x7e100201, 0x7e120200,
1404	0x7e140209, 0x7e160208,
1405	0x7e180207, 0x7e1a0206,
1406	0x7e1c0205, 0x7e1e0204,
1407	0x7e200203, 0x7e220202,
1408	0x7e240201, 0x7e260200,
1409	0x7e280209, 0x7e2a0208,
1410	0x7e2c0207, 0x7e2e0206,
1411	0x7e300205, 0x7e320204,
1412	0x7e340203, 0x7e360202,
1413	0x7e380201, 0x7e3a0200,
1414	0x7e3c0209, 0x7e3e0208,
1415	0x7e400207, 0x7e420206,
1416	0x7e440205, 0x7e460204,
1417	0x7e480203, 0x7e4a0202,
1418	0x7e4c0201, 0x7e4e0200,
1419	0x7e500209, 0x7e520208,
1420	0x7e540207, 0x7e560206,
1421	0x7e580205, 0x7e5a0204,
1422	0x7e5c0203, 0x7e5e0202,
1423	0x7e600201, 0x7e620200,
1424	0x7e640209, 0x7e660208,
1425	0x7e680207, 0x7e6a0206,
1426	0x7e6c0205, 0x7e6e0204,
1427	0x7e700203, 0x7e720202,
1428	0x7e740201, 0x7e760200,
1429	0x7e780209, 0x7e7a0208,
1430	0x7e7c0207, 0x7e7e0206,
1431	0xbf8a0000, 0xbf810000,
1432};
1433
1434static const u32 sgpr_init_compute_shader[] =
1435{
1436	0xbe8a0100, 0xbe8c0102,
1437	0xbe8e0104, 0xbe900106,
1438	0xbe920108, 0xbe940100,
1439	0xbe960102, 0xbe980104,
1440	0xbe9a0106, 0xbe9c0108,
1441	0xbe9e0100, 0xbea00102,
1442	0xbea20104, 0xbea40106,
1443	0xbea60108, 0xbea80100,
1444	0xbeaa0102, 0xbeac0104,
1445	0xbeae0106, 0xbeb00108,
1446	0xbeb20100, 0xbeb40102,
1447	0xbeb60104, 0xbeb80106,
1448	0xbeba0108, 0xbebc0100,
1449	0xbebe0102, 0xbec00104,
1450	0xbec20106, 0xbec40108,
1451	0xbec60100, 0xbec80102,
1452	0xbee60004, 0xbee70005,
1453	0xbeea0006, 0xbeeb0007,
1454	0xbee80008, 0xbee90009,
1455	0xbefc0000, 0xbf8a0000,
1456	0xbf810000, 0x00000000,
1457};
1458
1459static const u32 vgpr_init_regs[] =
1460{
1461	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xffffffff,
1462	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1463	mmCOMPUTE_NUM_THREAD_X, 256*4,
1464	mmCOMPUTE_NUM_THREAD_Y, 1,
1465	mmCOMPUTE_NUM_THREAD_Z, 1,
1466	mmCOMPUTE_PGM_RSRC1, 0x100004f, /* VGPRS=15 (64 logical VGPRs), SGPRS=1 (16 SGPRs), BULKY=1 */
1467	mmCOMPUTE_PGM_RSRC2, 20,
1468	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1469	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1470	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1471	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1472	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1473	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1474	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1475	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1476	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1477	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1478};
1479
1480static const u32 sgpr1_init_regs[] =
1481{
1482	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0x0f,
1483	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000, /* CU_GROUP_COUNT=1 */
1484	mmCOMPUTE_NUM_THREAD_X, 256*5,
1485	mmCOMPUTE_NUM_THREAD_Y, 1,
1486	mmCOMPUTE_NUM_THREAD_Z, 1,
1487	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1488	mmCOMPUTE_PGM_RSRC2, 20,
1489	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1490	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1491	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1492	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1493	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1494	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1495	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1496	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1497	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1498	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1499};
1500
1501static const u32 sgpr2_init_regs[] =
1502{
1503	mmCOMPUTE_STATIC_THREAD_MGMT_SE0, 0xf0,
1504	mmCOMPUTE_RESOURCE_LIMITS, 0x1000000,
1505	mmCOMPUTE_NUM_THREAD_X, 256*5,
1506	mmCOMPUTE_NUM_THREAD_Y, 1,
1507	mmCOMPUTE_NUM_THREAD_Z, 1,
1508	mmCOMPUTE_PGM_RSRC1, 0x240, /* SGPRS=9 (80 GPRS) */
1509	mmCOMPUTE_PGM_RSRC2, 20,
1510	mmCOMPUTE_USER_DATA_0, 0xedcedc00,
1511	mmCOMPUTE_USER_DATA_1, 0xedcedc01,
1512	mmCOMPUTE_USER_DATA_2, 0xedcedc02,
1513	mmCOMPUTE_USER_DATA_3, 0xedcedc03,
1514	mmCOMPUTE_USER_DATA_4, 0xedcedc04,
1515	mmCOMPUTE_USER_DATA_5, 0xedcedc05,
1516	mmCOMPUTE_USER_DATA_6, 0xedcedc06,
1517	mmCOMPUTE_USER_DATA_7, 0xedcedc07,
1518	mmCOMPUTE_USER_DATA_8, 0xedcedc08,
1519	mmCOMPUTE_USER_DATA_9, 0xedcedc09,
1520};
1521
1522static const u32 sec_ded_counter_registers[] =
1523{
1524	mmCPC_EDC_ATC_CNT,
1525	mmCPC_EDC_SCRATCH_CNT,
1526	mmCPC_EDC_UCODE_CNT,
1527	mmCPF_EDC_ATC_CNT,
1528	mmCPF_EDC_ROQ_CNT,
1529	mmCPF_EDC_TAG_CNT,
1530	mmCPG_EDC_ATC_CNT,
1531	mmCPG_EDC_DMA_CNT,
1532	mmCPG_EDC_TAG_CNT,
1533	mmDC_EDC_CSINVOC_CNT,
1534	mmDC_EDC_RESTORE_CNT,
1535	mmDC_EDC_STATE_CNT,
1536	mmGDS_EDC_CNT,
1537	mmGDS_EDC_GRBM_CNT,
1538	mmGDS_EDC_OA_DED,
1539	mmSPI_EDC_CNT,
1540	mmSQC_ATC_EDC_GATCL1_CNT,
1541	mmSQC_EDC_CNT,
1542	mmSQ_EDC_DED_CNT,
1543	mmSQ_EDC_INFO,
1544	mmSQ_EDC_SEC_CNT,
1545	mmTCC_EDC_CNT,
1546	mmTCP_ATC_EDC_GATCL1_CNT,
1547	mmTCP_EDC_CNT,
1548	mmTD_EDC_CNT
1549};
1550
1551static int gfx_v8_0_do_edc_gpr_workarounds(struct amdgpu_device *adev)
1552{
1553	struct amdgpu_ring *ring = &adev->gfx.compute_ring[0];
1554	struct amdgpu_ib ib;
1555	struct dma_fence *f = NULL;
1556	int r, i;
1557	u32 tmp;
1558	unsigned total_size, vgpr_offset, sgpr_offset;
1559	u64 gpu_addr;
1560
1561	/* only supported on CZ */
1562	if (adev->asic_type != CHIP_CARRIZO)
1563		return 0;
1564
1565	/* bail if the compute ring is not ready */
1566	if (!ring->ready)
1567		return 0;
1568
1569	tmp = RREG32(mmGB_EDC_MODE);
1570	WREG32(mmGB_EDC_MODE, 0);
1571
1572	total_size =
1573		(((ARRAY_SIZE(vgpr_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1574	total_size +=
1575		(((ARRAY_SIZE(sgpr1_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1576	total_size +=
1577		(((ARRAY_SIZE(sgpr2_init_regs) / 2) * 3) + 4 + 5 + 2) * 4;
1578	total_size = ALIGN(total_size, 256);
1579	vgpr_offset = total_size;
1580	total_size += ALIGN(sizeof(vgpr_init_compute_shader), 256);
1581	sgpr_offset = total_size;
1582	total_size += sizeof(sgpr_init_compute_shader);
1583
1584	/* allocate an indirect buffer to put the commands in */
1585	memset(&ib, 0, sizeof(ib));
1586	r = amdgpu_ib_get(adev, NULL, total_size, &ib);
 
1587	if (r) {
1588		DRM_ERROR("amdgpu: failed to get ib (%d).\n", r);
1589		return r;
1590	}
1591
1592	/* load the compute shaders */
1593	for (i = 0; i < ARRAY_SIZE(vgpr_init_compute_shader); i++)
1594		ib.ptr[i + (vgpr_offset / 4)] = vgpr_init_compute_shader[i];
1595
1596	for (i = 0; i < ARRAY_SIZE(sgpr_init_compute_shader); i++)
1597		ib.ptr[i + (sgpr_offset / 4)] = sgpr_init_compute_shader[i];
1598
1599	/* init the ib length to 0 */
1600	ib.length_dw = 0;
1601
1602	/* VGPR */
1603	/* write the register state for the compute dispatch */
1604	for (i = 0; i < ARRAY_SIZE(vgpr_init_regs); i += 2) {
1605		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1606		ib.ptr[ib.length_dw++] = vgpr_init_regs[i] - PACKET3_SET_SH_REG_START;
1607		ib.ptr[ib.length_dw++] = vgpr_init_regs[i + 1];
1608	}
1609	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1610	gpu_addr = (ib.gpu_addr + (u64)vgpr_offset) >> 8;
1611	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1612	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1613	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1614	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1615
1616	/* write dispatch packet */
1617	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1618	ib.ptr[ib.length_dw++] = 8; /* x */
1619	ib.ptr[ib.length_dw++] = 1; /* y */
1620	ib.ptr[ib.length_dw++] = 1; /* z */
1621	ib.ptr[ib.length_dw++] =
1622		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1623
1624	/* write CS partial flush packet */
1625	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1626	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1627
1628	/* SGPR1 */
1629	/* write the register state for the compute dispatch */
1630	for (i = 0; i < ARRAY_SIZE(sgpr1_init_regs); i += 2) {
1631		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1632		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i] - PACKET3_SET_SH_REG_START;
1633		ib.ptr[ib.length_dw++] = sgpr1_init_regs[i + 1];
1634	}
1635	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1636	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1637	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1638	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1639	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1640	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1641
1642	/* write dispatch packet */
1643	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1644	ib.ptr[ib.length_dw++] = 8; /* x */
1645	ib.ptr[ib.length_dw++] = 1; /* y */
1646	ib.ptr[ib.length_dw++] = 1; /* z */
1647	ib.ptr[ib.length_dw++] =
1648		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1649
1650	/* write CS partial flush packet */
1651	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1652	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1653
1654	/* SGPR2 */
1655	/* write the register state for the compute dispatch */
1656	for (i = 0; i < ARRAY_SIZE(sgpr2_init_regs); i += 2) {
1657		ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 1);
1658		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i] - PACKET3_SET_SH_REG_START;
1659		ib.ptr[ib.length_dw++] = sgpr2_init_regs[i + 1];
1660	}
1661	/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */
1662	gpu_addr = (ib.gpu_addr + (u64)sgpr_offset) >> 8;
1663	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_SET_SH_REG, 2);
1664	ib.ptr[ib.length_dw++] = mmCOMPUTE_PGM_LO - PACKET3_SET_SH_REG_START;
1665	ib.ptr[ib.length_dw++] = lower_32_bits(gpu_addr);
1666	ib.ptr[ib.length_dw++] = upper_32_bits(gpu_addr);
1667
1668	/* write dispatch packet */
1669	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_DISPATCH_DIRECT, 3);
1670	ib.ptr[ib.length_dw++] = 8; /* x */
1671	ib.ptr[ib.length_dw++] = 1; /* y */
1672	ib.ptr[ib.length_dw++] = 1; /* z */
1673	ib.ptr[ib.length_dw++] =
1674		REG_SET_FIELD(0, COMPUTE_DISPATCH_INITIATOR, COMPUTE_SHADER_EN, 1);
1675
1676	/* write CS partial flush packet */
1677	ib.ptr[ib.length_dw++] = PACKET3(PACKET3_EVENT_WRITE, 0);
1678	ib.ptr[ib.length_dw++] = EVENT_TYPE(7) | EVENT_INDEX(4);
1679
1680	/* shedule the ib on the ring */
1681	r = amdgpu_ib_schedule(ring, 1, &ib, NULL, &f);
1682	if (r) {
1683		DRM_ERROR("amdgpu: ib submit failed (%d).\n", r);
1684		goto fail;
1685	}
1686
1687	/* wait for the GPU to finish processing the IB */
1688	r = dma_fence_wait(f, false);
1689	if (r) {
1690		DRM_ERROR("amdgpu: fence wait failed (%d).\n", r);
1691		goto fail;
1692	}
1693
1694	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, DED_MODE, 2);
1695	tmp = REG_SET_FIELD(tmp, GB_EDC_MODE, PROP_FED, 1);
1696	WREG32(mmGB_EDC_MODE, tmp);
1697
1698	tmp = RREG32(mmCC_GC_EDC_CONFIG);
1699	tmp = REG_SET_FIELD(tmp, CC_GC_EDC_CONFIG, DIS_EDC, 0) | 1;
1700	WREG32(mmCC_GC_EDC_CONFIG, tmp);
1701
1702
1703	/* read back registers to clear the counters */
1704	for (i = 0; i < ARRAY_SIZE(sec_ded_counter_registers); i++)
1705		RREG32(sec_ded_counter_registers[i]);
1706
1707fail:
1708	amdgpu_ib_free(adev, &ib, NULL);
1709	dma_fence_put(f);
1710
1711	return r;
1712}
1713
1714static int gfx_v8_0_gpu_early_init(struct amdgpu_device *adev)
1715{
1716	u32 gb_addr_config;
1717	u32 mc_shared_chmap, mc_arb_ramcfg;
1718	u32 dimm00_addr_map, dimm01_addr_map, dimm10_addr_map, dimm11_addr_map;
1719	u32 tmp;
1720	int ret;
1721
1722	switch (adev->asic_type) {
1723	case CHIP_TOPAZ:
1724		adev->gfx.config.max_shader_engines = 1;
1725		adev->gfx.config.max_tile_pipes = 2;
1726		adev->gfx.config.max_cu_per_sh = 6;
1727		adev->gfx.config.max_sh_per_se = 1;
1728		adev->gfx.config.max_backends_per_se = 2;
1729		adev->gfx.config.max_texture_channel_caches = 2;
1730		adev->gfx.config.max_gprs = 256;
1731		adev->gfx.config.max_gs_threads = 32;
1732		adev->gfx.config.max_hw_contexts = 8;
1733
1734		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1735		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1736		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1737		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1738		gb_addr_config = TOPAZ_GB_ADDR_CONFIG_GOLDEN;
1739		break;
1740	case CHIP_FIJI:
1741		adev->gfx.config.max_shader_engines = 4;
1742		adev->gfx.config.max_tile_pipes = 16;
1743		adev->gfx.config.max_cu_per_sh = 16;
1744		adev->gfx.config.max_sh_per_se = 1;
1745		adev->gfx.config.max_backends_per_se = 4;
1746		adev->gfx.config.max_texture_channel_caches = 16;
1747		adev->gfx.config.max_gprs = 256;
1748		adev->gfx.config.max_gs_threads = 32;
1749		adev->gfx.config.max_hw_contexts = 8;
1750
1751		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1752		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1753		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1754		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1755		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1756		break;
1757	case CHIP_POLARIS11:
1758	case CHIP_POLARIS12:
1759		ret = amdgpu_atombios_get_gfx_info(adev);
1760		if (ret)
1761			return ret;
1762		adev->gfx.config.max_gprs = 256;
1763		adev->gfx.config.max_gs_threads = 32;
1764		adev->gfx.config.max_hw_contexts = 8;
1765
1766		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1767		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1768		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1769		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1770		gb_addr_config = POLARIS11_GB_ADDR_CONFIG_GOLDEN;
1771		break;
1772	case CHIP_POLARIS10:
 
1773		ret = amdgpu_atombios_get_gfx_info(adev);
1774		if (ret)
1775			return ret;
1776		adev->gfx.config.max_gprs = 256;
1777		adev->gfx.config.max_gs_threads = 32;
1778		adev->gfx.config.max_hw_contexts = 8;
1779
1780		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1781		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1782		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1783		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1784		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1785		break;
1786	case CHIP_TONGA:
1787		adev->gfx.config.max_shader_engines = 4;
1788		adev->gfx.config.max_tile_pipes = 8;
1789		adev->gfx.config.max_cu_per_sh = 8;
1790		adev->gfx.config.max_sh_per_se = 1;
1791		adev->gfx.config.max_backends_per_se = 2;
1792		adev->gfx.config.max_texture_channel_caches = 8;
1793		adev->gfx.config.max_gprs = 256;
1794		adev->gfx.config.max_gs_threads = 32;
1795		adev->gfx.config.max_hw_contexts = 8;
1796
1797		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1798		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1799		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1800		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1801		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1802		break;
1803	case CHIP_CARRIZO:
1804		adev->gfx.config.max_shader_engines = 1;
1805		adev->gfx.config.max_tile_pipes = 2;
1806		adev->gfx.config.max_sh_per_se = 1;
1807		adev->gfx.config.max_backends_per_se = 2;
1808		adev->gfx.config.max_cu_per_sh = 8;
1809		adev->gfx.config.max_texture_channel_caches = 2;
1810		adev->gfx.config.max_gprs = 256;
1811		adev->gfx.config.max_gs_threads = 32;
1812		adev->gfx.config.max_hw_contexts = 8;
1813
1814		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1815		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1816		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1817		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1818		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
1819		break;
1820	case CHIP_STONEY:
1821		adev->gfx.config.max_shader_engines = 1;
1822		adev->gfx.config.max_tile_pipes = 2;
1823		adev->gfx.config.max_sh_per_se = 1;
1824		adev->gfx.config.max_backends_per_se = 1;
1825		adev->gfx.config.max_cu_per_sh = 3;
1826		adev->gfx.config.max_texture_channel_caches = 2;
1827		adev->gfx.config.max_gprs = 256;
1828		adev->gfx.config.max_gs_threads = 16;
1829		adev->gfx.config.max_hw_contexts = 8;
1830
1831		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1832		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1833		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1834		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1835		gb_addr_config = CARRIZO_GB_ADDR_CONFIG_GOLDEN;
1836		break;
1837	default:
1838		adev->gfx.config.max_shader_engines = 2;
1839		adev->gfx.config.max_tile_pipes = 4;
1840		adev->gfx.config.max_cu_per_sh = 2;
1841		adev->gfx.config.max_sh_per_se = 1;
1842		adev->gfx.config.max_backends_per_se = 2;
1843		adev->gfx.config.max_texture_channel_caches = 4;
1844		adev->gfx.config.max_gprs = 256;
1845		adev->gfx.config.max_gs_threads = 32;
1846		adev->gfx.config.max_hw_contexts = 8;
1847
1848		adev->gfx.config.sc_prim_fifo_size_frontend = 0x20;
1849		adev->gfx.config.sc_prim_fifo_size_backend = 0x100;
1850		adev->gfx.config.sc_hiz_tile_fifo_size = 0x30;
1851		adev->gfx.config.sc_earlyz_tile_fifo_size = 0x130;
1852		gb_addr_config = TONGA_GB_ADDR_CONFIG_GOLDEN;
1853		break;
1854	}
1855
1856	mc_shared_chmap = RREG32(mmMC_SHARED_CHMAP);
1857	adev->gfx.config.mc_arb_ramcfg = RREG32(mmMC_ARB_RAMCFG);
1858	mc_arb_ramcfg = adev->gfx.config.mc_arb_ramcfg;
1859
 
 
 
 
 
1860	adev->gfx.config.num_tile_pipes = adev->gfx.config.max_tile_pipes;
1861	adev->gfx.config.mem_max_burst_length_bytes = 256;
1862	if (adev->flags & AMD_IS_APU) {
1863		/* Get memory bank mapping mode. */
1864		tmp = RREG32(mmMC_FUS_DRAM0_BANK_ADDR_MAPPING);
1865		dimm00_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
1866		dimm01_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM0_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
1867
1868		tmp = RREG32(mmMC_FUS_DRAM1_BANK_ADDR_MAPPING);
1869		dimm10_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM0ADDRMAP);
1870		dimm11_addr_map = REG_GET_FIELD(tmp, MC_FUS_DRAM1_BANK_ADDR_MAPPING, DIMM1ADDRMAP);
1871
1872		/* Validate settings in case only one DIMM installed. */
1873		if ((dimm00_addr_map == 0) || (dimm00_addr_map == 3) || (dimm00_addr_map == 4) || (dimm00_addr_map > 12))
1874			dimm00_addr_map = 0;
1875		if ((dimm01_addr_map == 0) || (dimm01_addr_map == 3) || (dimm01_addr_map == 4) || (dimm01_addr_map > 12))
1876			dimm01_addr_map = 0;
1877		if ((dimm10_addr_map == 0) || (dimm10_addr_map == 3) || (dimm10_addr_map == 4) || (dimm10_addr_map > 12))
1878			dimm10_addr_map = 0;
1879		if ((dimm11_addr_map == 0) || (dimm11_addr_map == 3) || (dimm11_addr_map == 4) || (dimm11_addr_map > 12))
1880			dimm11_addr_map = 0;
1881
1882		/* If DIMM Addr map is 8GB, ROW size should be 2KB. Otherwise 1KB. */
1883		/* If ROW size(DIMM1) != ROW size(DMIMM0), ROW size should be larger one. */
1884		if ((dimm00_addr_map == 11) || (dimm01_addr_map == 11) || (dimm10_addr_map == 11) || (dimm11_addr_map == 11))
1885			adev->gfx.config.mem_row_size_in_kb = 2;
1886		else
1887			adev->gfx.config.mem_row_size_in_kb = 1;
1888	} else {
1889		tmp = REG_GET_FIELD(mc_arb_ramcfg, MC_ARB_RAMCFG, NOOFCOLS);
1890		adev->gfx.config.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
1891		if (adev->gfx.config.mem_row_size_in_kb > 4)
1892			adev->gfx.config.mem_row_size_in_kb = 4;
1893	}
1894
1895	adev->gfx.config.shader_engine_tile_size = 32;
1896	adev->gfx.config.num_gpus = 1;
1897	adev->gfx.config.multi_gpu_tile_size = 64;
1898
1899	/* fix up row size */
1900	switch (adev->gfx.config.mem_row_size_in_kb) {
1901	case 1:
1902	default:
1903		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 0);
1904		break;
1905	case 2:
1906		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 1);
1907		break;
1908	case 4:
1909		gb_addr_config = REG_SET_FIELD(gb_addr_config, GB_ADDR_CONFIG, ROW_SIZE, 2);
1910		break;
1911	}
1912	adev->gfx.config.gb_addr_config = gb_addr_config;
1913
1914	return 0;
1915}
1916
1917static int gfx_v8_0_compute_ring_init(struct amdgpu_device *adev, int ring_id,
1918					int mec, int pipe, int queue)
1919{
1920	int r;
1921	unsigned irq_type;
1922	struct amdgpu_ring *ring = &adev->gfx.compute_ring[ring_id];
 
1923
1924	ring = &adev->gfx.compute_ring[ring_id];
1925
1926	/* mec0 is me1 */
1927	ring->me = mec + 1;
1928	ring->pipe = pipe;
1929	ring->queue = queue;
1930
1931	ring->ring_obj = NULL;
1932	ring->use_doorbell = true;
1933	ring->doorbell_index = AMDGPU_DOORBELL_MEC_RING0 + ring_id;
1934	ring->eop_gpu_addr = adev->gfx.mec.hpd_eop_gpu_addr
1935				+ (ring_id * GFX8_MEC_HPD_SIZE);
1936	sprintf(ring->name, "comp_%d.%d.%d", ring->me, ring->pipe, ring->queue);
1937
1938	irq_type = AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP
1939		+ ((ring->me - 1) * adev->gfx.mec.num_pipe_per_mec)
1940		+ ring->pipe;
1941
 
 
1942	/* type-2 packets are deprecated on MEC, use type-3 instead */
1943	r = amdgpu_ring_init(adev, ring, 1024,
1944			&adev->gfx.eop_irq, irq_type);
1945	if (r)
1946		return r;
1947
1948
1949	return 0;
1950}
1951
1952static int gfx_v8_0_sw_init(void *handle)
 
 
1953{
1954	int i, j, k, r, ring_id;
 
1955	struct amdgpu_ring *ring;
1956	struct amdgpu_kiq *kiq;
1957	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1958
1959	switch (adev->asic_type) {
 
 
1960	case CHIP_FIJI:
1961	case CHIP_TONGA:
1962	case CHIP_POLARIS11:
1963	case CHIP_POLARIS12:
1964	case CHIP_POLARIS10:
1965	case CHIP_CARRIZO:
1966		adev->gfx.mec.num_mec = 2;
1967		break;
1968	case CHIP_TOPAZ:
1969	case CHIP_STONEY:
1970	default:
1971		adev->gfx.mec.num_mec = 1;
1972		break;
1973	}
1974
1975	adev->gfx.mec.num_pipe_per_mec = 4;
1976	adev->gfx.mec.num_queue_per_pipe = 8;
1977
1978	/* KIQ event */
1979	r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 178, &adev->gfx.kiq.irq);
1980	if (r)
1981		return r;
1982
1983	/* EOP Event */
1984	r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 181, &adev->gfx.eop_irq);
1985	if (r)
1986		return r;
1987
1988	/* Privileged reg */
1989	r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 184,
1990			      &adev->gfx.priv_reg_irq);
1991	if (r)
1992		return r;
1993
1994	/* Privileged inst */
1995	r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 185,
1996			      &adev->gfx.priv_inst_irq);
1997	if (r)
1998		return r;
1999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2000	adev->gfx.gfx_current_status = AMDGPU_GFX_NORMAL_MODE;
2001
2002	gfx_v8_0_scratch_init(adev);
2003
2004	r = gfx_v8_0_init_microcode(adev);
2005	if (r) {
2006		DRM_ERROR("Failed to load gfx firmware!\n");
2007		return r;
2008	}
2009
2010	r = gfx_v8_0_rlc_init(adev);
2011	if (r) {
2012		DRM_ERROR("Failed to init rlc BOs!\n");
2013		return r;
2014	}
2015
2016	r = gfx_v8_0_mec_init(adev);
2017	if (r) {
2018		DRM_ERROR("Failed to init MEC BOs!\n");
2019		return r;
2020	}
2021
2022	/* set up the gfx ring */
2023	for (i = 0; i < adev->gfx.num_gfx_rings; i++) {
2024		ring = &adev->gfx.gfx_ring[i];
2025		ring->ring_obj = NULL;
2026		sprintf(ring->name, "gfx");
2027		/* no gfx doorbells on iceland */
2028		if (adev->asic_type != CHIP_TOPAZ) {
2029			ring->use_doorbell = true;
2030			ring->doorbell_index = AMDGPU_DOORBELL_GFX_RING0;
2031		}
2032
2033		r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq,
2034				     AMDGPU_CP_IRQ_GFX_EOP);
 
2035		if (r)
2036			return r;
2037	}
2038
2039
2040	/* set up the compute queues - allocate horizontally across pipes */
2041	ring_id = 0;
2042	for (i = 0; i < adev->gfx.mec.num_mec; ++i) {
2043		for (j = 0; j < adev->gfx.mec.num_queue_per_pipe; j++) {
2044			for (k = 0; k < adev->gfx.mec.num_pipe_per_mec; k++) {
2045				if (!amdgpu_gfx_is_mec_queue_enabled(adev, i, k, j))
 
2046					continue;
2047
2048				r = gfx_v8_0_compute_ring_init(adev,
2049								ring_id,
2050								i, k, j);
2051				if (r)
2052					return r;
2053
2054				ring_id++;
2055			}
2056		}
2057	}
2058
2059	r = amdgpu_gfx_kiq_init(adev, GFX8_MEC_HPD_SIZE);
2060	if (r) {
2061		DRM_ERROR("Failed to init KIQ BOs!\n");
2062		return r;
2063	}
2064
2065	kiq = &adev->gfx.kiq;
2066	r = amdgpu_gfx_kiq_init_ring(adev, &kiq->ring, &kiq->irq);
2067	if (r)
2068		return r;
2069
2070	/* create MQD for all compute queues as well as KIQ for SRIOV case */
2071	r = amdgpu_gfx_compute_mqd_sw_init(adev, sizeof(struct vi_mqd_allocation));
2072	if (r)
2073		return r;
2074
2075	/* reserve GDS, GWS and OA resource for gfx */
2076	r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
2077				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
2078				    &adev->gds.gds_gfx_bo, NULL, NULL);
2079	if (r)
2080		return r;
2081
2082	r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
2083				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
2084				    &adev->gds.gws_gfx_bo, NULL, NULL);
2085	if (r)
2086		return r;
2087
2088	r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
2089				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
2090				    &adev->gds.oa_gfx_bo, NULL, NULL);
2091	if (r)
2092		return r;
2093
2094	adev->gfx.ce_ram_size = 0x8000;
2095
2096	r = gfx_v8_0_gpu_early_init(adev);
2097	if (r)
2098		return r;
2099
2100	return 0;
2101}
2102
2103static int gfx_v8_0_sw_fini(void *handle)
2104{
 
2105	int i;
2106	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2107
2108	amdgpu_bo_free_kernel(&adev->gds.oa_gfx_bo, NULL, NULL);
2109	amdgpu_bo_free_kernel(&adev->gds.gws_gfx_bo, NULL, NULL);
2110	amdgpu_bo_free_kernel(&adev->gds.gds_gfx_bo, NULL, NULL);
2111
2112	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
2113		amdgpu_ring_fini(&adev->gfx.gfx_ring[i]);
2114	for (i = 0; i < adev->gfx.num_compute_rings; i++)
2115		amdgpu_ring_fini(&adev->gfx.compute_ring[i]);
2116
2117	amdgpu_gfx_compute_mqd_sw_fini(adev);
2118	amdgpu_gfx_kiq_free_ring(&adev->gfx.kiq.ring, &adev->gfx.kiq.irq);
2119	amdgpu_gfx_kiq_fini(adev);
2120
2121	gfx_v8_0_mec_fini(adev);
2122	gfx_v8_0_rlc_fini(adev);
2123	amdgpu_bo_free_kernel(&adev->gfx.rlc.clear_state_obj,
2124				&adev->gfx.rlc.clear_state_gpu_addr,
2125				(void **)&adev->gfx.rlc.cs_ptr);
2126	if ((adev->asic_type == CHIP_CARRIZO) ||
2127	    (adev->asic_type == CHIP_STONEY)) {
2128		amdgpu_bo_free_kernel(&adev->gfx.rlc.cp_table_obj,
2129				&adev->gfx.rlc.cp_table_gpu_addr,
2130				(void **)&adev->gfx.rlc.cp_table_ptr);
2131	}
2132	gfx_v8_0_free_microcode(adev);
2133
2134	return 0;
2135}
2136
2137static void gfx_v8_0_tiling_mode_table_init(struct amdgpu_device *adev)
2138{
2139	uint32_t *modearray, *mod2array;
2140	const u32 num_tile_mode_states = ARRAY_SIZE(adev->gfx.config.tile_mode_array);
2141	const u32 num_secondary_tile_mode_states = ARRAY_SIZE(adev->gfx.config.macrotile_mode_array);
2142	u32 reg_offset;
2143
2144	modearray = adev->gfx.config.tile_mode_array;
2145	mod2array = adev->gfx.config.macrotile_mode_array;
2146
2147	for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2148		modearray[reg_offset] = 0;
2149
2150	for (reg_offset = 0; reg_offset <  num_secondary_tile_mode_states; reg_offset++)
2151		mod2array[reg_offset] = 0;
2152
2153	switch (adev->asic_type) {
2154	case CHIP_TOPAZ:
2155		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2156				PIPE_CONFIG(ADDR_SURF_P2) |
2157				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2158				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2159		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2160				PIPE_CONFIG(ADDR_SURF_P2) |
2161				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2162				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2163		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2164				PIPE_CONFIG(ADDR_SURF_P2) |
2165				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2166				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2167		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2168				PIPE_CONFIG(ADDR_SURF_P2) |
2169				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2170				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2171		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2172				PIPE_CONFIG(ADDR_SURF_P2) |
2173				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2174				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2175		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2176				PIPE_CONFIG(ADDR_SURF_P2) |
2177				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2178				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2179		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2180				PIPE_CONFIG(ADDR_SURF_P2) |
2181				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2182				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2183		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2184				PIPE_CONFIG(ADDR_SURF_P2));
2185		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2186				PIPE_CONFIG(ADDR_SURF_P2) |
2187				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2188				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2189		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2190				 PIPE_CONFIG(ADDR_SURF_P2) |
2191				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2192				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2193		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2194				 PIPE_CONFIG(ADDR_SURF_P2) |
2195				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2196				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2197		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2198				 PIPE_CONFIG(ADDR_SURF_P2) |
2199				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2200				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2201		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2202				 PIPE_CONFIG(ADDR_SURF_P2) |
2203				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2204				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2205		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2206				 PIPE_CONFIG(ADDR_SURF_P2) |
2207				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2208				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2209		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2210				 PIPE_CONFIG(ADDR_SURF_P2) |
2211				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2212				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2213		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2214				 PIPE_CONFIG(ADDR_SURF_P2) |
2215				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2216				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2217		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2218				 PIPE_CONFIG(ADDR_SURF_P2) |
2219				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2220				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2221		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2222				 PIPE_CONFIG(ADDR_SURF_P2) |
2223				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2224				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2225		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2226				 PIPE_CONFIG(ADDR_SURF_P2) |
2227				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2228				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2229		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2230				 PIPE_CONFIG(ADDR_SURF_P2) |
2231				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2232				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2233		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2234				 PIPE_CONFIG(ADDR_SURF_P2) |
2235				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2236				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2237		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2238				 PIPE_CONFIG(ADDR_SURF_P2) |
2239				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2240				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2241		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2242				 PIPE_CONFIG(ADDR_SURF_P2) |
2243				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2244				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2245		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2246				 PIPE_CONFIG(ADDR_SURF_P2) |
2247				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2248				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2249		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2250				 PIPE_CONFIG(ADDR_SURF_P2) |
2251				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2252				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2253		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2254				 PIPE_CONFIG(ADDR_SURF_P2) |
2255				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2256				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2257
2258		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2259				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2260				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2261				NUM_BANKS(ADDR_SURF_8_BANK));
2262		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2263				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2264				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2265				NUM_BANKS(ADDR_SURF_8_BANK));
2266		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2267				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2268				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2269				NUM_BANKS(ADDR_SURF_8_BANK));
2270		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2271				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2272				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2273				NUM_BANKS(ADDR_SURF_8_BANK));
2274		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2275				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2276				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2277				NUM_BANKS(ADDR_SURF_8_BANK));
2278		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2279				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2280				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2281				NUM_BANKS(ADDR_SURF_8_BANK));
2282		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2283				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2284				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2285				NUM_BANKS(ADDR_SURF_8_BANK));
2286		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2287				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2288				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2289				NUM_BANKS(ADDR_SURF_16_BANK));
2290		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
2291				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2292				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2293				NUM_BANKS(ADDR_SURF_16_BANK));
2294		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2295				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2296				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2297				 NUM_BANKS(ADDR_SURF_16_BANK));
2298		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2299				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2300				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2301				 NUM_BANKS(ADDR_SURF_16_BANK));
2302		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2303				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2304				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2305				 NUM_BANKS(ADDR_SURF_16_BANK));
2306		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2307				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2308				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2309				 NUM_BANKS(ADDR_SURF_16_BANK));
2310		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2311				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2312				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2313				 NUM_BANKS(ADDR_SURF_8_BANK));
2314
2315		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2316			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
2317			    reg_offset != 23)
2318				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2319
2320		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2321			if (reg_offset != 7)
2322				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2323
2324		break;
2325	case CHIP_FIJI:
 
2326		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2327				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2328				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2329				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2330		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2331				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2332				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2333				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2334		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2335				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2336				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2337				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2338		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2339				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2340				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2341				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2342		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2343				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2344				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2345				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2346		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2347				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2348				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2349				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2350		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2351				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2352				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2353				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2354		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2355				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2356				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2357				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2358		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2359				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
2360		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2361				PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2362				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2363				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2364		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2365				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2366				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2367				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2368		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2369				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2370				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2371				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2372		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2373				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2374				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2375				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2376		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2377				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2378				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2379				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2380		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2381				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2382				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2383				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2384		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2385				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2386				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2387				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2388		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2389				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2390				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2391				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2392		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2393				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2394				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2395				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2396		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2397				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2398				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2399				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2400		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2401				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2402				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2403				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2404		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2405				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2406				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2407				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2408		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2409				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2410				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2411				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2412		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2413				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2414				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2415				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2416		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2417				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2418				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2419				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2420		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2421				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2422				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2423				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2424		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2425				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2426				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2427				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2428		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2429				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2430				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2431				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2432		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2433				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2434				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2435				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2436		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2437				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2438				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2439				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2440		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2441				 PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
2442				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2443				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2444		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2445				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2446				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2447				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2448
2449		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2450				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2451				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2452				NUM_BANKS(ADDR_SURF_8_BANK));
2453		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2454				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2455				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2456				NUM_BANKS(ADDR_SURF_8_BANK));
2457		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2458				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2459				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2460				NUM_BANKS(ADDR_SURF_8_BANK));
2461		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2462				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2463				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2464				NUM_BANKS(ADDR_SURF_8_BANK));
2465		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2466				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2467				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2468				NUM_BANKS(ADDR_SURF_8_BANK));
2469		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2470				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2471				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2472				NUM_BANKS(ADDR_SURF_8_BANK));
2473		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2474				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2475				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2476				NUM_BANKS(ADDR_SURF_8_BANK));
2477		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2478				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2479				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2480				NUM_BANKS(ADDR_SURF_8_BANK));
2481		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2482				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2483				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2484				NUM_BANKS(ADDR_SURF_8_BANK));
2485		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2486				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2487				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2488				 NUM_BANKS(ADDR_SURF_8_BANK));
2489		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2490				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2491				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2492				 NUM_BANKS(ADDR_SURF_8_BANK));
2493		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2494				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2495				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2496				 NUM_BANKS(ADDR_SURF_8_BANK));
2497		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2498				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2499				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2500				 NUM_BANKS(ADDR_SURF_8_BANK));
2501		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2502				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2503				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2504				 NUM_BANKS(ADDR_SURF_4_BANK));
2505
2506		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2507			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2508
2509		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2510			if (reg_offset != 7)
2511				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2512
2513		break;
2514	case CHIP_TONGA:
2515		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2516				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2517				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2518				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2519		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2520				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2521				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2522				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2523		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2524				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2525				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2526				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2527		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2528				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2529				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2530				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2531		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2532				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2533				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2534				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2535		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2536				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2537				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2538				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2539		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2540				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2541				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2542				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2543		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2544				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2545				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2546				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2547		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2548				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2549		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2550				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2551				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2552				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2553		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2554				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2555				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2556				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2557		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2558				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2559				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2560				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2561		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2562				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2563				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2564				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2565		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2566				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2567				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2568				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2569		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2570				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2571				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2572				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2573		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2574				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2575				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2576				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2577		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2578				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2579				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2580				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2581		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2582				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2583				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2584				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2585		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2586				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2587				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2588				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2589		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2590				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2591				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2592				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2593		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2594				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2595				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2596				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2597		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2598				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2599				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2600				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2601		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2602				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2603				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2604				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2605		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2606				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2607				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2608				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2609		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2610				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2611				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2612				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2613		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2614				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2615				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2616				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2617		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2618				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2619				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2620				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2621		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2622				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2623				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2624				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2625		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2626				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2627				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2628				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2629		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2630				 PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2631				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2632				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2633		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2634				 PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2635				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2636				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2637
2638		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2639				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2640				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2641				NUM_BANKS(ADDR_SURF_16_BANK));
2642		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2643				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2644				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2645				NUM_BANKS(ADDR_SURF_16_BANK));
2646		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2647				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2648				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2649				NUM_BANKS(ADDR_SURF_16_BANK));
2650		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2651				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2652				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2653				NUM_BANKS(ADDR_SURF_16_BANK));
2654		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2655				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2656				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2657				NUM_BANKS(ADDR_SURF_16_BANK));
2658		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2659				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2660				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2661				NUM_BANKS(ADDR_SURF_16_BANK));
2662		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2663				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2664				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2665				NUM_BANKS(ADDR_SURF_16_BANK));
2666		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2667				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2668				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2669				NUM_BANKS(ADDR_SURF_16_BANK));
2670		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2671				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2672				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2673				NUM_BANKS(ADDR_SURF_16_BANK));
2674		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2675				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2676				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2677				 NUM_BANKS(ADDR_SURF_16_BANK));
2678		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2679				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2680				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2681				 NUM_BANKS(ADDR_SURF_16_BANK));
2682		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2683				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2684				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2685				 NUM_BANKS(ADDR_SURF_8_BANK));
2686		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2687				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2688				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2689				 NUM_BANKS(ADDR_SURF_4_BANK));
2690		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2691				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2692				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2693				 NUM_BANKS(ADDR_SURF_4_BANK));
2694
2695		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2696			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2697
2698		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2699			if (reg_offset != 7)
2700				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2701
2702		break;
2703	case CHIP_POLARIS11:
2704	case CHIP_POLARIS12:
2705		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2706				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2707				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2708				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2709		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2710				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2711				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2712				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2713		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2714				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2715				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2716				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2717		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2718				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2719				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2720				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2721		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2722				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2723				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2724				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2725		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2726				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2727				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2728				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2729		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2730				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2731				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2732				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2733		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2734				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2735				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2736				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2737		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2738				PIPE_CONFIG(ADDR_SURF_P4_16x16));
2739		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2740				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2741				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2742				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2743		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2744				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2745				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2746				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2747		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2748				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2749				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2750				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2751		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2752				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2753				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2754				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2755		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2756				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2757				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2758				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2759		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2760				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2761				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2762				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2763		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2764				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2765				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2766				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2767		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2768				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2769				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2770				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2771		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2772				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2773				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2774				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2775		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2776				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2777				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2778				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2779		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2780				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2781				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2782				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2783		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2784				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2785				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2786				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2787		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2788				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2789				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2790				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2791		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2792				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2793				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2794				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2795		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2796				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2797				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2798				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2799		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2800				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2801				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2802				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2803		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
2804				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2805				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2806				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2807		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
2808				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2809				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2810				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2811		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2812				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2813				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2814				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2815		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2816				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2817				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2818				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2819		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2820				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2821				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2822				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2823		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2824				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2825				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
2826				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2827
2828		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2829				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2830				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2831				NUM_BANKS(ADDR_SURF_16_BANK));
2832
2833		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2834				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2835				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2836				NUM_BANKS(ADDR_SURF_16_BANK));
2837
2838		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2839				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2840				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2841				NUM_BANKS(ADDR_SURF_16_BANK));
2842
2843		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2844				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2845				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2846				NUM_BANKS(ADDR_SURF_16_BANK));
2847
2848		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2849				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2850				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2851				NUM_BANKS(ADDR_SURF_16_BANK));
2852
2853		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2854				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2855				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2856				NUM_BANKS(ADDR_SURF_16_BANK));
2857
2858		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2859				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2860				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2861				NUM_BANKS(ADDR_SURF_16_BANK));
2862
2863		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2864				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
2865				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2866				NUM_BANKS(ADDR_SURF_16_BANK));
2867
2868		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
2869				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2870				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2871				NUM_BANKS(ADDR_SURF_16_BANK));
2872
2873		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2874				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
2875				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2876				NUM_BANKS(ADDR_SURF_16_BANK));
2877
2878		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2879				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
2880				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
2881				NUM_BANKS(ADDR_SURF_16_BANK));
2882
2883		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2884				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2885				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2886				NUM_BANKS(ADDR_SURF_16_BANK));
2887
2888		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2889				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2890				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
2891				NUM_BANKS(ADDR_SURF_8_BANK));
2892
2893		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
2894				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
2895				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
2896				NUM_BANKS(ADDR_SURF_4_BANK));
2897
2898		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
2899			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
2900
2901		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
2902			if (reg_offset != 7)
2903				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
2904
2905		break;
2906	case CHIP_POLARIS10:
2907		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2908				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2909				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
2910				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2911		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2912				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2913				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
2914				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2915		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2916				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2917				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
2918				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2919		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2920				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2921				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
2922				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2923		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2924				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2925				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2926				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2927		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2928				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2929				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2930				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2931		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2932				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2933				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2934				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2935		modearray[7] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2936				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2937				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
2938				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
2939		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
2940				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
2941		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2942				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2943				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2944				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2945		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2946				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2947				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2948				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2949		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2950				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2951				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2952				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2953		modearray[12] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2954				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2955				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
2956				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2957		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
2958				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2959				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2960				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2961		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
2962				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2963				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2964				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2965		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
2966				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2967				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2968				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
2969		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2970				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2971				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2972				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2973		modearray[17] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
2974				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2975				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2976				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
2977		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2978				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2979				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
2980				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2981		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
2982				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2983				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2984				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2985		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
2986				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2987				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2988				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2989		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
2990				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2991				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2992				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2993		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2994				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
2995				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
2996				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
2997		modearray[23] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
2998				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
2999				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3000				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3001		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3002				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3003				MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3004				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3005		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3006				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3007				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3008				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3009		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3010				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3011				MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3012				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3013		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3014				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3015				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3016				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3017		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3018				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3019				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3020				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3021		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3022				PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
3023				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3024				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3025		modearray[30] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3026				PIPE_CONFIG(ADDR_SURF_P4_16x16) |
3027				MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3028				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3029
3030		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3031				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3032				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3033				NUM_BANKS(ADDR_SURF_16_BANK));
3034
3035		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3036				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3037				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3038				NUM_BANKS(ADDR_SURF_16_BANK));
3039
3040		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3041				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3042				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3043				NUM_BANKS(ADDR_SURF_16_BANK));
3044
3045		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3046				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3047				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3048				NUM_BANKS(ADDR_SURF_16_BANK));
3049
3050		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3051				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3052				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3053				NUM_BANKS(ADDR_SURF_16_BANK));
3054
3055		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3056				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3057				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3058				NUM_BANKS(ADDR_SURF_16_BANK));
3059
3060		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3061				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3062				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3063				NUM_BANKS(ADDR_SURF_16_BANK));
3064
3065		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3066				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3067				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3068				NUM_BANKS(ADDR_SURF_16_BANK));
3069
3070		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3071				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3072				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3073				NUM_BANKS(ADDR_SURF_16_BANK));
3074
3075		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3076				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3077				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3078				NUM_BANKS(ADDR_SURF_16_BANK));
3079
3080		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3081				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3082				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3083				NUM_BANKS(ADDR_SURF_16_BANK));
3084
3085		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3086				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3087				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3088				NUM_BANKS(ADDR_SURF_8_BANK));
3089
3090		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3091				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3092				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3093				NUM_BANKS(ADDR_SURF_4_BANK));
3094
3095		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3096				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3097				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
3098				NUM_BANKS(ADDR_SURF_4_BANK));
3099
3100		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3101			WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3102
3103		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3104			if (reg_offset != 7)
3105				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3106
3107		break;
3108	case CHIP_STONEY:
3109		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3110				PIPE_CONFIG(ADDR_SURF_P2) |
3111				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3112				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3113		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3114				PIPE_CONFIG(ADDR_SURF_P2) |
3115				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3116				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3117		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3118				PIPE_CONFIG(ADDR_SURF_P2) |
3119				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3120				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3121		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3122				PIPE_CONFIG(ADDR_SURF_P2) |
3123				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3124				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3125		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3126				PIPE_CONFIG(ADDR_SURF_P2) |
3127				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3128				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3129		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3130				PIPE_CONFIG(ADDR_SURF_P2) |
3131				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3132				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3133		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3134				PIPE_CONFIG(ADDR_SURF_P2) |
3135				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3136				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3137		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3138				PIPE_CONFIG(ADDR_SURF_P2));
3139		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3140				PIPE_CONFIG(ADDR_SURF_P2) |
3141				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3142				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3143		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3144				 PIPE_CONFIG(ADDR_SURF_P2) |
3145				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3146				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3147		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3148				 PIPE_CONFIG(ADDR_SURF_P2) |
3149				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3150				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3151		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3152				 PIPE_CONFIG(ADDR_SURF_P2) |
3153				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3154				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3155		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3156				 PIPE_CONFIG(ADDR_SURF_P2) |
3157				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3158				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3159		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3160				 PIPE_CONFIG(ADDR_SURF_P2) |
3161				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3162				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3163		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3164				 PIPE_CONFIG(ADDR_SURF_P2) |
3165				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3166				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3167		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3168				 PIPE_CONFIG(ADDR_SURF_P2) |
3169				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3170				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3171		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3172				 PIPE_CONFIG(ADDR_SURF_P2) |
3173				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3174				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3175		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3176				 PIPE_CONFIG(ADDR_SURF_P2) |
3177				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3178				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3179		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3180				 PIPE_CONFIG(ADDR_SURF_P2) |
3181				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3182				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3183		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3184				 PIPE_CONFIG(ADDR_SURF_P2) |
3185				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3186				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3187		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3188				 PIPE_CONFIG(ADDR_SURF_P2) |
3189				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3190				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3191		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3192				 PIPE_CONFIG(ADDR_SURF_P2) |
3193				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3194				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3195		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3196				 PIPE_CONFIG(ADDR_SURF_P2) |
3197				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3198				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3199		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3200				 PIPE_CONFIG(ADDR_SURF_P2) |
3201				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3202				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3203		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3204				 PIPE_CONFIG(ADDR_SURF_P2) |
3205				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3206				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3207		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3208				 PIPE_CONFIG(ADDR_SURF_P2) |
3209				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3210				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3211
3212		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3213				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3214				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3215				NUM_BANKS(ADDR_SURF_8_BANK));
3216		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3217				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3218				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3219				NUM_BANKS(ADDR_SURF_8_BANK));
3220		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3221				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3222				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3223				NUM_BANKS(ADDR_SURF_8_BANK));
3224		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3225				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3226				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3227				NUM_BANKS(ADDR_SURF_8_BANK));
3228		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3229				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3230				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3231				NUM_BANKS(ADDR_SURF_8_BANK));
3232		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3233				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3234				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3235				NUM_BANKS(ADDR_SURF_8_BANK));
3236		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3237				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3238				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3239				NUM_BANKS(ADDR_SURF_8_BANK));
3240		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3241				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3242				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3243				NUM_BANKS(ADDR_SURF_16_BANK));
3244		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3245				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3246				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3247				NUM_BANKS(ADDR_SURF_16_BANK));
3248		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3249				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3250				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3251				 NUM_BANKS(ADDR_SURF_16_BANK));
3252		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3253				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3254				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3255				 NUM_BANKS(ADDR_SURF_16_BANK));
3256		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3257				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3258				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3259				 NUM_BANKS(ADDR_SURF_16_BANK));
3260		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3261				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3262				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3263				 NUM_BANKS(ADDR_SURF_16_BANK));
3264		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3265				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3266				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3267				 NUM_BANKS(ADDR_SURF_8_BANK));
3268
3269		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3270			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
3271			    reg_offset != 23)
3272				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3273
3274		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3275			if (reg_offset != 7)
3276				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3277
3278		break;
3279	default:
3280		dev_warn(adev->dev,
3281			 "Unknown chip type (%d) in function gfx_v8_0_tiling_mode_table_init() falling through to CHIP_CARRIZO\n",
3282			 adev->asic_type);
 
3283
3284	case CHIP_CARRIZO:
3285		modearray[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3286				PIPE_CONFIG(ADDR_SURF_P2) |
3287				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B) |
3288				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3289		modearray[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3290				PIPE_CONFIG(ADDR_SURF_P2) |
3291				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B) |
3292				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3293		modearray[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3294				PIPE_CONFIG(ADDR_SURF_P2) |
3295				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B) |
3296				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3297		modearray[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3298				PIPE_CONFIG(ADDR_SURF_P2) |
3299				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B) |
3300				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3301		modearray[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3302				PIPE_CONFIG(ADDR_SURF_P2) |
3303				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3304				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3305		modearray[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3306				PIPE_CONFIG(ADDR_SURF_P2) |
3307				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3308				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3309		modearray[6] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3310				PIPE_CONFIG(ADDR_SURF_P2) |
3311				TILE_SPLIT(ADDR_SURF_TILE_SPLIT_2KB) |
3312				MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
3313		modearray[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
3314				PIPE_CONFIG(ADDR_SURF_P2));
3315		modearray[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3316				PIPE_CONFIG(ADDR_SURF_P2) |
3317				MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3318				SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3319		modearray[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3320				 PIPE_CONFIG(ADDR_SURF_P2) |
3321				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3322				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3323		modearray[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3324				 PIPE_CONFIG(ADDR_SURF_P2) |
3325				 MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
3326				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3327		modearray[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3328				 PIPE_CONFIG(ADDR_SURF_P2) |
3329				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3330				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3331		modearray[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3332				 PIPE_CONFIG(ADDR_SURF_P2) |
3333				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3334				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3335		modearray[15] = (ARRAY_MODE(ARRAY_3D_TILED_THIN1) |
3336				 PIPE_CONFIG(ADDR_SURF_P2) |
3337				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3338				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3339		modearray[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3340				 PIPE_CONFIG(ADDR_SURF_P2) |
3341				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3342				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3343		modearray[18] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3344				 PIPE_CONFIG(ADDR_SURF_P2) |
3345				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3346				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3347		modearray[19] = (ARRAY_MODE(ARRAY_1D_TILED_THICK) |
3348				 PIPE_CONFIG(ADDR_SURF_P2) |
3349				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3350				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3351		modearray[20] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3352				 PIPE_CONFIG(ADDR_SURF_P2) |
3353				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3354				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3355		modearray[21] = (ARRAY_MODE(ARRAY_3D_TILED_THICK) |
3356				 PIPE_CONFIG(ADDR_SURF_P2) |
3357				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3358				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3359		modearray[22] = (ARRAY_MODE(ARRAY_PRT_TILED_THICK) |
3360				 PIPE_CONFIG(ADDR_SURF_P2) |
3361				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3362				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3363		modearray[24] = (ARRAY_MODE(ARRAY_2D_TILED_THICK) |
3364				 PIPE_CONFIG(ADDR_SURF_P2) |
3365				 MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
3366				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3367		modearray[25] = (ARRAY_MODE(ARRAY_2D_TILED_XTHICK) |
3368				 PIPE_CONFIG(ADDR_SURF_P2) |
3369				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3370				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3371		modearray[26] = (ARRAY_MODE(ARRAY_3D_TILED_XTHICK) |
3372				 PIPE_CONFIG(ADDR_SURF_P2) |
3373				 MICRO_TILE_MODE_NEW(ADDR_SURF_THICK_MICRO_TILING) |
3374				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_1));
3375		modearray[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
3376				 PIPE_CONFIG(ADDR_SURF_P2) |
3377				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3378				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3379		modearray[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
3380				 PIPE_CONFIG(ADDR_SURF_P2) |
3381				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3382				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
3383		modearray[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
3384				 PIPE_CONFIG(ADDR_SURF_P2) |
3385				 MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
3386				 SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_8));
3387
3388		mod2array[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3389				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3390				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3391				NUM_BANKS(ADDR_SURF_8_BANK));
3392		mod2array[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3393				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3394				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3395				NUM_BANKS(ADDR_SURF_8_BANK));
3396		mod2array[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3397				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3398				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3399				NUM_BANKS(ADDR_SURF_8_BANK));
3400		mod2array[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3401				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3402				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3403				NUM_BANKS(ADDR_SURF_8_BANK));
3404		mod2array[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3405				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3406				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3407				NUM_BANKS(ADDR_SURF_8_BANK));
3408		mod2array[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3409				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3410				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3411				NUM_BANKS(ADDR_SURF_8_BANK));
3412		mod2array[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3413				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3414				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3415				NUM_BANKS(ADDR_SURF_8_BANK));
3416		mod2array[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3417				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
3418				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3419				NUM_BANKS(ADDR_SURF_16_BANK));
3420		mod2array[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
3421				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3422				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3423				NUM_BANKS(ADDR_SURF_16_BANK));
3424		mod2array[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3425				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
3426				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3427				 NUM_BANKS(ADDR_SURF_16_BANK));
3428		mod2array[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
3429				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3430				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3431				 NUM_BANKS(ADDR_SURF_16_BANK));
3432		mod2array[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3433				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
3434				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3435				 NUM_BANKS(ADDR_SURF_16_BANK));
3436		mod2array[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3437				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3438				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
3439				 NUM_BANKS(ADDR_SURF_16_BANK));
3440		mod2array[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
3441				 BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
3442				 MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
3443				 NUM_BANKS(ADDR_SURF_8_BANK));
3444
3445		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
3446			if (reg_offset != 7 && reg_offset != 12 && reg_offset != 17 &&
3447			    reg_offset != 23)
3448				WREG32(mmGB_TILE_MODE0 + reg_offset, modearray[reg_offset]);
3449
3450		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
3451			if (reg_offset != 7)
3452				WREG32(mmGB_MACROTILE_MODE0 + reg_offset, mod2array[reg_offset]);
3453
3454		break;
3455	}
3456}
3457
3458static void gfx_v8_0_select_se_sh(struct amdgpu_device *adev,
3459				  u32 se_num, u32 sh_num, u32 instance)
 
3460{
3461	u32 data;
3462
3463	if (instance == 0xffffffff)
3464		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES, 1);
3465	else
3466		data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX, instance);
3467
3468	if (se_num == 0xffffffff)
3469		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES, 1);
3470	else
3471		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
3472
3473	if (sh_num == 0xffffffff)
3474		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES, 1);
3475	else
3476		data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
3477
3478	WREG32(mmGRBM_GFX_INDEX, data);
3479}
3480
3481static void gfx_v8_0_select_me_pipe_q(struct amdgpu_device *adev,
3482				  u32 me, u32 pipe, u32 q)
3483{
3484	vi_srbm_select(adev, me, pipe, q, 0);
3485}
3486
3487static u32 gfx_v8_0_get_rb_active_bitmap(struct amdgpu_device *adev)
3488{
3489	u32 data, mask;
3490
3491	data =  RREG32(mmCC_RB_BACKEND_DISABLE) |
3492		RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3493
3494	data = REG_GET_FIELD(data, GC_USER_RB_BACKEND_DISABLE, BACKEND_DISABLE);
3495
3496	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_backends_per_se /
3497					 adev->gfx.config.max_sh_per_se);
3498
3499	return (~data) & mask;
3500}
3501
3502static void
3503gfx_v8_0_raster_config(struct amdgpu_device *adev, u32 *rconf, u32 *rconf1)
3504{
3505	switch (adev->asic_type) {
3506	case CHIP_FIJI:
 
3507		*rconf |= RB_MAP_PKR0(2) | RB_MAP_PKR1(2) |
3508			  RB_XSEL2(1) | PKR_MAP(2) |
3509			  PKR_XSEL(1) | PKR_YSEL(1) |
3510			  SE_MAP(2) | SE_XSEL(2) | SE_YSEL(3);
3511		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(3) |
3512			   SE_PAIR_YSEL(2);
3513		break;
3514	case CHIP_TONGA:
3515	case CHIP_POLARIS10:
3516		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3517			  SE_XSEL(1) | SE_YSEL(1);
3518		*rconf1 |= SE_PAIR_MAP(2) | SE_PAIR_XSEL(2) |
3519			   SE_PAIR_YSEL(2);
3520		break;
3521	case CHIP_TOPAZ:
3522	case CHIP_CARRIZO:
3523		*rconf |= RB_MAP_PKR0(2);
3524		*rconf1 |= 0x0;
3525		break;
3526	case CHIP_POLARIS11:
3527	case CHIP_POLARIS12:
3528		*rconf |= RB_MAP_PKR0(2) | RB_XSEL2(1) | SE_MAP(2) |
3529			  SE_XSEL(1) | SE_YSEL(1);
3530		*rconf1 |= 0x0;
3531		break;
3532	case CHIP_STONEY:
3533		*rconf |= 0x0;
3534		*rconf1 |= 0x0;
3535		break;
3536	default:
3537		DRM_ERROR("unknown asic: 0x%x\n", adev->asic_type);
3538		break;
3539	}
3540}
3541
3542static void
3543gfx_v8_0_write_harvested_raster_configs(struct amdgpu_device *adev,
3544					u32 raster_config, u32 raster_config_1,
3545					unsigned rb_mask, unsigned num_rb)
3546{
3547	unsigned sh_per_se = max_t(unsigned, adev->gfx.config.max_sh_per_se, 1);
3548	unsigned num_se = max_t(unsigned, adev->gfx.config.max_shader_engines, 1);
3549	unsigned rb_per_pkr = min_t(unsigned, num_rb / num_se / sh_per_se, 2);
3550	unsigned rb_per_se = num_rb / num_se;
3551	unsigned se_mask[4];
3552	unsigned se;
3553
3554	se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
3555	se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
3556	se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
3557	se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
3558
3559	WARN_ON(!(num_se == 1 || num_se == 2 || num_se == 4));
3560	WARN_ON(!(sh_per_se == 1 || sh_per_se == 2));
3561	WARN_ON(!(rb_per_pkr == 1 || rb_per_pkr == 2));
3562
3563	if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
3564			     (!se_mask[2] && !se_mask[3]))) {
3565		raster_config_1 &= ~SE_PAIR_MAP_MASK;
3566
3567		if (!se_mask[0] && !se_mask[1]) {
3568			raster_config_1 |=
3569				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_3);
3570		} else {
3571			raster_config_1 |=
3572				SE_PAIR_MAP(RASTER_CONFIG_SE_PAIR_MAP_0);
3573		}
3574	}
3575
3576	for (se = 0; se < num_se; se++) {
3577		unsigned raster_config_se = raster_config;
3578		unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
3579		unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
3580		int idx = (se / 2) * 2;
3581
3582		if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
3583			raster_config_se &= ~SE_MAP_MASK;
3584
3585			if (!se_mask[idx]) {
3586				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_3);
3587			} else {
3588				raster_config_se |= SE_MAP(RASTER_CONFIG_SE_MAP_0);
3589			}
3590		}
3591
3592		pkr0_mask &= rb_mask;
3593		pkr1_mask &= rb_mask;
3594		if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
3595			raster_config_se &= ~PKR_MAP_MASK;
3596
3597			if (!pkr0_mask) {
3598				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_3);
3599			} else {
3600				raster_config_se |= PKR_MAP(RASTER_CONFIG_PKR_MAP_0);
3601			}
3602		}
3603
3604		if (rb_per_se >= 2) {
3605			unsigned rb0_mask = 1 << (se * rb_per_se);
3606			unsigned rb1_mask = rb0_mask << 1;
3607
3608			rb0_mask &= rb_mask;
3609			rb1_mask &= rb_mask;
3610			if (!rb0_mask || !rb1_mask) {
3611				raster_config_se &= ~RB_MAP_PKR0_MASK;
3612
3613				if (!rb0_mask) {
3614					raster_config_se |=
3615						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_3);
3616				} else {
3617					raster_config_se |=
3618						RB_MAP_PKR0(RASTER_CONFIG_RB_MAP_0);
3619				}
3620			}
3621
3622			if (rb_per_se > 2) {
3623				rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
3624				rb1_mask = rb0_mask << 1;
3625				rb0_mask &= rb_mask;
3626				rb1_mask &= rb_mask;
3627				if (!rb0_mask || !rb1_mask) {
3628					raster_config_se &= ~RB_MAP_PKR1_MASK;
3629
3630					if (!rb0_mask) {
3631						raster_config_se |=
3632							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_3);
3633					} else {
3634						raster_config_se |=
3635							RB_MAP_PKR1(RASTER_CONFIG_RB_MAP_0);
3636					}
3637				}
3638			}
3639		}
3640
3641		/* GRBM_GFX_INDEX has a different offset on VI */
3642		gfx_v8_0_select_se_sh(adev, se, 0xffffffff, 0xffffffff);
3643		WREG32(mmPA_SC_RASTER_CONFIG, raster_config_se);
3644		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3645	}
3646
3647	/* GRBM_GFX_INDEX has a different offset on VI */
3648	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3649}
3650
3651static void gfx_v8_0_setup_rb(struct amdgpu_device *adev)
3652{
3653	int i, j;
3654	u32 data;
3655	u32 raster_config = 0, raster_config_1 = 0;
3656	u32 active_rbs = 0;
3657	u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se /
3658					adev->gfx.config.max_sh_per_se;
3659	unsigned num_rb_pipes;
3660
3661	mutex_lock(&adev->grbm_idx_mutex);
3662	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3663		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3664			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
3665			data = gfx_v8_0_get_rb_active_bitmap(adev);
3666			active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) *
3667					       rb_bitmap_width_per_sh);
3668		}
3669	}
3670	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3671
3672	adev->gfx.config.backend_enable_mask = active_rbs;
3673	adev->gfx.config.num_rbs = hweight32(active_rbs);
3674
3675	num_rb_pipes = min_t(unsigned, adev->gfx.config.max_backends_per_se *
3676			     adev->gfx.config.max_shader_engines, 16);
3677
3678	gfx_v8_0_raster_config(adev, &raster_config, &raster_config_1);
3679
3680	if (!adev->gfx.config.backend_enable_mask ||
3681			adev->gfx.config.num_rbs >= num_rb_pipes) {
3682		WREG32(mmPA_SC_RASTER_CONFIG, raster_config);
3683		WREG32(mmPA_SC_RASTER_CONFIG_1, raster_config_1);
3684	} else {
3685		gfx_v8_0_write_harvested_raster_configs(adev, raster_config, raster_config_1,
3686							adev->gfx.config.backend_enable_mask,
3687							num_rb_pipes);
3688	}
3689
3690	/* cache the values for userspace */
3691	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3692		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3693			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
3694			adev->gfx.config.rb_config[i][j].rb_backend_disable =
3695				RREG32(mmCC_RB_BACKEND_DISABLE);
3696			adev->gfx.config.rb_config[i][j].user_rb_backend_disable =
3697				RREG32(mmGC_USER_RB_BACKEND_DISABLE);
3698			adev->gfx.config.rb_config[i][j].raster_config =
3699				RREG32(mmPA_SC_RASTER_CONFIG);
3700			adev->gfx.config.rb_config[i][j].raster_config_1 =
3701				RREG32(mmPA_SC_RASTER_CONFIG_1);
3702		}
3703	}
3704	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3705	mutex_unlock(&adev->grbm_idx_mutex);
3706}
3707
 
3708/**
3709 * gfx_v8_0_init_compute_vmid - gart enable
3710 *
3711 * @adev: amdgpu_device pointer
3712 *
3713 * Initialize compute vmid sh_mem registers
3714 *
3715 */
3716#define DEFAULT_SH_MEM_BASES	(0x6000)
3717#define FIRST_COMPUTE_VMID	(8)
3718#define LAST_COMPUTE_VMID	(16)
3719static void gfx_v8_0_init_compute_vmid(struct amdgpu_device *adev)
3720{
3721	int i;
3722	uint32_t sh_mem_config;
3723	uint32_t sh_mem_bases;
3724
3725	/*
3726	 * Configure apertures:
3727	 * LDS:         0x60000000'00000000 - 0x60000001'00000000 (4GB)
3728	 * Scratch:     0x60000001'00000000 - 0x60000002'00000000 (4GB)
3729	 * GPUVM:       0x60010000'00000000 - 0x60020000'00000000 (1TB)
3730	 */
3731	sh_mem_bases = DEFAULT_SH_MEM_BASES | (DEFAULT_SH_MEM_BASES << 16);
3732
3733	sh_mem_config = SH_MEM_ADDRESS_MODE_HSA64 <<
3734			SH_MEM_CONFIG__ADDRESS_MODE__SHIFT |
3735			SH_MEM_ALIGNMENT_MODE_UNALIGNED <<
3736			SH_MEM_CONFIG__ALIGNMENT_MODE__SHIFT |
3737			MTYPE_CC << SH_MEM_CONFIG__DEFAULT_MTYPE__SHIFT |
3738			SH_MEM_CONFIG__PRIVATE_ATC_MASK;
3739
3740	mutex_lock(&adev->srbm_mutex);
3741	for (i = FIRST_COMPUTE_VMID; i < LAST_COMPUTE_VMID; i++) {
3742		vi_srbm_select(adev, 0, 0, 0, i);
3743		/* CP and shaders */
3744		WREG32(mmSH_MEM_CONFIG, sh_mem_config);
3745		WREG32(mmSH_MEM_APE1_BASE, 1);
3746		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3747		WREG32(mmSH_MEM_BASES, sh_mem_bases);
3748	}
3749	vi_srbm_select(adev, 0, 0, 0, 0);
3750	mutex_unlock(&adev->srbm_mutex);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3751}
3752
3753static void gfx_v8_0_config_init(struct amdgpu_device *adev)
3754{
3755	switch (adev->asic_type) {
3756	default:
3757		adev->gfx.config.double_offchip_lds_buf = 1;
3758		break;
3759	case CHIP_CARRIZO:
3760	case CHIP_STONEY:
3761		adev->gfx.config.double_offchip_lds_buf = 0;
3762		break;
3763	}
3764}
3765
3766static void gfx_v8_0_gpu_init(struct amdgpu_device *adev)
3767{
3768	u32 tmp, sh_static_mem_cfg;
3769	int i;
3770
3771	WREG32_FIELD(GRBM_CNTL, READ_TIMEOUT, 0xFF);
3772	WREG32(mmGB_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
3773	WREG32(mmHDP_ADDR_CONFIG, adev->gfx.config.gb_addr_config);
3774	WREG32(mmDMIF_ADDR_CALC, adev->gfx.config.gb_addr_config);
3775
3776	gfx_v8_0_tiling_mode_table_init(adev);
3777	gfx_v8_0_setup_rb(adev);
3778	gfx_v8_0_get_cu_info(adev);
3779	gfx_v8_0_config_init(adev);
3780
3781	/* XXX SH_MEM regs */
3782	/* where to put LDS, scratch, GPUVM in FSA64 space */
3783	sh_static_mem_cfg = REG_SET_FIELD(0, SH_STATIC_MEM_CONFIG,
3784				   SWIZZLE_ENABLE, 1);
3785	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
3786				   ELEMENT_SIZE, 1);
3787	sh_static_mem_cfg = REG_SET_FIELD(sh_static_mem_cfg, SH_STATIC_MEM_CONFIG,
3788				   INDEX_STRIDE, 3);
3789	WREG32(mmSH_STATIC_MEM_CONFIG, sh_static_mem_cfg);
3790
3791	mutex_lock(&adev->srbm_mutex);
3792	for (i = 0; i < adev->vm_manager.id_mgr[0].num_ids; i++) {
3793		vi_srbm_select(adev, 0, 0, 0, i);
3794		/* CP and shaders */
3795		if (i == 0) {
3796			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_UC);
3797			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
3798			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
3799					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3800			WREG32(mmSH_MEM_CONFIG, tmp);
3801			WREG32(mmSH_MEM_BASES, 0);
3802		} else {
3803			tmp = REG_SET_FIELD(0, SH_MEM_CONFIG, DEFAULT_MTYPE, MTYPE_NC);
3804			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, APE1_MTYPE, MTYPE_UC);
3805			tmp = REG_SET_FIELD(tmp, SH_MEM_CONFIG, ALIGNMENT_MODE,
3806					    SH_MEM_ALIGNMENT_MODE_UNALIGNED);
3807			WREG32(mmSH_MEM_CONFIG, tmp);
3808			tmp = adev->gmc.shared_aperture_start >> 48;
3809			WREG32(mmSH_MEM_BASES, tmp);
3810		}
3811
3812		WREG32(mmSH_MEM_APE1_BASE, 1);
3813		WREG32(mmSH_MEM_APE1_LIMIT, 0);
3814	}
3815	vi_srbm_select(adev, 0, 0, 0, 0);
3816	mutex_unlock(&adev->srbm_mutex);
3817
3818	gfx_v8_0_init_compute_vmid(adev);
 
3819
3820	mutex_lock(&adev->grbm_idx_mutex);
3821	/*
3822	 * making sure that the following register writes will be broadcasted
3823	 * to all the shaders
3824	 */
3825	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3826
3827	WREG32(mmPA_SC_FIFO_SIZE,
3828		   (adev->gfx.config.sc_prim_fifo_size_frontend <<
3829			PA_SC_FIFO_SIZE__SC_FRONTEND_PRIM_FIFO_SIZE__SHIFT) |
3830		   (adev->gfx.config.sc_prim_fifo_size_backend <<
3831			PA_SC_FIFO_SIZE__SC_BACKEND_PRIM_FIFO_SIZE__SHIFT) |
3832		   (adev->gfx.config.sc_hiz_tile_fifo_size <<
3833			PA_SC_FIFO_SIZE__SC_HIZ_TILE_FIFO_SIZE__SHIFT) |
3834		   (adev->gfx.config.sc_earlyz_tile_fifo_size <<
3835			PA_SC_FIFO_SIZE__SC_EARLYZ_TILE_FIFO_SIZE__SHIFT));
3836
3837	tmp = RREG32(mmSPI_ARB_PRIORITY);
3838	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS0, 2);
3839	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS1, 2);
3840	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS2, 2);
3841	tmp = REG_SET_FIELD(tmp, SPI_ARB_PRIORITY, PIPE_ORDER_TS3, 2);
3842	WREG32(mmSPI_ARB_PRIORITY, tmp);
3843
3844	mutex_unlock(&adev->grbm_idx_mutex);
3845
3846}
3847
3848static void gfx_v8_0_wait_for_rlc_serdes(struct amdgpu_device *adev)
3849{
3850	u32 i, j, k;
3851	u32 mask;
3852
3853	mutex_lock(&adev->grbm_idx_mutex);
3854	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
3855		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
3856			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
3857			for (k = 0; k < adev->usec_timeout; k++) {
3858				if (RREG32(mmRLC_SERDES_CU_MASTER_BUSY) == 0)
3859					break;
3860				udelay(1);
3861			}
3862			if (k == adev->usec_timeout) {
3863				gfx_v8_0_select_se_sh(adev, 0xffffffff,
3864						      0xffffffff, 0xffffffff);
3865				mutex_unlock(&adev->grbm_idx_mutex);
3866				DRM_INFO("Timeout wait for RLC serdes %u,%u\n",
3867					 i, j);
3868				return;
3869			}
3870		}
3871	}
3872	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
3873	mutex_unlock(&adev->grbm_idx_mutex);
3874
3875	mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
3876		RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
3877		RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
3878		RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
3879	for (k = 0; k < adev->usec_timeout; k++) {
3880		if ((RREG32(mmRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
3881			break;
3882		udelay(1);
3883	}
3884}
3885
3886static void gfx_v8_0_enable_gui_idle_interrupt(struct amdgpu_device *adev,
3887					       bool enable)
3888{
3889	u32 tmp = RREG32(mmCP_INT_CNTL_RING0);
3890
3891	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE, enable ? 1 : 0);
3892	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_EMPTY_INT_ENABLE, enable ? 1 : 0);
3893	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CMP_BUSY_INT_ENABLE, enable ? 1 : 0);
3894	tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, GFX_IDLE_INT_ENABLE, enable ? 1 : 0);
3895
3896	WREG32(mmCP_INT_CNTL_RING0, tmp);
3897}
3898
3899static void gfx_v8_0_init_csb(struct amdgpu_device *adev)
3900{
 
3901	/* csib */
3902	WREG32(mmRLC_CSIB_ADDR_HI,
3903			adev->gfx.rlc.clear_state_gpu_addr >> 32);
3904	WREG32(mmRLC_CSIB_ADDR_LO,
3905			adev->gfx.rlc.clear_state_gpu_addr & 0xfffffffc);
3906	WREG32(mmRLC_CSIB_LENGTH,
3907			adev->gfx.rlc.clear_state_size);
3908}
3909
3910static void gfx_v8_0_parse_ind_reg_list(int *register_list_format,
3911				int ind_offset,
3912				int list_size,
3913				int *unique_indices,
3914				int *indices_count,
3915				int max_indices,
3916				int *ind_start_offsets,
3917				int *offset_count,
3918				int max_offset)
3919{
3920	int indices;
3921	bool new_entry = true;
3922
3923	for (; ind_offset < list_size; ind_offset++) {
3924
3925		if (new_entry) {
3926			new_entry = false;
3927			ind_start_offsets[*offset_count] = ind_offset;
3928			*offset_count = *offset_count + 1;
3929			BUG_ON(*offset_count >= max_offset);
3930		}
3931
3932		if (register_list_format[ind_offset] == 0xFFFFFFFF) {
3933			new_entry = true;
3934			continue;
3935		}
3936
3937		ind_offset += 2;
3938
3939		/* look for the matching indice */
3940		for (indices = 0;
3941			indices < *indices_count;
3942			indices++) {
3943			if (unique_indices[indices] ==
3944				register_list_format[ind_offset])
3945				break;
3946		}
3947
3948		if (indices >= *indices_count) {
3949			unique_indices[*indices_count] =
3950				register_list_format[ind_offset];
3951			indices = *indices_count;
3952			*indices_count = *indices_count + 1;
3953			BUG_ON(*indices_count >= max_indices);
3954		}
3955
3956		register_list_format[ind_offset] = indices;
3957	}
3958}
3959
3960static int gfx_v8_0_init_save_restore_list(struct amdgpu_device *adev)
3961{
3962	int i, temp, data;
3963	int unique_indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
3964	int indices_count = 0;
3965	int indirect_start_offsets[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3966	int offset_count = 0;
3967
3968	int list_size;
3969	unsigned int *register_list_format =
3970		kmalloc(adev->gfx.rlc.reg_list_format_size_bytes, GFP_KERNEL);
 
3971	if (!register_list_format)
3972		return -ENOMEM;
3973	memcpy(register_list_format, adev->gfx.rlc.register_list_format,
3974			adev->gfx.rlc.reg_list_format_size_bytes);
3975
3976	gfx_v8_0_parse_ind_reg_list(register_list_format,
3977				RLC_FormatDirectRegListLength,
3978				adev->gfx.rlc.reg_list_format_size_bytes >> 2,
3979				unique_indices,
3980				&indices_count,
3981				ARRAY_SIZE(unique_indices),
3982				indirect_start_offsets,
3983				&offset_count,
3984				ARRAY_SIZE(indirect_start_offsets));
3985
3986	/* save and restore list */
3987	WREG32_FIELD(RLC_SRM_CNTL, AUTO_INCR_ADDR, 1);
3988
3989	WREG32(mmRLC_SRM_ARAM_ADDR, 0);
3990	for (i = 0; i < adev->gfx.rlc.reg_list_size_bytes >> 2; i++)
3991		WREG32(mmRLC_SRM_ARAM_DATA, adev->gfx.rlc.register_restore[i]);
3992
3993	/* indirect list */
3994	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_list_format_start);
3995	for (i = 0; i < adev->gfx.rlc.reg_list_format_size_bytes >> 2; i++)
3996		WREG32(mmRLC_GPM_SCRATCH_DATA, register_list_format[i]);
3997
3998	list_size = adev->gfx.rlc.reg_list_size_bytes >> 2;
3999	list_size = list_size >> 1;
4000	WREG32(mmRLC_GPM_SCRATCH_ADDR, adev->gfx.rlc.reg_restore_list_size);
4001	WREG32(mmRLC_GPM_SCRATCH_DATA, list_size);
4002
4003	/* starting offsets starts */
4004	WREG32(mmRLC_GPM_SCRATCH_ADDR,
4005		adev->gfx.rlc.starting_offsets_start);
4006	for (i = 0; i < ARRAY_SIZE(indirect_start_offsets); i++)
4007		WREG32(mmRLC_GPM_SCRATCH_DATA,
4008				indirect_start_offsets[i]);
4009
4010	/* unique indices */
4011	temp = mmRLC_SRM_INDEX_CNTL_ADDR_0;
4012	data = mmRLC_SRM_INDEX_CNTL_DATA_0;
4013	for (i = 0; i < ARRAY_SIZE(unique_indices); i++) {
4014		if (unique_indices[i] != 0) {
4015			WREG32(temp + i, unique_indices[i] & 0x3FFFF);
4016			WREG32(data + i, unique_indices[i] >> 20);
4017		}
4018	}
4019	kfree(register_list_format);
4020
4021	return 0;
4022}
4023
4024static void gfx_v8_0_enable_save_restore_machine(struct amdgpu_device *adev)
4025{
4026	WREG32_FIELD(RLC_SRM_CNTL, SRM_ENABLE, 1);
4027}
4028
4029static void gfx_v8_0_init_power_gating(struct amdgpu_device *adev)
4030{
4031	uint32_t data;
4032
4033	WREG32_FIELD(CP_RB_WPTR_POLL_CNTL, IDLE_POLL_COUNT, 0x60);
4034
4035	data = REG_SET_FIELD(0, RLC_PG_DELAY, POWER_UP_DELAY, 0x10);
4036	data = REG_SET_FIELD(data, RLC_PG_DELAY, POWER_DOWN_DELAY, 0x10);
4037	data = REG_SET_FIELD(data, RLC_PG_DELAY, CMD_PROPAGATE_DELAY, 0x10);
4038	data = REG_SET_FIELD(data, RLC_PG_DELAY, MEM_SLEEP_DELAY, 0x10);
4039	WREG32(mmRLC_PG_DELAY, data);
4040
4041	WREG32_FIELD(RLC_PG_DELAY_2, SERDES_CMD_DELAY, 0x3);
4042	WREG32_FIELD(RLC_AUTO_PG_CTRL, GRBM_REG_SAVE_GFX_IDLE_THRESHOLD, 0x55f0);
4043
4044}
4045
4046static void cz_enable_sck_slow_down_on_power_up(struct amdgpu_device *adev,
4047						bool enable)
4048{
4049	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PU_ENABLE, enable ? 1 : 0);
4050}
4051
4052static void cz_enable_sck_slow_down_on_power_down(struct amdgpu_device *adev,
4053						  bool enable)
4054{
4055	WREG32_FIELD(RLC_PG_CNTL, SMU_CLK_SLOWDOWN_ON_PD_ENABLE, enable ? 1 : 0);
4056}
4057
4058static void cz_enable_cp_power_gating(struct amdgpu_device *adev, bool enable)
4059{
4060	WREG32_FIELD(RLC_PG_CNTL, CP_PG_DISABLE, enable ? 0 : 1);
4061}
4062
4063static void gfx_v8_0_init_pg(struct amdgpu_device *adev)
4064{
4065	if ((adev->asic_type == CHIP_CARRIZO) ||
4066	    (adev->asic_type == CHIP_STONEY)) {
4067		gfx_v8_0_init_csb(adev);
4068		gfx_v8_0_init_save_restore_list(adev);
4069		gfx_v8_0_enable_save_restore_machine(adev);
4070		WREG32(mmRLC_JUMP_TABLE_RESTORE, adev->gfx.rlc.cp_table_gpu_addr >> 8);
4071		gfx_v8_0_init_power_gating(adev);
4072		WREG32(mmRLC_PG_ALWAYS_ON_CU_MASK, adev->gfx.cu_info.ao_cu_mask);
4073	} else if ((adev->asic_type == CHIP_POLARIS11) ||
4074		   (adev->asic_type == CHIP_POLARIS12)) {
 
4075		gfx_v8_0_init_csb(adev);
4076		gfx_v8_0_init_save_restore_list(adev);
4077		gfx_v8_0_enable_save_restore_machine(adev);
4078		gfx_v8_0_init_power_gating(adev);
4079	}
4080
4081}
4082
4083static void gfx_v8_0_rlc_stop(struct amdgpu_device *adev)
4084{
4085	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 0);
4086
4087	gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4088	gfx_v8_0_wait_for_rlc_serdes(adev);
4089}
4090
4091static void gfx_v8_0_rlc_reset(struct amdgpu_device *adev)
4092{
4093	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
4094	udelay(50);
4095
4096	WREG32_FIELD(GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
4097	udelay(50);
4098}
4099
4100static void gfx_v8_0_rlc_start(struct amdgpu_device *adev)
4101{
4102	WREG32_FIELD(RLC_CNTL, RLC_ENABLE_F32, 1);
4103
4104	/* carrizo do enable cp interrupt after cp inited */
4105	if (!(adev->flags & AMD_IS_APU))
4106		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4107
4108	udelay(50);
4109}
4110
4111static int gfx_v8_0_rlc_load_microcode(struct amdgpu_device *adev)
4112{
4113	const struct rlc_firmware_header_v2_0 *hdr;
4114	const __le32 *fw_data;
4115	unsigned i, fw_size;
4116
4117	if (!adev->gfx.rlc_fw)
4118		return -EINVAL;
4119
4120	hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
4121	amdgpu_ucode_print_rlc_hdr(&hdr->header);
4122
4123	fw_data = (const __le32 *)(adev->gfx.rlc_fw->data +
4124			   le32_to_cpu(hdr->header.ucode_array_offset_bytes));
4125	fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
4126
4127	WREG32(mmRLC_GPM_UCODE_ADDR, 0);
4128	for (i = 0; i < fw_size; i++)
4129		WREG32(mmRLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
4130	WREG32(mmRLC_GPM_UCODE_ADDR, adev->gfx.rlc_fw_version);
4131
4132	return 0;
4133}
4134
4135static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
4136{
4137	int r;
4138	u32 tmp;
4139
4140	gfx_v8_0_rlc_stop(adev);
4141
4142	/* disable CG */
4143	tmp = RREG32(mmRLC_CGCG_CGLS_CTRL);
4144	tmp &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
4145		 RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
4146	WREG32(mmRLC_CGCG_CGLS_CTRL, tmp);
4147	if (adev->asic_type == CHIP_POLARIS11 ||
4148	    adev->asic_type == CHIP_POLARIS10 ||
4149	    adev->asic_type == CHIP_POLARIS12) {
4150		tmp = RREG32(mmRLC_CGCG_CGLS_CTRL_3D);
4151		tmp &= ~0x3;
4152		WREG32(mmRLC_CGCG_CGLS_CTRL_3D, tmp);
4153	}
4154
4155	/* disable PG */
4156	WREG32(mmRLC_PG_CNTL, 0);
4157
4158	gfx_v8_0_rlc_reset(adev);
4159	gfx_v8_0_init_pg(adev);
4160
4161
4162	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
4163		/* legacy rlc firmware loading */
4164		r = gfx_v8_0_rlc_load_microcode(adev);
4165		if (r)
4166			return r;
4167	}
4168
4169	gfx_v8_0_rlc_start(adev);
4170
4171	return 0;
4172}
4173
4174static void gfx_v8_0_cp_gfx_enable(struct amdgpu_device *adev, bool enable)
4175{
4176	int i;
4177	u32 tmp = RREG32(mmCP_ME_CNTL);
4178
4179	if (enable) {
4180		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 0);
4181		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 0);
4182		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 0);
4183	} else {
4184		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, ME_HALT, 1);
4185		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, PFP_HALT, 1);
4186		tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT, 1);
4187		for (i = 0; i < adev->gfx.num_gfx_rings; i++)
4188			adev->gfx.gfx_ring[i].ready = false;
4189	}
4190	WREG32(mmCP_ME_CNTL, tmp);
4191	udelay(50);
4192}
4193
4194static int gfx_v8_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
4195{
4196	const struct gfx_firmware_header_v1_0 *pfp_hdr;
4197	const struct gfx_firmware_header_v1_0 *ce_hdr;
4198	const struct gfx_firmware_header_v1_0 *me_hdr;
4199	const __le32 *fw_data;
4200	unsigned i, fw_size;
4201
4202	if (!adev->gfx.me_fw || !adev->gfx.pfp_fw || !adev->gfx.ce_fw)
4203		return -EINVAL;
4204
4205	pfp_hdr = (const struct gfx_firmware_header_v1_0 *)
4206		adev->gfx.pfp_fw->data;
4207	ce_hdr = (const struct gfx_firmware_header_v1_0 *)
4208		adev->gfx.ce_fw->data;
4209	me_hdr = (const struct gfx_firmware_header_v1_0 *)
4210		adev->gfx.me_fw->data;
4211
4212	amdgpu_ucode_print_gfx_hdr(&pfp_hdr->header);
4213	amdgpu_ucode_print_gfx_hdr(&ce_hdr->header);
4214	amdgpu_ucode_print_gfx_hdr(&me_hdr->header);
4215
4216	gfx_v8_0_cp_gfx_enable(adev, false);
4217
4218	/* PFP */
4219	fw_data = (const __le32 *)
4220		(adev->gfx.pfp_fw->data +
4221		 le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
4222	fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
4223	WREG32(mmCP_PFP_UCODE_ADDR, 0);
4224	for (i = 0; i < fw_size; i++)
4225		WREG32(mmCP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
4226	WREG32(mmCP_PFP_UCODE_ADDR, adev->gfx.pfp_fw_version);
4227
4228	/* CE */
4229	fw_data = (const __le32 *)
4230		(adev->gfx.ce_fw->data +
4231		 le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
4232	fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
4233	WREG32(mmCP_CE_UCODE_ADDR, 0);
4234	for (i = 0; i < fw_size; i++)
4235		WREG32(mmCP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
4236	WREG32(mmCP_CE_UCODE_ADDR, adev->gfx.ce_fw_version);
4237
4238	/* ME */
4239	fw_data = (const __le32 *)
4240		(adev->gfx.me_fw->data +
4241		 le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
4242	fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
4243	WREG32(mmCP_ME_RAM_WADDR, 0);
4244	for (i = 0; i < fw_size; i++)
4245		WREG32(mmCP_ME_RAM_DATA, le32_to_cpup(fw_data++));
4246	WREG32(mmCP_ME_RAM_WADDR, adev->gfx.me_fw_version);
4247
4248	return 0;
4249}
4250
4251static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev)
4252{
4253	u32 count = 0;
4254	const struct cs_section_def *sect = NULL;
4255	const struct cs_extent_def *ext = NULL;
4256
4257	/* begin clear state */
4258	count += 2;
4259	/* context control state */
4260	count += 3;
4261
4262	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4263		for (ext = sect->section; ext->extent != NULL; ++ext) {
4264			if (sect->id == SECT_CONTEXT)
4265				count += 2 + ext->reg_count;
4266			else
4267				return 0;
4268		}
4269	}
4270	/* pa_sc_raster_config/pa_sc_raster_config1 */
4271	count += 4;
4272	/* end clear state */
4273	count += 2;
4274	/* clear state */
4275	count += 2;
4276
4277	return count;
4278}
4279
4280static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
4281{
4282	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
4283	const struct cs_section_def *sect = NULL;
4284	const struct cs_extent_def *ext = NULL;
4285	int r, i;
4286
4287	/* init the CP */
4288	WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
4289	WREG32(mmCP_ENDIAN_SWAP, 0);
4290	WREG32(mmCP_DEVICE_ID, 1);
4291
4292	gfx_v8_0_cp_gfx_enable(adev, true);
4293
4294	r = amdgpu_ring_alloc(ring, gfx_v8_0_get_csb_size(adev) + 4);
4295	if (r) {
4296		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
4297		return r;
4298	}
4299
4300	/* clear state buffer */
4301	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4302	amdgpu_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
4303
4304	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
4305	amdgpu_ring_write(ring, 0x80000000);
4306	amdgpu_ring_write(ring, 0x80000000);
4307
4308	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
4309		for (ext = sect->section; ext->extent != NULL; ++ext) {
4310			if (sect->id == SECT_CONTEXT) {
4311				amdgpu_ring_write(ring,
4312				       PACKET3(PACKET3_SET_CONTEXT_REG,
4313					       ext->reg_count));
4314				amdgpu_ring_write(ring,
4315				       ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
4316				for (i = 0; i < ext->reg_count; i++)
4317					amdgpu_ring_write(ring, ext->extent[i]);
4318			}
4319		}
4320	}
4321
4322	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
4323	amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
4324	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config);
4325	amdgpu_ring_write(ring, adev->gfx.config.rb_config[0][0].raster_config_1);
4326
4327	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
4328	amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
4329
4330	amdgpu_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
4331	amdgpu_ring_write(ring, 0);
4332
4333	/* init the CE partitions */
4334	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4335	amdgpu_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4336	amdgpu_ring_write(ring, 0x8000);
4337	amdgpu_ring_write(ring, 0x8000);
4338
4339	amdgpu_ring_commit(ring);
4340
4341	return 0;
4342}
4343static void gfx_v8_0_set_cpg_door_bell(struct amdgpu_device *adev, struct amdgpu_ring *ring)
4344{
4345	u32 tmp;
4346	/* no gfx doorbells on iceland */
4347	if (adev->asic_type == CHIP_TOPAZ)
4348		return;
4349
4350	tmp = RREG32(mmCP_RB_DOORBELL_CONTROL);
4351
4352	if (ring->use_doorbell) {
4353		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4354				DOORBELL_OFFSET, ring->doorbell_index);
4355		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4356						DOORBELL_HIT, 0);
4357		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL,
4358					    DOORBELL_EN, 1);
4359	} else {
4360		tmp = REG_SET_FIELD(tmp, CP_RB_DOORBELL_CONTROL, DOORBELL_EN, 0);
4361	}
4362
4363	WREG32(mmCP_RB_DOORBELL_CONTROL, tmp);
4364
4365	if (adev->flags & AMD_IS_APU)
4366		return;
4367
4368	tmp = REG_SET_FIELD(0, CP_RB_DOORBELL_RANGE_LOWER,
4369					DOORBELL_RANGE_LOWER,
4370					AMDGPU_DOORBELL_GFX_RING0);
4371	WREG32(mmCP_RB_DOORBELL_RANGE_LOWER, tmp);
4372
4373	WREG32(mmCP_RB_DOORBELL_RANGE_UPPER,
4374		CP_RB_DOORBELL_RANGE_UPPER__DOORBELL_RANGE_UPPER_MASK);
4375}
4376
4377static int gfx_v8_0_cp_gfx_resume(struct amdgpu_device *adev)
4378{
4379	struct amdgpu_ring *ring;
4380	u32 tmp;
4381	u32 rb_bufsz;
4382	u64 rb_addr, rptr_addr, wptr_gpu_addr;
4383	int r;
4384
4385	/* Set the write pointer delay */
4386	WREG32(mmCP_RB_WPTR_DELAY, 0);
4387
4388	/* set the RB to use vmid 0 */
4389	WREG32(mmCP_RB_VMID, 0);
4390
4391	/* Set ring buffer size */
4392	ring = &adev->gfx.gfx_ring[0];
4393	rb_bufsz = order_base_2(ring->ring_size / 8);
4394	tmp = REG_SET_FIELD(0, CP_RB0_CNTL, RB_BUFSZ, rb_bufsz);
4395	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, RB_BLKSZ, rb_bufsz - 2);
4396	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MTYPE, 3);
4397	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, MIN_IB_AVAILSZ, 1);
4398#ifdef __BIG_ENDIAN
4399	tmp = REG_SET_FIELD(tmp, CP_RB0_CNTL, BUF_SWAP, 1);
4400#endif
4401	WREG32(mmCP_RB0_CNTL, tmp);
4402
4403	/* Initialize the ring buffer's read and write pointers */
4404	WREG32(mmCP_RB0_CNTL, tmp | CP_RB0_CNTL__RB_RPTR_WR_ENA_MASK);
4405	ring->wptr = 0;
4406	WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
4407
4408	/* set the wb address wether it's enabled or not */
4409	rptr_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
4410	WREG32(mmCP_RB0_RPTR_ADDR, lower_32_bits(rptr_addr));
4411	WREG32(mmCP_RB0_RPTR_ADDR_HI, upper_32_bits(rptr_addr) & 0xFF);
4412
4413	wptr_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
4414	WREG32(mmCP_RB_WPTR_POLL_ADDR_LO, lower_32_bits(wptr_gpu_addr));
4415	WREG32(mmCP_RB_WPTR_POLL_ADDR_HI, upper_32_bits(wptr_gpu_addr));
4416	mdelay(1);
4417	WREG32(mmCP_RB0_CNTL, tmp);
4418
4419	rb_addr = ring->gpu_addr >> 8;
4420	WREG32(mmCP_RB0_BASE, rb_addr);
4421	WREG32(mmCP_RB0_BASE_HI, upper_32_bits(rb_addr));
4422
4423	gfx_v8_0_set_cpg_door_bell(adev, ring);
4424	/* start the ring */
4425	amdgpu_ring_clear_ring(ring);
4426	gfx_v8_0_cp_gfx_start(adev);
4427	ring->ready = true;
4428	r = amdgpu_ring_test_ring(ring);
4429	if (r)
4430		ring->ready = false;
4431
4432	return r;
4433}
4434
4435static void gfx_v8_0_cp_compute_enable(struct amdgpu_device *adev, bool enable)
4436{
4437	int i;
4438
4439	if (enable) {
4440		WREG32(mmCP_MEC_CNTL, 0);
4441	} else {
4442		WREG32(mmCP_MEC_CNTL, (CP_MEC_CNTL__MEC_ME1_HALT_MASK | CP_MEC_CNTL__MEC_ME2_HALT_MASK));
4443		for (i = 0; i < adev->gfx.num_compute_rings; i++)
4444			adev->gfx.compute_ring[i].ready = false;
4445		adev->gfx.kiq.ring.ready = false;
4446	}
4447	udelay(50);
4448}
4449
4450static int gfx_v8_0_cp_compute_load_microcode(struct amdgpu_device *adev)
4451{
4452	const struct gfx_firmware_header_v1_0 *mec_hdr;
4453	const __le32 *fw_data;
4454	unsigned i, fw_size;
4455
4456	if (!adev->gfx.mec_fw)
4457		return -EINVAL;
4458
4459	gfx_v8_0_cp_compute_enable(adev, false);
4460
4461	mec_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec_fw->data;
4462	amdgpu_ucode_print_gfx_hdr(&mec_hdr->header);
4463
4464	fw_data = (const __le32 *)
4465		(adev->gfx.mec_fw->data +
4466		 le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
4467	fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
4468
4469	/* MEC1 */
4470	WREG32(mmCP_MEC_ME1_UCODE_ADDR, 0);
4471	for (i = 0; i < fw_size; i++)
4472		WREG32(mmCP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data+i));
4473	WREG32(mmCP_MEC_ME1_UCODE_ADDR, adev->gfx.mec_fw_version);
4474
4475	/* Loading MEC2 firmware is only necessary if MEC2 should run different microcode than MEC1. */
4476	if (adev->gfx.mec2_fw) {
4477		const struct gfx_firmware_header_v1_0 *mec2_hdr;
4478
4479		mec2_hdr = (const struct gfx_firmware_header_v1_0 *)adev->gfx.mec2_fw->data;
4480		amdgpu_ucode_print_gfx_hdr(&mec2_hdr->header);
4481
4482		fw_data = (const __le32 *)
4483			(adev->gfx.mec2_fw->data +
4484			 le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
4485		fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
4486
4487		WREG32(mmCP_MEC_ME2_UCODE_ADDR, 0);
4488		for (i = 0; i < fw_size; i++)
4489			WREG32(mmCP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data+i));
4490		WREG32(mmCP_MEC_ME2_UCODE_ADDR, adev->gfx.mec2_fw_version);
4491	}
4492
4493	return 0;
4494}
4495
4496/* KIQ functions */
4497static void gfx_v8_0_kiq_setting(struct amdgpu_ring *ring)
4498{
4499	uint32_t tmp;
4500	struct amdgpu_device *adev = ring->adev;
4501
4502	/* tell RLC which is KIQ queue */
4503	tmp = RREG32(mmRLC_CP_SCHEDULERS);
4504	tmp &= 0xffffff00;
4505	tmp |= (ring->me << 5) | (ring->pipe << 3) | (ring->queue);
4506	WREG32(mmRLC_CP_SCHEDULERS, tmp);
4507	tmp |= 0x80;
4508	WREG32(mmRLC_CP_SCHEDULERS, tmp);
4509}
4510
4511static int gfx_v8_0_kiq_kcq_enable(struct amdgpu_device *adev)
4512{
4513	struct amdgpu_ring *kiq_ring = &adev->gfx.kiq.ring;
4514	uint32_t scratch, tmp = 0;
4515	uint64_t queue_mask = 0;
4516	int r, i;
4517
4518	for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
4519		if (!test_bit(i, adev->gfx.mec.queue_bitmap))
4520			continue;
4521
4522		/* This situation may be hit in the future if a new HW
4523		 * generation exposes more than 64 queues. If so, the
4524		 * definition of queue_mask needs updating */
4525		if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
4526			DRM_ERROR("Invalid KCQ enabled: %d\n", i);
4527			break;
4528		}
4529
4530		queue_mask |= (1ull << i);
4531	}
4532
4533	r = amdgpu_gfx_scratch_get(adev, &scratch);
4534	if (r) {
4535		DRM_ERROR("Failed to get scratch reg (%d).\n", r);
4536		return r;
4537	}
4538	WREG32(scratch, 0xCAFEDEAD);
4539
4540	r = amdgpu_ring_alloc(kiq_ring, (8 * adev->gfx.num_compute_rings) + 11);
4541	if (r) {
4542		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
4543		amdgpu_gfx_scratch_free(adev, scratch);
4544		return r;
4545	}
4546	/* set resources */
4547	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_RESOURCES, 6));
4548	amdgpu_ring_write(kiq_ring, 0);	/* vmid_mask:0 queue_type:0 (KIQ) */
4549	amdgpu_ring_write(kiq_ring, lower_32_bits(queue_mask));	/* queue mask lo */
4550	amdgpu_ring_write(kiq_ring, upper_32_bits(queue_mask));	/* queue mask hi */
4551	amdgpu_ring_write(kiq_ring, 0);	/* gws mask lo */
4552	amdgpu_ring_write(kiq_ring, 0);	/* gws mask hi */
4553	amdgpu_ring_write(kiq_ring, 0);	/* oac mask */
4554	amdgpu_ring_write(kiq_ring, 0);	/* gds heap base:0, gds heap size:0 */
4555	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4556		struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
4557		uint64_t mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
4558		uint64_t wptr_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
4559
4560		/* map queues */
4561		amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_MAP_QUEUES, 5));
4562		/* Q_sel:0, vmid:0, vidmem: 1, engine:0, num_Q:1*/
4563		amdgpu_ring_write(kiq_ring,
4564				  PACKET3_MAP_QUEUES_NUM_QUEUES(1));
4565		amdgpu_ring_write(kiq_ring,
4566				  PACKET3_MAP_QUEUES_DOORBELL_OFFSET(ring->doorbell_index) |
4567				  PACKET3_MAP_QUEUES_QUEUE(ring->queue) |
4568				  PACKET3_MAP_QUEUES_PIPE(ring->pipe) |
4569				  PACKET3_MAP_QUEUES_ME(ring->me == 1 ? 0 : 1)); /* doorbell */
4570		amdgpu_ring_write(kiq_ring, lower_32_bits(mqd_addr));
4571		amdgpu_ring_write(kiq_ring, upper_32_bits(mqd_addr));
4572		amdgpu_ring_write(kiq_ring, lower_32_bits(wptr_addr));
4573		amdgpu_ring_write(kiq_ring, upper_32_bits(wptr_addr));
4574	}
4575	/* write to scratch for completion */
4576	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
4577	amdgpu_ring_write(kiq_ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
4578	amdgpu_ring_write(kiq_ring, 0xDEADBEEF);
4579	amdgpu_ring_commit(kiq_ring);
4580
4581	for (i = 0; i < adev->usec_timeout; i++) {
4582		tmp = RREG32(scratch);
4583		if (tmp == 0xDEADBEEF)
4584			break;
4585		DRM_UDELAY(1);
4586	}
4587	if (i >= adev->usec_timeout) {
4588		DRM_ERROR("KCQ enable failed (scratch(0x%04X)=0x%08X)\n",
4589			  scratch, tmp);
4590		r = -EINVAL;
4591	}
4592	amdgpu_gfx_scratch_free(adev, scratch);
4593
4594	return r;
4595}
4596
4597static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)
4598{
4599	int i, r = 0;
4600
4601	if (RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK) {
4602		WREG32_FIELD(CP_HQD_DEQUEUE_REQUEST, DEQUEUE_REQ, req);
4603		for (i = 0; i < adev->usec_timeout; i++) {
4604			if (!(RREG32(mmCP_HQD_ACTIVE) & CP_HQD_ACTIVE__ACTIVE_MASK))
4605				break;
4606			udelay(1);
4607		}
4608		if (i == adev->usec_timeout)
4609			r = -ETIMEDOUT;
4610	}
4611	WREG32(mmCP_HQD_DEQUEUE_REQUEST, 0);
4612	WREG32(mmCP_HQD_PQ_RPTR, 0);
4613	WREG32(mmCP_HQD_PQ_WPTR, 0);
4614
4615	return r;
4616}
4617
 
 
 
 
 
 
 
 
 
 
 
 
 
4618static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)
4619{
4620	struct amdgpu_device *adev = ring->adev;
4621	struct vi_mqd *mqd = ring->mqd_ptr;
4622	uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr;
4623	uint32_t tmp;
4624
4625	mqd->header = 0xC0310800;
4626	mqd->compute_pipelinestat_enable = 0x00000001;
4627	mqd->compute_static_thread_mgmt_se0 = 0xffffffff;
4628	mqd->compute_static_thread_mgmt_se1 = 0xffffffff;
4629	mqd->compute_static_thread_mgmt_se2 = 0xffffffff;
4630	mqd->compute_static_thread_mgmt_se3 = 0xffffffff;
4631	mqd->compute_misc_reserved = 0x00000003;
4632	mqd->dynamic_cu_mask_addr_lo = lower_32_bits(ring->mqd_gpu_addr
4633						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
4634	mqd->dynamic_cu_mask_addr_hi = upper_32_bits(ring->mqd_gpu_addr
4635						     + offsetof(struct vi_mqd_allocation, dynamic_cu_mask));
4636	eop_base_addr = ring->eop_gpu_addr >> 8;
4637	mqd->cp_hqd_eop_base_addr_lo = eop_base_addr;
4638	mqd->cp_hqd_eop_base_addr_hi = upper_32_bits(eop_base_addr);
4639
4640	/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
4641	tmp = RREG32(mmCP_HQD_EOP_CONTROL);
4642	tmp = REG_SET_FIELD(tmp, CP_HQD_EOP_CONTROL, EOP_SIZE,
4643			(order_base_2(GFX8_MEC_HPD_SIZE / 4) - 1));
4644
4645	mqd->cp_hqd_eop_control = tmp;
4646
4647	/* enable doorbell? */
4648	tmp = REG_SET_FIELD(RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL),
4649			    CP_HQD_PQ_DOORBELL_CONTROL,
4650			    DOORBELL_EN,
4651			    ring->use_doorbell ? 1 : 0);
4652
4653	mqd->cp_hqd_pq_doorbell_control = tmp;
4654
4655	/* set the pointer to the MQD */
4656	mqd->cp_mqd_base_addr_lo = ring->mqd_gpu_addr & 0xfffffffc;
4657	mqd->cp_mqd_base_addr_hi = upper_32_bits(ring->mqd_gpu_addr);
4658
4659	/* set MQD vmid to 0 */
4660	tmp = RREG32(mmCP_MQD_CONTROL);
4661	tmp = REG_SET_FIELD(tmp, CP_MQD_CONTROL, VMID, 0);
4662	mqd->cp_mqd_control = tmp;
4663
4664	/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
4665	hqd_gpu_addr = ring->gpu_addr >> 8;
4666	mqd->cp_hqd_pq_base_lo = hqd_gpu_addr;
4667	mqd->cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
4668
4669	/* set up the HQD, this is similar to CP_RB0_CNTL */
4670	tmp = RREG32(mmCP_HQD_PQ_CONTROL);
4671	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, QUEUE_SIZE,
4672			    (order_base_2(ring->ring_size / 4) - 1));
4673	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE,
4674			((order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1) << 8));
4675#ifdef __BIG_ENDIAN
4676	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1);
4677#endif
4678	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
4679	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ROQ_PQ_IB_FLIP, 0);
4680	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
4681	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
4682	mqd->cp_hqd_pq_control = tmp;
4683
4684	/* set the wb address whether it's enabled or not */
4685	wb_gpu_addr = adev->wb.gpu_addr + (ring->rptr_offs * 4);
4686	mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr & 0xfffffffc;
4687	mqd->cp_hqd_pq_rptr_report_addr_hi =
4688		upper_32_bits(wb_gpu_addr) & 0xffff;
4689
4690	/* only used if CP_PQ_WPTR_POLL_CNTL.CP_PQ_WPTR_POLL_CNTL__EN_MASK=1 */
4691	wb_gpu_addr = adev->wb.gpu_addr + (ring->wptr_offs * 4);
4692	mqd->cp_hqd_pq_wptr_poll_addr_lo = wb_gpu_addr & 0xfffffffc;
4693	mqd->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
4694
4695	tmp = 0;
4696	/* enable the doorbell if requested */
4697	if (ring->use_doorbell) {
4698		tmp = RREG32(mmCP_HQD_PQ_DOORBELL_CONTROL);
4699		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4700				DOORBELL_OFFSET, ring->doorbell_index);
4701
4702		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4703					 DOORBELL_EN, 1);
4704		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4705					 DOORBELL_SOURCE, 0);
4706		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_DOORBELL_CONTROL,
4707					 DOORBELL_HIT, 0);
4708	}
4709
4710	mqd->cp_hqd_pq_doorbell_control = tmp;
4711
4712	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
4713	ring->wptr = 0;
4714	mqd->cp_hqd_pq_wptr = ring->wptr;
4715	mqd->cp_hqd_pq_rptr = RREG32(mmCP_HQD_PQ_RPTR);
4716
4717	/* set the vmid for the queue */
4718	mqd->cp_hqd_vmid = 0;
4719
4720	tmp = RREG32(mmCP_HQD_PERSISTENT_STATE);
4721	tmp = REG_SET_FIELD(tmp, CP_HQD_PERSISTENT_STATE, PRELOAD_SIZE, 0x53);
4722	mqd->cp_hqd_persistent_state = tmp;
4723
4724	/* set MTYPE */
4725	tmp = RREG32(mmCP_HQD_IB_CONTROL);
4726	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);
4727	tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MTYPE, 3);
4728	mqd->cp_hqd_ib_control = tmp;
4729
4730	tmp = RREG32(mmCP_HQD_IQ_TIMER);
4731	tmp = REG_SET_FIELD(tmp, CP_HQD_IQ_TIMER, MTYPE, 3);
4732	mqd->cp_hqd_iq_timer = tmp;
4733
4734	tmp = RREG32(mmCP_HQD_CTX_SAVE_CONTROL);
4735	tmp = REG_SET_FIELD(tmp, CP_HQD_CTX_SAVE_CONTROL, MTYPE, 3);
4736	mqd->cp_hqd_ctx_save_control = tmp;
4737
4738	/* defaults */
4739	mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);
4740	mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);
4741	mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);
4742	mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);
4743	mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);
4744	mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);
4745	mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);
4746	mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);
4747	mqd->cp_hqd_cntl_stack_size = RREG32(mmCP_HQD_CNTL_STACK_SIZE);
4748	mqd->cp_hqd_wg_state_offset = RREG32(mmCP_HQD_WG_STATE_OFFSET);
4749	mqd->cp_hqd_ctx_save_size = RREG32(mmCP_HQD_CTX_SAVE_SIZE);
4750	mqd->cp_hqd_eop_done_events = RREG32(mmCP_HQD_EOP_EVENTS);
4751	mqd->cp_hqd_error = RREG32(mmCP_HQD_ERROR);
4752	mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);
4753	mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);
4754
4755	/* activate the queue */
4756	mqd->cp_hqd_active = 1;
 
 
 
 
 
 
 
4757
4758	return 0;
4759}
4760
4761int gfx_v8_0_mqd_commit(struct amdgpu_device *adev,
4762			struct vi_mqd *mqd)
4763{
4764	uint32_t mqd_reg;
4765	uint32_t *mqd_data;
4766
4767	/* HQD registers extend from mmCP_MQD_BASE_ADDR to mmCP_HQD_ERROR */
4768	mqd_data = &mqd->cp_mqd_base_addr_lo;
4769
4770	/* disable wptr polling */
4771	WREG32_FIELD(CP_PQ_WPTR_POLL_CNTL, EN, 0);
4772
4773	/* program all HQD registers */
4774	for (mqd_reg = mmCP_HQD_VMID; mqd_reg <= mmCP_HQD_EOP_CONTROL; mqd_reg++)
4775		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4776
4777	/* Tonga errata: EOP RPTR/WPTR should be left unmodified.
4778	 * This is safe since EOP RPTR==WPTR for any inactive HQD
4779	 * on ASICs that do not support context-save.
4780	 * EOP writes/reads can start anywhere in the ring.
4781	 */
4782	if (adev->asic_type != CHIP_TONGA) {
4783		WREG32(mmCP_HQD_EOP_RPTR, mqd->cp_hqd_eop_rptr);
4784		WREG32(mmCP_HQD_EOP_WPTR, mqd->cp_hqd_eop_wptr);
4785		WREG32(mmCP_HQD_EOP_WPTR_MEM, mqd->cp_hqd_eop_wptr_mem);
4786	}
4787
4788	for (mqd_reg = mmCP_HQD_EOP_EVENTS; mqd_reg <= mmCP_HQD_ERROR; mqd_reg++)
4789		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4790
4791	/* activate the HQD */
4792	for (mqd_reg = mmCP_MQD_BASE_ADDR; mqd_reg <= mmCP_HQD_ACTIVE; mqd_reg++)
4793		WREG32(mqd_reg, mqd_data[mqd_reg - mmCP_MQD_BASE_ADDR]);
4794
4795	return 0;
4796}
4797
4798static int gfx_v8_0_kiq_init_queue(struct amdgpu_ring *ring)
4799{
4800	struct amdgpu_device *adev = ring->adev;
4801	struct vi_mqd *mqd = ring->mqd_ptr;
4802	int mqd_idx = AMDGPU_MAX_COMPUTE_RINGS;
4803
4804	gfx_v8_0_kiq_setting(ring);
4805
4806	if (adev->in_gpu_reset) { /* for GPU_RESET case */
4807		/* reset MQD to a clean status */
4808		if (adev->gfx.mec.mqd_backup[mqd_idx])
4809			memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
4810
4811		/* reset ring buffer */
4812		ring->wptr = 0;
4813		amdgpu_ring_clear_ring(ring);
4814		mutex_lock(&adev->srbm_mutex);
4815		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4816		gfx_v8_0_mqd_commit(adev, mqd);
4817		vi_srbm_select(adev, 0, 0, 0, 0);
4818		mutex_unlock(&adev->srbm_mutex);
4819	} else {
4820		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
4821		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
4822		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
 
 
4823		mutex_lock(&adev->srbm_mutex);
4824		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4825		gfx_v8_0_mqd_init(ring);
4826		gfx_v8_0_mqd_commit(adev, mqd);
4827		vi_srbm_select(adev, 0, 0, 0, 0);
4828		mutex_unlock(&adev->srbm_mutex);
4829
4830		if (adev->gfx.mec.mqd_backup[mqd_idx])
4831			memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
4832	}
4833
4834	return 0;
4835}
4836
4837static int gfx_v8_0_kcq_init_queue(struct amdgpu_ring *ring)
4838{
4839	struct amdgpu_device *adev = ring->adev;
4840	struct vi_mqd *mqd = ring->mqd_ptr;
4841	int mqd_idx = ring - &adev->gfx.compute_ring[0];
4842
4843	if (!adev->in_gpu_reset && !adev->gfx.in_suspend) {
4844		memset((void *)mqd, 0, sizeof(struct vi_mqd_allocation));
4845		((struct vi_mqd_allocation *)mqd)->dynamic_cu_mask = 0xFFFFFFFF;
4846		((struct vi_mqd_allocation *)mqd)->dynamic_rb_mask = 0xFFFFFFFF;
4847		mutex_lock(&adev->srbm_mutex);
4848		vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
4849		gfx_v8_0_mqd_init(ring);
4850		vi_srbm_select(adev, 0, 0, 0, 0);
4851		mutex_unlock(&adev->srbm_mutex);
4852
4853		if (adev->gfx.mec.mqd_backup[mqd_idx])
4854			memcpy(adev->gfx.mec.mqd_backup[mqd_idx], mqd, sizeof(struct vi_mqd_allocation));
4855	} else if (adev->in_gpu_reset) { /* for GPU_RESET case */
4856		/* reset MQD to a clean status */
4857		if (adev->gfx.mec.mqd_backup[mqd_idx])
4858			memcpy(mqd, adev->gfx.mec.mqd_backup[mqd_idx], sizeof(struct vi_mqd_allocation));
4859		/* reset ring buffer */
4860		ring->wptr = 0;
4861		amdgpu_ring_clear_ring(ring);
4862	} else {
4863		amdgpu_ring_clear_ring(ring);
4864	}
4865	return 0;
4866}
4867
4868static void gfx_v8_0_set_mec_doorbell_range(struct amdgpu_device *adev)
4869{
4870	if (adev->asic_type > CHIP_TONGA) {
4871		WREG32(mmCP_MEC_DOORBELL_RANGE_LOWER, AMDGPU_DOORBELL_KIQ << 2);
4872		WREG32(mmCP_MEC_DOORBELL_RANGE_UPPER, AMDGPU_DOORBELL_MEC_RING7 << 2);
4873	}
4874	/* enable doorbells */
4875	WREG32_FIELD(CP_PQ_STATUS, DOORBELL_ENABLE, 1);
4876}
4877
4878static int gfx_v8_0_kiq_resume(struct amdgpu_device *adev)
4879{
4880	struct amdgpu_ring *ring = NULL;
4881	int r = 0, i;
4882
4883	gfx_v8_0_cp_compute_enable(adev, true);
4884
4885	ring = &adev->gfx.kiq.ring;
4886
4887	r = amdgpu_bo_reserve(ring->mqd_obj, false);
4888	if (unlikely(r != 0))
4889		goto done;
4890
4891	r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
4892	if (!r) {
4893		r = gfx_v8_0_kiq_init_queue(ring);
4894		amdgpu_bo_kunmap(ring->mqd_obj);
4895		ring->mqd_ptr = NULL;
4896	}
 
 
 
 
4897	amdgpu_bo_unreserve(ring->mqd_obj);
4898	if (r)
4899		goto done;
 
 
 
 
 
 
 
4900
4901	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4902		ring = &adev->gfx.compute_ring[i];
4903
4904		r = amdgpu_bo_reserve(ring->mqd_obj, false);
4905		if (unlikely(r != 0))
4906			goto done;
4907		r = amdgpu_bo_kmap(ring->mqd_obj, &ring->mqd_ptr);
4908		if (!r) {
4909			r = gfx_v8_0_kcq_init_queue(ring);
4910			amdgpu_bo_kunmap(ring->mqd_obj);
4911			ring->mqd_ptr = NULL;
4912		}
4913		amdgpu_bo_unreserve(ring->mqd_obj);
4914		if (r)
4915			goto done;
4916	}
4917
4918	gfx_v8_0_set_mec_doorbell_range(adev);
4919
4920	r = gfx_v8_0_kiq_kcq_enable(adev);
4921	if (r)
4922		goto done;
4923
4924	/* Test KIQ */
4925	ring = &adev->gfx.kiq.ring;
4926	ring->ready = true;
4927	r = amdgpu_ring_test_ring(ring);
4928	if (r) {
4929		ring->ready = false;
4930		goto done;
4931	}
 
 
 
 
 
 
 
 
 
 
 
4932
4933	/* Test KCQs */
4934	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
4935		ring = &adev->gfx.compute_ring[i];
4936		ring->ready = true;
4937		r = amdgpu_ring_test_ring(ring);
4938		if (r)
4939			ring->ready = false;
4940	}
4941
4942done:
4943	return r;
4944}
4945
4946static int gfx_v8_0_cp_resume(struct amdgpu_device *adev)
4947{
4948	int r;
4949
4950	if (!(adev->flags & AMD_IS_APU))
4951		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
4952
4953	if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT) {
4954			/* legacy firmware loading */
4955		r = gfx_v8_0_cp_gfx_load_microcode(adev);
4956		if (r)
4957			return r;
4958
4959		r = gfx_v8_0_cp_compute_load_microcode(adev);
4960		if (r)
4961			return r;
4962	}
4963
4964	r = gfx_v8_0_cp_gfx_resume(adev);
4965	if (r)
4966		return r;
4967
4968	r = gfx_v8_0_kiq_resume(adev);
4969	if (r)
4970		return r;
4971
4972	gfx_v8_0_enable_gui_idle_interrupt(adev, true);
4973
4974	return 0;
4975}
4976
4977static void gfx_v8_0_cp_enable(struct amdgpu_device *adev, bool enable)
4978{
4979	gfx_v8_0_cp_gfx_enable(adev, enable);
4980	gfx_v8_0_cp_compute_enable(adev, enable);
4981}
4982
4983static int gfx_v8_0_hw_init(void *handle)
4984{
4985	int r;
4986	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4987
4988	gfx_v8_0_init_golden_registers(adev);
4989	gfx_v8_0_gpu_init(adev);
4990
4991	r = gfx_v8_0_rlc_resume(adev);
4992	if (r)
4993		return r;
4994
4995	r = gfx_v8_0_cp_resume(adev);
4996
4997	return r;
4998}
4999
5000static int gfx_v8_0_kcq_disable(struct amdgpu_ring *kiq_ring,struct amdgpu_ring *ring)
5001{
5002	struct amdgpu_device *adev = kiq_ring->adev;
5003	uint32_t scratch, tmp = 0;
5004	int r, i;
 
5005
5006	r = amdgpu_gfx_scratch_get(adev, &scratch);
5007	if (r) {
5008		DRM_ERROR("Failed to get scratch reg (%d).\n", r);
5009		return r;
5010	}
5011	WREG32(scratch, 0xCAFEDEAD);
5012
5013	r = amdgpu_ring_alloc(kiq_ring, 10);
5014	if (r) {
5015		DRM_ERROR("Failed to lock KIQ (%d).\n", r);
5016		amdgpu_gfx_scratch_free(adev, scratch);
5017		return r;
5018	}
5019
5020	/* unmap queues */
5021	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_UNMAP_QUEUES, 4));
5022	amdgpu_ring_write(kiq_ring, /* Q_sel: 0, vmid: 0, engine: 0, num_Q: 1 */
5023						PACKET3_UNMAP_QUEUES_ACTION(1) | /* RESET_QUEUES */
5024						PACKET3_UNMAP_QUEUES_QUEUE_SEL(0) |
5025						PACKET3_UNMAP_QUEUES_ENGINE_SEL(0) |
5026						PACKET3_UNMAP_QUEUES_NUM_QUEUES(1));
5027	amdgpu_ring_write(kiq_ring, PACKET3_UNMAP_QUEUES_DOORBELL_OFFSET0(ring->doorbell_index));
5028	amdgpu_ring_write(kiq_ring, 0);
5029	amdgpu_ring_write(kiq_ring, 0);
5030	amdgpu_ring_write(kiq_ring, 0);
5031	/* write to scratch for completion */
5032	amdgpu_ring_write(kiq_ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
5033	amdgpu_ring_write(kiq_ring, (scratch - PACKET3_SET_UCONFIG_REG_START));
5034	amdgpu_ring_write(kiq_ring, 0xDEADBEEF);
5035	amdgpu_ring_commit(kiq_ring);
 
 
 
 
 
 
 
 
5036
5037	for (i = 0; i < adev->usec_timeout; i++) {
5038		tmp = RREG32(scratch);
5039		if (tmp == 0xDEADBEEF)
5040			break;
5041		DRM_UDELAY(1);
5042	}
5043	if (i >= adev->usec_timeout) {
5044		DRM_ERROR("KCQ disabled failed (scratch(0x%04X)=0x%08X)\n", scratch, tmp);
5045		r = -EINVAL;
5046	}
5047	amdgpu_gfx_scratch_free(adev, scratch);
5048	return r;
5049}
5050
5051static int gfx_v8_0_hw_fini(void *handle)
5052{
5053	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5054	int i;
5055
5056	amdgpu_irq_put(adev, &adev->gfx.priv_reg_irq, 0);
5057	amdgpu_irq_put(adev, &adev->gfx.priv_inst_irq, 0);
5058
5059	/* disable KCQ to avoid CPC touch memory not valid anymore */
5060	for (i = 0; i < adev->gfx.num_compute_rings; i++)
5061		gfx_v8_0_kcq_disable(&adev->gfx.kiq.ring, &adev->gfx.compute_ring[i]);
5062
5063	if (amdgpu_sriov_vf(adev)) {
5064		pr_debug("For SRIOV client, shouldn't do anything.\n");
5065		return 0;
5066	}
5067	gfx_v8_0_cp_enable(adev, false);
5068	gfx_v8_0_rlc_stop(adev);
5069
5070	amdgpu_device_ip_set_powergating_state(adev,
5071					       AMD_IP_BLOCK_TYPE_GFX,
5072					       AMD_PG_STATE_UNGATE);
5073
5074	return 0;
5075}
5076
5077static int gfx_v8_0_suspend(void *handle)
5078{
5079	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5080	adev->gfx.in_suspend = true;
5081	return gfx_v8_0_hw_fini(adev);
 
 
 
5082}
5083
5084static int gfx_v8_0_resume(void *handle)
5085{
5086	int r;
5087	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5088
5089	r = gfx_v8_0_hw_init(adev);
5090	adev->gfx.in_suspend = false;
5091	return r;
5092}
5093
5094static bool gfx_v8_0_is_idle(void *handle)
5095{
5096	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5097
5098	if (REG_GET_FIELD(RREG32(mmGRBM_STATUS), GRBM_STATUS, GUI_ACTIVE))
5099		return false;
5100	else
5101		return true;
5102}
5103
5104static int gfx_v8_0_wait_for_idle(void *handle)
5105{
5106	unsigned i;
5107	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5108
5109	for (i = 0; i < adev->usec_timeout; i++) {
5110		if (gfx_v8_0_is_idle(handle))
5111			return 0;
5112
5113		udelay(1);
5114	}
5115	return -ETIMEDOUT;
5116}
5117
5118static bool gfx_v8_0_check_soft_reset(void *handle)
5119{
5120	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5121	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5122	u32 tmp;
5123
5124	/* GRBM_STATUS */
5125	tmp = RREG32(mmGRBM_STATUS);
5126	if (tmp & (GRBM_STATUS__PA_BUSY_MASK | GRBM_STATUS__SC_BUSY_MASK |
5127		   GRBM_STATUS__BCI_BUSY_MASK | GRBM_STATUS__SX_BUSY_MASK |
5128		   GRBM_STATUS__TA_BUSY_MASK | GRBM_STATUS__VGT_BUSY_MASK |
5129		   GRBM_STATUS__DB_BUSY_MASK | GRBM_STATUS__CB_BUSY_MASK |
5130		   GRBM_STATUS__GDS_BUSY_MASK | GRBM_STATUS__SPI_BUSY_MASK |
5131		   GRBM_STATUS__IA_BUSY_MASK | GRBM_STATUS__IA_BUSY_NO_DMA_MASK |
5132		   GRBM_STATUS__CP_BUSY_MASK | GRBM_STATUS__CP_COHERENCY_BUSY_MASK)) {
5133		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
5134						GRBM_SOFT_RESET, SOFT_RESET_CP, 1);
5135		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
5136						GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
5137		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
5138						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
5139	}
5140
5141	/* GRBM_STATUS2 */
5142	tmp = RREG32(mmGRBM_STATUS2);
5143	if (REG_GET_FIELD(tmp, GRBM_STATUS2, RLC_BUSY))
5144		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset,
5145						GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
5146
5147	if (REG_GET_FIELD(tmp, GRBM_STATUS2, CPF_BUSY) ||
5148	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPC_BUSY) ||
5149	    REG_GET_FIELD(tmp, GRBM_STATUS2, CPG_BUSY)) {
5150		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
5151						SOFT_RESET_CPF, 1);
5152		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
5153						SOFT_RESET_CPC, 1);
5154		grbm_soft_reset = REG_SET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET,
5155						SOFT_RESET_CPG, 1);
5156		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET,
5157						SOFT_RESET_GRBM, 1);
5158	}
5159
5160	/* SRBM_STATUS */
5161	tmp = RREG32(mmSRBM_STATUS);
5162	if (REG_GET_FIELD(tmp, SRBM_STATUS, GRBM_RQ_PENDING))
5163		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
5164						SRBM_SOFT_RESET, SOFT_RESET_GRBM, 1);
5165	if (REG_GET_FIELD(tmp, SRBM_STATUS, SEM_BUSY))
5166		srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,
5167						SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
5168
5169	if (grbm_soft_reset || srbm_soft_reset) {
5170		adev->gfx.grbm_soft_reset = grbm_soft_reset;
5171		adev->gfx.srbm_soft_reset = srbm_soft_reset;
5172		return true;
5173	} else {
5174		adev->gfx.grbm_soft_reset = 0;
5175		adev->gfx.srbm_soft_reset = 0;
5176		return false;
5177	}
5178}
5179
5180static int gfx_v8_0_pre_soft_reset(void *handle)
5181{
5182	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5183	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5184
5185	if ((!adev->gfx.grbm_soft_reset) &&
5186	    (!adev->gfx.srbm_soft_reset))
5187		return 0;
5188
5189	grbm_soft_reset = adev->gfx.grbm_soft_reset;
5190	srbm_soft_reset = adev->gfx.srbm_soft_reset;
5191
5192	/* stop the rlc */
5193	gfx_v8_0_rlc_stop(adev);
5194
5195	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5196	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
5197		/* Disable GFX parsing/prefetching */
5198		gfx_v8_0_cp_gfx_enable(adev, false);
5199
5200	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5201	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
5202	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
5203	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
5204		int i;
5205
5206		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
5207			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
5208
5209			mutex_lock(&adev->srbm_mutex);
5210			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5211			gfx_v8_0_deactivate_hqd(adev, 2);
5212			vi_srbm_select(adev, 0, 0, 0, 0);
5213			mutex_unlock(&adev->srbm_mutex);
5214		}
5215		/* Disable MEC parsing/prefetching */
5216		gfx_v8_0_cp_compute_enable(adev, false);
5217	}
5218
5219       return 0;
5220}
5221
5222static int gfx_v8_0_soft_reset(void *handle)
5223{
5224	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5225	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5226	u32 tmp;
5227
5228	if ((!adev->gfx.grbm_soft_reset) &&
5229	    (!adev->gfx.srbm_soft_reset))
5230		return 0;
5231
5232	grbm_soft_reset = adev->gfx.grbm_soft_reset;
5233	srbm_soft_reset = adev->gfx.srbm_soft_reset;
5234
5235	if (grbm_soft_reset || srbm_soft_reset) {
5236		tmp = RREG32(mmGMCON_DEBUG);
5237		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 1);
5238		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 1);
5239		WREG32(mmGMCON_DEBUG, tmp);
5240		udelay(50);
5241	}
5242
5243	if (grbm_soft_reset) {
5244		tmp = RREG32(mmGRBM_SOFT_RESET);
5245		tmp |= grbm_soft_reset;
5246		dev_info(adev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
5247		WREG32(mmGRBM_SOFT_RESET, tmp);
5248		tmp = RREG32(mmGRBM_SOFT_RESET);
5249
5250		udelay(50);
5251
5252		tmp &= ~grbm_soft_reset;
5253		WREG32(mmGRBM_SOFT_RESET, tmp);
5254		tmp = RREG32(mmGRBM_SOFT_RESET);
5255	}
5256
5257	if (srbm_soft_reset) {
5258		tmp = RREG32(mmSRBM_SOFT_RESET);
5259		tmp |= srbm_soft_reset;
5260		dev_info(adev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
5261		WREG32(mmSRBM_SOFT_RESET, tmp);
5262		tmp = RREG32(mmSRBM_SOFT_RESET);
5263
5264		udelay(50);
5265
5266		tmp &= ~srbm_soft_reset;
5267		WREG32(mmSRBM_SOFT_RESET, tmp);
5268		tmp = RREG32(mmSRBM_SOFT_RESET);
5269	}
5270
5271	if (grbm_soft_reset || srbm_soft_reset) {
5272		tmp = RREG32(mmGMCON_DEBUG);
5273		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_STALL, 0);
5274		tmp = REG_SET_FIELD(tmp, GMCON_DEBUG, GFX_CLEAR, 0);
5275		WREG32(mmGMCON_DEBUG, tmp);
5276	}
5277
5278	/* Wait a little for things to settle down */
5279	udelay(50);
5280
5281	return 0;
5282}
5283
5284static int gfx_v8_0_post_soft_reset(void *handle)
5285{
5286	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5287	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5288
5289	if ((!adev->gfx.grbm_soft_reset) &&
5290	    (!adev->gfx.srbm_soft_reset))
5291		return 0;
5292
5293	grbm_soft_reset = adev->gfx.grbm_soft_reset;
5294	srbm_soft_reset = adev->gfx.srbm_soft_reset;
5295
5296	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5297	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_GFX))
5298		gfx_v8_0_cp_gfx_resume(adev);
5299
5300	if (REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CP) ||
5301	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPF) ||
5302	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPC) ||
5303	    REG_GET_FIELD(grbm_soft_reset, GRBM_SOFT_RESET, SOFT_RESET_CPG)) {
5304		int i;
5305
5306		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
5307			struct amdgpu_ring *ring = &adev->gfx.compute_ring[i];
5308
5309			mutex_lock(&adev->srbm_mutex);
5310			vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
5311			gfx_v8_0_deactivate_hqd(adev, 2);
5312			vi_srbm_select(adev, 0, 0, 0, 0);
5313			mutex_unlock(&adev->srbm_mutex);
5314		}
5315		gfx_v8_0_kiq_resume(adev);
 
5316	}
5317	gfx_v8_0_rlc_start(adev);
 
 
 
 
 
 
 
5318
5319	return 0;
5320}
5321
5322/**
5323 * gfx_v8_0_get_gpu_clock_counter - return GPU clock counter snapshot
5324 *
5325 * @adev: amdgpu_device pointer
5326 *
5327 * Fetches a GPU clock counter snapshot.
5328 * Returns the 64 bit clock counter snapshot.
5329 */
5330static uint64_t gfx_v8_0_get_gpu_clock_counter(struct amdgpu_device *adev)
5331{
5332	uint64_t clock;
5333
5334	mutex_lock(&adev->gfx.gpu_clock_mutex);
5335	WREG32(mmRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
5336	clock = (uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_LSB) |
5337		((uint64_t)RREG32(mmRLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
5338	mutex_unlock(&adev->gfx.gpu_clock_mutex);
5339	return clock;
5340}
5341
5342static void gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring *ring,
5343					  uint32_t vmid,
5344					  uint32_t gds_base, uint32_t gds_size,
5345					  uint32_t gws_base, uint32_t gws_size,
5346					  uint32_t oa_base, uint32_t oa_size)
5347{
5348	gds_base = gds_base >> AMDGPU_GDS_SHIFT;
5349	gds_size = gds_size >> AMDGPU_GDS_SHIFT;
5350
5351	gws_base = gws_base >> AMDGPU_GWS_SHIFT;
5352	gws_size = gws_size >> AMDGPU_GWS_SHIFT;
5353
5354	oa_base = oa_base >> AMDGPU_OA_SHIFT;
5355	oa_size = oa_size >> AMDGPU_OA_SHIFT;
5356
5357	/* GDS Base */
5358	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5359	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5360				WRITE_DATA_DST_SEL(0)));
5361	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_base);
5362	amdgpu_ring_write(ring, 0);
5363	amdgpu_ring_write(ring, gds_base);
5364
5365	/* GDS Size */
5366	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5367	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5368				WRITE_DATA_DST_SEL(0)));
5369	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].mem_size);
5370	amdgpu_ring_write(ring, 0);
5371	amdgpu_ring_write(ring, gds_size);
5372
5373	/* GWS */
5374	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5375	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5376				WRITE_DATA_DST_SEL(0)));
5377	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].gws);
5378	amdgpu_ring_write(ring, 0);
5379	amdgpu_ring_write(ring, gws_size << GDS_GWS_VMID0__SIZE__SHIFT | gws_base);
5380
5381	/* OA */
5382	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
5383	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
5384				WRITE_DATA_DST_SEL(0)));
5385	amdgpu_ring_write(ring, amdgpu_gds_reg_offset[vmid].oa);
5386	amdgpu_ring_write(ring, 0);
5387	amdgpu_ring_write(ring, (1 << (oa_size + oa_base)) - (1 << oa_base));
5388}
5389
5390static uint32_t wave_read_ind(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t address)
5391{
5392	WREG32(mmSQ_IND_INDEX,
5393		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5394		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5395		(address << SQ_IND_INDEX__INDEX__SHIFT) |
5396		(SQ_IND_INDEX__FORCE_READ_MASK));
5397	return RREG32(mmSQ_IND_DATA);
5398}
5399
5400static void wave_read_regs(struct amdgpu_device *adev, uint32_t simd,
5401			   uint32_t wave, uint32_t thread,
5402			   uint32_t regno, uint32_t num, uint32_t *out)
5403{
5404	WREG32(mmSQ_IND_INDEX,
5405		(wave << SQ_IND_INDEX__WAVE_ID__SHIFT) |
5406		(simd << SQ_IND_INDEX__SIMD_ID__SHIFT) |
5407		(regno << SQ_IND_INDEX__INDEX__SHIFT) |
5408		(thread << SQ_IND_INDEX__THREAD_ID__SHIFT) |
5409		(SQ_IND_INDEX__FORCE_READ_MASK) |
5410		(SQ_IND_INDEX__AUTO_INCR_MASK));
5411	while (num--)
5412		*(out++) = RREG32(mmSQ_IND_DATA);
5413}
5414
5415static void gfx_v8_0_read_wave_data(struct amdgpu_device *adev, uint32_t simd, uint32_t wave, uint32_t *dst, int *no_fields)
5416{
5417	/* type 0 wave data */
5418	dst[(*no_fields)++] = 0;
5419	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_STATUS);
5420	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_LO);
5421	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_PC_HI);
5422	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_LO);
5423	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_EXEC_HI);
5424	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_HW_ID);
5425	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW0);
5426	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_INST_DW1);
5427	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_GPR_ALLOC);
5428	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_LDS_ALLOC);
5429	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TRAPSTS);
5430	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_STS);
5431	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_LO);
5432	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TBA_HI);
5433	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_LO);
5434	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_TMA_HI);
5435	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_IB_DBG0);
5436	dst[(*no_fields)++] = wave_read_ind(adev, simd, wave, ixSQ_WAVE_M0);
 
5437}
5438
5439static void gfx_v8_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t simd,
5440				     uint32_t wave, uint32_t start,
5441				     uint32_t size, uint32_t *dst)
5442{
5443	wave_read_regs(
5444		adev, simd, wave, 0,
5445		start + SQIND_WAVE_SGPRS_OFFSET, size, dst);
5446}
5447
5448
5449static const struct amdgpu_gfx_funcs gfx_v8_0_gfx_funcs = {
5450	.get_gpu_clock_counter = &gfx_v8_0_get_gpu_clock_counter,
5451	.select_se_sh = &gfx_v8_0_select_se_sh,
5452	.read_wave_data = &gfx_v8_0_read_wave_data,
5453	.read_wave_sgprs = &gfx_v8_0_read_wave_sgprs,
5454	.select_me_pipe_q = &gfx_v8_0_select_me_pipe_q
5455};
5456
5457static int gfx_v8_0_early_init(void *handle)
5458{
5459	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5460
 
5461	adev->gfx.num_gfx_rings = GFX8_NUM_GFX_RINGS;
5462	adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
 
5463	adev->gfx.funcs = &gfx_v8_0_gfx_funcs;
5464	gfx_v8_0_set_ring_funcs(adev);
5465	gfx_v8_0_set_irq_funcs(adev);
5466	gfx_v8_0_set_gds_init(adev);
5467	gfx_v8_0_set_rlc_funcs(adev);
5468
5469	return 0;
5470}
5471
5472static int gfx_v8_0_late_init(void *handle)
5473{
5474	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5475	int r;
5476
5477	r = amdgpu_irq_get(adev, &adev->gfx.priv_reg_irq, 0);
5478	if (r)
5479		return r;
5480
5481	r = amdgpu_irq_get(adev, &adev->gfx.priv_inst_irq, 0);
5482	if (r)
5483		return r;
5484
5485	/* requires IBs so do in late init after IB pool is initialized */
5486	r = gfx_v8_0_do_edc_gpr_workarounds(adev);
5487	if (r)
5488		return r;
5489
5490	amdgpu_device_ip_set_powergating_state(adev,
5491					       AMD_IP_BLOCK_TYPE_GFX,
5492					       AMD_PG_STATE_GATE);
 
 
 
 
 
 
 
 
 
 
5493
5494	return 0;
5495}
5496
5497static void gfx_v8_0_enable_gfx_static_mg_power_gating(struct amdgpu_device *adev,
5498						       bool enable)
5499{
5500	if ((adev->asic_type == CHIP_POLARIS11) ||
5501	    (adev->asic_type == CHIP_POLARIS12))
 
5502		/* Send msg to SMU via Powerplay */
5503		amdgpu_device_ip_set_powergating_state(adev,
5504						       AMD_IP_BLOCK_TYPE_SMC,
5505						       enable ?
5506						       AMD_PG_STATE_GATE : AMD_PG_STATE_UNGATE);
5507
5508	WREG32_FIELD(RLC_PG_CNTL, STATIC_PER_CU_PG_ENABLE, enable ? 1 : 0);
5509}
5510
5511static void gfx_v8_0_enable_gfx_dynamic_mg_power_gating(struct amdgpu_device *adev,
5512							bool enable)
5513{
5514	WREG32_FIELD(RLC_PG_CNTL, DYN_PER_CU_PG_ENABLE, enable ? 1 : 0);
5515}
5516
5517static void polaris11_enable_gfx_quick_mg_power_gating(struct amdgpu_device *adev,
5518		bool enable)
5519{
5520	WREG32_FIELD(RLC_PG_CNTL, QUICK_PG_ENABLE, enable ? 1 : 0);
5521}
5522
5523static void cz_enable_gfx_cg_power_gating(struct amdgpu_device *adev,
5524					  bool enable)
5525{
5526	WREG32_FIELD(RLC_PG_CNTL, GFX_POWER_GATING_ENABLE, enable ? 1 : 0);
5527}
5528
5529static void cz_enable_gfx_pipeline_power_gating(struct amdgpu_device *adev,
5530						bool enable)
5531{
5532	WREG32_FIELD(RLC_PG_CNTL, GFX_PIPELINE_PG_ENABLE, enable ? 1 : 0);
5533
5534	/* Read any GFX register to wake up GFX. */
5535	if (!enable)
5536		RREG32(mmDB_RENDER_CONTROL);
5537}
5538
5539static void cz_update_gfx_cg_power_gating(struct amdgpu_device *adev,
5540					  bool enable)
5541{
5542	if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_PG) && enable) {
5543		cz_enable_gfx_cg_power_gating(adev, true);
5544		if (adev->pg_flags & AMD_PG_SUPPORT_GFX_PIPELINE)
5545			cz_enable_gfx_pipeline_power_gating(adev, true);
5546	} else {
5547		cz_enable_gfx_cg_power_gating(adev, false);
5548		cz_enable_gfx_pipeline_power_gating(adev, false);
5549	}
5550}
5551
5552static int gfx_v8_0_set_powergating_state(void *handle,
5553					  enum amd_powergating_state state)
5554{
5555	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5556	bool enable = (state == AMD_PG_STATE_GATE);
5557
5558	if (amdgpu_sriov_vf(adev))
5559		return 0;
5560
 
 
 
 
 
5561	switch (adev->asic_type) {
5562	case CHIP_CARRIZO:
5563	case CHIP_STONEY:
5564
5565		if (adev->pg_flags & AMD_PG_SUPPORT_RLC_SMU_HS) {
5566			cz_enable_sck_slow_down_on_power_up(adev, true);
5567			cz_enable_sck_slow_down_on_power_down(adev, true);
5568		} else {
5569			cz_enable_sck_slow_down_on_power_up(adev, false);
5570			cz_enable_sck_slow_down_on_power_down(adev, false);
5571		}
5572		if (adev->pg_flags & AMD_PG_SUPPORT_CP)
5573			cz_enable_cp_power_gating(adev, true);
5574		else
5575			cz_enable_cp_power_gating(adev, false);
5576
5577		cz_update_gfx_cg_power_gating(adev, enable);
5578
5579		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
5580			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
5581		else
5582			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
5583
5584		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
5585			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
5586		else
5587			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
5588		break;
5589	case CHIP_POLARIS11:
5590	case CHIP_POLARIS12:
 
5591		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_SMG) && enable)
5592			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, true);
5593		else
5594			gfx_v8_0_enable_gfx_static_mg_power_gating(adev, false);
5595
5596		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_DMG) && enable)
5597			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, true);
5598		else
5599			gfx_v8_0_enable_gfx_dynamic_mg_power_gating(adev, false);
5600
5601		if ((adev->pg_flags & AMD_PG_SUPPORT_GFX_QUICK_MG) && enable)
5602			polaris11_enable_gfx_quick_mg_power_gating(adev, true);
5603		else
5604			polaris11_enable_gfx_quick_mg_power_gating(adev, false);
5605		break;
5606	default:
5607		break;
5608	}
5609
 
 
 
 
5610	return 0;
5611}
5612
5613static void gfx_v8_0_get_clockgating_state(void *handle, u32 *flags)
5614{
5615	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5616	int data;
5617
5618	if (amdgpu_sriov_vf(adev))
5619		*flags = 0;
5620
5621	/* AMD_CG_SUPPORT_GFX_MGCG */
5622	data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5623	if (!(data & RLC_CGTT_MGCG_OVERRIDE__CPF_MASK))
5624		*flags |= AMD_CG_SUPPORT_GFX_MGCG;
5625
5626	/* AMD_CG_SUPPORT_GFX_CGLG */
5627	data = RREG32(mmRLC_CGCG_CGLS_CTRL);
5628	if (data & RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK)
5629		*flags |= AMD_CG_SUPPORT_GFX_CGCG;
5630
5631	/* AMD_CG_SUPPORT_GFX_CGLS */
5632	if (data & RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK)
5633		*flags |= AMD_CG_SUPPORT_GFX_CGLS;
5634
5635	/* AMD_CG_SUPPORT_GFX_CGTS */
5636	data = RREG32(mmCGTS_SM_CTRL_REG);
5637	if (!(data & CGTS_SM_CTRL_REG__OVERRIDE_MASK))
5638		*flags |= AMD_CG_SUPPORT_GFX_CGTS;
5639
5640	/* AMD_CG_SUPPORT_GFX_CGTS_LS */
5641	if (!(data & CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK))
5642		*flags |= AMD_CG_SUPPORT_GFX_CGTS_LS;
5643
5644	/* AMD_CG_SUPPORT_GFX_RLC_LS */
5645	data = RREG32(mmRLC_MEM_SLP_CNTL);
5646	if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK)
5647		*flags |= AMD_CG_SUPPORT_GFX_RLC_LS | AMD_CG_SUPPORT_GFX_MGLS;
5648
5649	/* AMD_CG_SUPPORT_GFX_CP_LS */
5650	data = RREG32(mmCP_MEM_SLP_CNTL);
5651	if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK)
5652		*flags |= AMD_CG_SUPPORT_GFX_CP_LS | AMD_CG_SUPPORT_GFX_MGLS;
5653}
5654
5655static void gfx_v8_0_send_serdes_cmd(struct amdgpu_device *adev,
5656				     uint32_t reg_addr, uint32_t cmd)
5657{
5658	uint32_t data;
5659
5660	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
5661
5662	WREG32(mmRLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
5663	WREG32(mmRLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
5664
5665	data = RREG32(mmRLC_SERDES_WR_CTRL);
5666	if (adev->asic_type == CHIP_STONEY)
5667		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5668			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5669			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5670			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5671			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5672			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5673			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5674			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5675			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5676	else
5677		data &= ~(RLC_SERDES_WR_CTRL__WRITE_COMMAND_MASK |
5678			  RLC_SERDES_WR_CTRL__READ_COMMAND_MASK |
5679			  RLC_SERDES_WR_CTRL__P1_SELECT_MASK |
5680			  RLC_SERDES_WR_CTRL__P2_SELECT_MASK |
5681			  RLC_SERDES_WR_CTRL__RDDATA_RESET_MASK |
5682			  RLC_SERDES_WR_CTRL__POWER_DOWN_MASK |
5683			  RLC_SERDES_WR_CTRL__POWER_UP_MASK |
5684			  RLC_SERDES_WR_CTRL__SHORT_FORMAT_MASK |
5685			  RLC_SERDES_WR_CTRL__BPM_DATA_MASK |
5686			  RLC_SERDES_WR_CTRL__REG_ADDR_MASK |
5687			  RLC_SERDES_WR_CTRL__SRBM_OVERRIDE_MASK);
5688	data |= (RLC_SERDES_WR_CTRL__RSVD_BPM_ADDR_MASK |
5689		 (cmd << RLC_SERDES_WR_CTRL__BPM_DATA__SHIFT) |
5690		 (reg_addr << RLC_SERDES_WR_CTRL__REG_ADDR__SHIFT) |
5691		 (0xff << RLC_SERDES_WR_CTRL__BPM_ADDR__SHIFT));
5692
5693	WREG32(mmRLC_SERDES_WR_CTRL, data);
5694}
5695
5696#define MSG_ENTER_RLC_SAFE_MODE     1
5697#define MSG_EXIT_RLC_SAFE_MODE      0
5698#define RLC_GPR_REG2__REQ_MASK 0x00000001
5699#define RLC_GPR_REG2__REQ__SHIFT 0
5700#define RLC_GPR_REG2__MESSAGE__SHIFT 0x00000001
5701#define RLC_GPR_REG2__MESSAGE_MASK 0x0000001e
5702
5703static void iceland_enter_rlc_safe_mode(struct amdgpu_device *adev)
5704{
5705	u32 data;
5706	unsigned i;
5707
5708	data = RREG32(mmRLC_CNTL);
5709	if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
5710		return;
5711
5712	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
5713		data |= RLC_SAFE_MODE__CMD_MASK;
5714		data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5715		data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
5716		WREG32(mmRLC_SAFE_MODE, data);
5717
5718		for (i = 0; i < adev->usec_timeout; i++) {
5719			if ((RREG32(mmRLC_GPM_STAT) &
5720			     (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5721			      RLC_GPM_STAT__GFX_POWER_STATUS_MASK)) ==
5722			    (RLC_GPM_STAT__GFX_CLOCK_STATUS_MASK |
5723			     RLC_GPM_STAT__GFX_POWER_STATUS_MASK))
5724				break;
5725			udelay(1);
5726		}
5727
5728		for (i = 0; i < adev->usec_timeout; i++) {
5729			if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5730				break;
5731			udelay(1);
5732		}
5733		adev->gfx.rlc.in_safe_mode = true;
 
 
 
 
 
 
 
 
5734	}
5735}
5736
5737static void iceland_exit_rlc_safe_mode(struct amdgpu_device *adev)
5738{
5739	u32 data = 0;
5740	unsigned i;
5741
5742	data = RREG32(mmRLC_CNTL);
5743	if (!(data & RLC_CNTL__RLC_ENABLE_F32_MASK))
5744		return;
5745
5746	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_MGCG)) {
5747		if (adev->gfx.rlc.in_safe_mode) {
5748			data |= RLC_SAFE_MODE__CMD_MASK;
5749			data &= ~RLC_SAFE_MODE__MESSAGE_MASK;
5750			WREG32(mmRLC_SAFE_MODE, data);
5751			adev->gfx.rlc.in_safe_mode = false;
5752		}
5753	}
5754
5755	for (i = 0; i < adev->usec_timeout; i++) {
5756		if (!REG_GET_FIELD(RREG32(mmRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
5757			break;
5758		udelay(1);
5759	}
5760}
5761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5762static const struct amdgpu_rlc_funcs iceland_rlc_funcs = {
5763	.enter_safe_mode = iceland_enter_rlc_safe_mode,
5764	.exit_safe_mode = iceland_exit_rlc_safe_mode
 
 
 
 
 
 
 
 
 
 
5765};
5766
5767static void gfx_v8_0_update_medium_grain_clock_gating(struct amdgpu_device *adev,
5768						      bool enable)
5769{
5770	uint32_t temp, data;
5771
5772	adev->gfx.rlc.funcs->enter_safe_mode(adev);
5773
5774	/* It is disabled by HW by default */
5775	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG)) {
5776		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
5777			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS)
5778				/* 1 - RLC memory Light sleep */
5779				WREG32_FIELD(RLC_MEM_SLP_CNTL, RLC_MEM_LS_EN, 1);
5780
5781			if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS)
5782				WREG32_FIELD(CP_MEM_SLP_CNTL, CP_MEM_LS_EN, 1);
5783		}
5784
5785		/* 3 - RLC_CGTT_MGCG_OVERRIDE */
5786		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5787		if (adev->flags & AMD_IS_APU)
5788			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5789				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5790				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK);
5791		else
5792			data &= ~(RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5793				  RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5794				  RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
5795				  RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
5796
5797		if (temp != data)
5798			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
5799
5800		/* 4 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5801		gfx_v8_0_wait_for_rlc_serdes(adev);
5802
5803		/* 5 - clear mgcg override */
5804		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
5805
5806		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS) {
5807			/* 6 - Enable CGTS(Tree Shade) MGCG /MGLS */
5808			temp = data = RREG32(mmCGTS_SM_CTRL_REG);
5809			data &= ~(CGTS_SM_CTRL_REG__SM_MODE_MASK);
5810			data |= (0x2 << CGTS_SM_CTRL_REG__SM_MODE__SHIFT);
5811			data |= CGTS_SM_CTRL_REG__SM_MODE_ENABLE_MASK;
5812			data &= ~CGTS_SM_CTRL_REG__OVERRIDE_MASK;
5813			if ((adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) &&
5814			    (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGTS_LS))
5815				data &= ~CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK;
5816			data |= CGTS_SM_CTRL_REG__ON_MONITOR_ADD_EN_MASK;
5817			data |= (0x96 << CGTS_SM_CTRL_REG__ON_MONITOR_ADD__SHIFT);
5818			if (temp != data)
5819				WREG32(mmCGTS_SM_CTRL_REG, data);
5820		}
5821		udelay(50);
5822
5823		/* 7 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5824		gfx_v8_0_wait_for_rlc_serdes(adev);
5825	} else {
5826		/* 1 - MGCG_OVERRIDE[0] for CP and MGCG_OVERRIDE[1] for RLC */
5827		temp = data = RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5828		data |= (RLC_CGTT_MGCG_OVERRIDE__CPF_MASK |
5829				RLC_CGTT_MGCG_OVERRIDE__RLC_MASK |
5830				RLC_CGTT_MGCG_OVERRIDE__MGCG_MASK |
5831				RLC_CGTT_MGCG_OVERRIDE__GRBM_MASK);
5832		if (temp != data)
5833			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data);
5834
5835		/* 2 - disable MGLS in RLC */
5836		data = RREG32(mmRLC_MEM_SLP_CNTL);
5837		if (data & RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK) {
5838			data &= ~RLC_MEM_SLP_CNTL__RLC_MEM_LS_EN_MASK;
5839			WREG32(mmRLC_MEM_SLP_CNTL, data);
5840		}
5841
5842		/* 3 - disable MGLS in CP */
5843		data = RREG32(mmCP_MEM_SLP_CNTL);
5844		if (data & CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK) {
5845			data &= ~CP_MEM_SLP_CNTL__CP_MEM_LS_EN_MASK;
5846			WREG32(mmCP_MEM_SLP_CNTL, data);
5847		}
5848
5849		/* 4 - Disable CGTS(Tree Shade) MGCG and MGLS */
5850		temp = data = RREG32(mmCGTS_SM_CTRL_REG);
5851		data |= (CGTS_SM_CTRL_REG__OVERRIDE_MASK |
5852				CGTS_SM_CTRL_REG__LS_OVERRIDE_MASK);
5853		if (temp != data)
5854			WREG32(mmCGTS_SM_CTRL_REG, data);
5855
5856		/* 5 - wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5857		gfx_v8_0_wait_for_rlc_serdes(adev);
5858
5859		/* 6 - set mgcg override */
5860		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_MGCG_OVERRIDE, SET_BPM_SERDES_CMD);
5861
5862		udelay(50);
5863
5864		/* 7- wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5865		gfx_v8_0_wait_for_rlc_serdes(adev);
5866	}
5867
5868	adev->gfx.rlc.funcs->exit_safe_mode(adev);
5869}
5870
5871static void gfx_v8_0_update_coarse_grain_clock_gating(struct amdgpu_device *adev,
5872						      bool enable)
5873{
5874	uint32_t temp, temp1, data, data1;
5875
5876	temp = data = RREG32(mmRLC_CGCG_CGLS_CTRL);
5877
5878	adev->gfx.rlc.funcs->enter_safe_mode(adev);
5879
5880	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG)) {
5881		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5882		data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK;
5883		if (temp1 != data1)
5884			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5885
5886		/* : wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5887		gfx_v8_0_wait_for_rlc_serdes(adev);
5888
5889		/* 2 - clear cgcg override */
5890		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, CLE_BPM_SERDES_CMD);
5891
5892		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5893		gfx_v8_0_wait_for_rlc_serdes(adev);
5894
5895		/* 3 - write cmd to set CGLS */
5896		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, SET_BPM_SERDES_CMD);
5897
5898		/* 4 - enable cgcg */
5899		data |= RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK;
5900
5901		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
5902			/* enable cgls*/
5903			data |= RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
5904
5905			temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5906			data1 &= ~RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK;
5907
5908			if (temp1 != data1)
5909				WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5910		} else {
5911			data &= ~RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK;
5912		}
5913
5914		if (temp != data)
5915			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5916
5917		/* 5 enable cntx_empty_int_enable/cntx_busy_int_enable/
5918		 * Cmp_busy/GFX_Idle interrupts
5919		 */
5920		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
5921	} else {
5922		/* disable cntx_empty_int_enable & GFX Idle interrupt */
5923		gfx_v8_0_enable_gui_idle_interrupt(adev, false);
5924
5925		/* TEST CGCG */
5926		temp1 = data1 =	RREG32(mmRLC_CGTT_MGCG_OVERRIDE);
5927		data1 |= (RLC_CGTT_MGCG_OVERRIDE__CGCG_MASK |
5928				RLC_CGTT_MGCG_OVERRIDE__CGLS_MASK);
5929		if (temp1 != data1)
5930			WREG32(mmRLC_CGTT_MGCG_OVERRIDE, data1);
5931
5932		/* read gfx register to wake up cgcg */
5933		RREG32(mmCB_CGTT_SCLK_CTRL);
5934		RREG32(mmCB_CGTT_SCLK_CTRL);
5935		RREG32(mmCB_CGTT_SCLK_CTRL);
5936		RREG32(mmCB_CGTT_SCLK_CTRL);
5937
5938		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5939		gfx_v8_0_wait_for_rlc_serdes(adev);
5940
5941		/* write cmd to Set CGCG Overrride */
5942		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGCG_OVERRIDE, SET_BPM_SERDES_CMD);
5943
5944		/* wait for RLC_SERDES_CU_MASTER & RLC_SERDES_NONCU_MASTER idle */
5945		gfx_v8_0_wait_for_rlc_serdes(adev);
5946
5947		/* write cmd to Clear CGLS */
5948		gfx_v8_0_send_serdes_cmd(adev, BPM_REG_CGLS_EN, CLE_BPM_SERDES_CMD);
5949
5950		/* disable cgcg, cgls should be disabled too. */
5951		data &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
5952			  RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
5953		if (temp != data)
5954			WREG32(mmRLC_CGCG_CGLS_CTRL, data);
5955		/* enable interrupts again for PG */
5956		gfx_v8_0_enable_gui_idle_interrupt(adev, true);
5957	}
5958
5959	gfx_v8_0_wait_for_rlc_serdes(adev);
5960
5961	adev->gfx.rlc.funcs->exit_safe_mode(adev);
5962}
5963static int gfx_v8_0_update_gfx_clock_gating(struct amdgpu_device *adev,
5964					    bool enable)
5965{
5966	if (enable) {
5967		/* CGCG/CGLS should be enabled after MGCG/MGLS/TS(CG/LS)
5968		 * ===  MGCG + MGLS + TS(CG/LS) ===
5969		 */
5970		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
5971		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
5972	} else {
5973		/* CGCG/CGLS should be disabled before MGCG/MGLS/TS(CG/LS)
5974		 * ===  CGCG + CGLS ===
5975		 */
5976		gfx_v8_0_update_coarse_grain_clock_gating(adev, enable);
5977		gfx_v8_0_update_medium_grain_clock_gating(adev, enable);
5978	}
5979	return 0;
5980}
5981
5982static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,
5983					  enum amd_clockgating_state state)
5984{
5985	uint32_t msg_id, pp_state = 0;
5986	uint32_t pp_support_state = 0;
5987
5988	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
5989		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
5990			pp_support_state = PP_STATE_SUPPORT_LS;
5991			pp_state = PP_STATE_LS;
5992		}
5993		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
5994			pp_support_state |= PP_STATE_SUPPORT_CG;
5995			pp_state |= PP_STATE_CG;
5996		}
5997		if (state == AMD_CG_STATE_UNGATE)
5998			pp_state = 0;
5999
6000		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6001				PP_BLOCK_GFX_CG,
6002				pp_support_state,
6003				pp_state);
6004		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6005			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6006	}
6007
6008	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
6009		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
6010			pp_support_state = PP_STATE_SUPPORT_LS;
6011			pp_state = PP_STATE_LS;
6012		}
6013
6014		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
6015			pp_support_state |= PP_STATE_SUPPORT_CG;
6016			pp_state |= PP_STATE_CG;
6017		}
6018
6019		if (state == AMD_CG_STATE_UNGATE)
6020			pp_state = 0;
6021
6022		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6023				PP_BLOCK_GFX_MG,
6024				pp_support_state,
6025				pp_state);
6026		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6027			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6028	}
6029
6030	return 0;
6031}
6032
6033static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,
6034					  enum amd_clockgating_state state)
6035{
6036
6037	uint32_t msg_id, pp_state = 0;
6038	uint32_t pp_support_state = 0;
6039
6040	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_CGCG | AMD_CG_SUPPORT_GFX_CGLS)) {
6041		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGLS) {
6042			pp_support_state = PP_STATE_SUPPORT_LS;
6043			pp_state = PP_STATE_LS;
6044		}
6045		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CGCG) {
6046			pp_support_state |= PP_STATE_SUPPORT_CG;
6047			pp_state |= PP_STATE_CG;
6048		}
6049		if (state == AMD_CG_STATE_UNGATE)
6050			pp_state = 0;
6051
6052		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6053				PP_BLOCK_GFX_CG,
6054				pp_support_state,
6055				pp_state);
6056		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6057			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6058	}
6059
6060	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_3D_CGCG | AMD_CG_SUPPORT_GFX_3D_CGLS)) {
6061		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGLS) {
6062			pp_support_state = PP_STATE_SUPPORT_LS;
6063			pp_state = PP_STATE_LS;
6064		}
6065		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_3D_CGCG) {
6066			pp_support_state |= PP_STATE_SUPPORT_CG;
6067			pp_state |= PP_STATE_CG;
6068		}
6069		if (state == AMD_CG_STATE_UNGATE)
6070			pp_state = 0;
6071
6072		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6073				PP_BLOCK_GFX_3D,
6074				pp_support_state,
6075				pp_state);
6076		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6077			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6078	}
6079
6080	if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG | AMD_CG_SUPPORT_GFX_MGLS)) {
6081		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGLS) {
6082			pp_support_state = PP_STATE_SUPPORT_LS;
6083			pp_state = PP_STATE_LS;
6084		}
6085
6086		if (adev->cg_flags & AMD_CG_SUPPORT_GFX_MGCG) {
6087			pp_support_state |= PP_STATE_SUPPORT_CG;
6088			pp_state |= PP_STATE_CG;
6089		}
6090
6091		if (state == AMD_CG_STATE_UNGATE)
6092			pp_state = 0;
6093
6094		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6095				PP_BLOCK_GFX_MG,
6096				pp_support_state,
6097				pp_state);
6098		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6099			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6100	}
6101
6102	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_RLC_LS) {
6103		pp_support_state = PP_STATE_SUPPORT_LS;
6104
6105		if (state == AMD_CG_STATE_UNGATE)
6106			pp_state = 0;
6107		else
6108			pp_state = PP_STATE_LS;
6109
6110		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6111				PP_BLOCK_GFX_RLC,
6112				pp_support_state,
6113				pp_state);
6114		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6115			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6116	}
6117
6118	if (adev->cg_flags & AMD_CG_SUPPORT_GFX_CP_LS) {
6119		pp_support_state = PP_STATE_SUPPORT_LS;
6120
6121		if (state == AMD_CG_STATE_UNGATE)
6122			pp_state = 0;
6123		else
6124			pp_state = PP_STATE_LS;
6125		msg_id = PP_CG_MSG_ID(PP_GROUP_GFX,
6126			PP_BLOCK_GFX_CP,
6127			pp_support_state,
6128			pp_state);
6129		if (adev->powerplay.pp_funcs->set_clockgating_by_smu)
6130			amdgpu_dpm_set_clockgating_by_smu(adev, msg_id);
6131	}
6132
6133	return 0;
6134}
6135
6136static int gfx_v8_0_set_clockgating_state(void *handle,
6137					  enum amd_clockgating_state state)
6138{
6139	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6140
6141	if (amdgpu_sriov_vf(adev))
6142		return 0;
6143
6144	switch (adev->asic_type) {
6145	case CHIP_FIJI:
6146	case CHIP_CARRIZO:
6147	case CHIP_STONEY:
6148		gfx_v8_0_update_gfx_clock_gating(adev,
6149						 state == AMD_CG_STATE_GATE);
6150		break;
6151	case CHIP_TONGA:
6152		gfx_v8_0_tonga_update_gfx_clock_gating(adev, state);
6153		break;
6154	case CHIP_POLARIS10:
6155	case CHIP_POLARIS11:
6156	case CHIP_POLARIS12:
 
6157		gfx_v8_0_polaris_update_gfx_clock_gating(adev, state);
6158		break;
6159	default:
6160		break;
6161	}
6162	return 0;
6163}
6164
6165static u64 gfx_v8_0_ring_get_rptr(struct amdgpu_ring *ring)
6166{
6167	return ring->adev->wb.wb[ring->rptr_offs];
6168}
6169
6170static u64 gfx_v8_0_ring_get_wptr_gfx(struct amdgpu_ring *ring)
6171{
6172	struct amdgpu_device *adev = ring->adev;
6173
6174	if (ring->use_doorbell)
6175		/* XXX check if swapping is necessary on BE */
6176		return ring->adev->wb.wb[ring->wptr_offs];
6177	else
6178		return RREG32(mmCP_RB0_WPTR);
6179}
6180
6181static void gfx_v8_0_ring_set_wptr_gfx(struct amdgpu_ring *ring)
6182{
6183	struct amdgpu_device *adev = ring->adev;
6184
6185	if (ring->use_doorbell) {
6186		/* XXX check if swapping is necessary on BE */
6187		adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);
6188		WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6189	} else {
6190		WREG32(mmCP_RB0_WPTR, lower_32_bits(ring->wptr));
6191		(void)RREG32(mmCP_RB0_WPTR);
6192	}
6193}
6194
6195static void gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
6196{
6197	u32 ref_and_mask, reg_mem_engine;
6198
6199	if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) ||
6200	    (ring->funcs->type == AMDGPU_RING_TYPE_KIQ)) {
6201		switch (ring->me) {
6202		case 1:
6203			ref_and_mask = GPU_HDP_FLUSH_DONE__CP2_MASK << ring->pipe;
6204			break;
6205		case 2:
6206			ref_and_mask = GPU_HDP_FLUSH_DONE__CP6_MASK << ring->pipe;
6207			break;
6208		default:
6209			return;
6210		}
6211		reg_mem_engine = 0;
6212	} else {
6213		ref_and_mask = GPU_HDP_FLUSH_DONE__CP0_MASK;
6214		reg_mem_engine = WAIT_REG_MEM_ENGINE(1); /* pfp */
6215	}
6216
6217	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6218	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
6219				 WAIT_REG_MEM_FUNCTION(3) |  /* == */
6220				 reg_mem_engine));
6221	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_REQ);
6222	amdgpu_ring_write(ring, mmGPU_HDP_FLUSH_DONE);
6223	amdgpu_ring_write(ring, ref_and_mask);
6224	amdgpu_ring_write(ring, ref_and_mask);
6225	amdgpu_ring_write(ring, 0x20); /* poll interval */
6226}
6227
6228static void gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)
6229{
6230	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
6231	amdgpu_ring_write(ring, EVENT_TYPE(VS_PARTIAL_FLUSH) |
6232		EVENT_INDEX(4));
6233
6234	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE, 0));
6235	amdgpu_ring_write(ring, EVENT_TYPE(VGT_FLUSH) |
6236		EVENT_INDEX(0));
6237}
6238
6239static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
6240				      struct amdgpu_ib *ib,
6241				      unsigned vmid, bool ctx_switch)
 
6242{
 
6243	u32 header, control = 0;
6244
6245	if (ib->flags & AMDGPU_IB_FLAG_CE)
6246		header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
6247	else
6248		header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
6249
6250	control |= ib->length_dw | (vmid << 24);
6251
6252	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
6253		control |= INDIRECT_BUFFER_PRE_ENB(1);
6254
6255		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
6256			gfx_v8_0_ring_emit_de_meta(ring);
6257	}
6258
6259	amdgpu_ring_write(ring, header);
6260	amdgpu_ring_write(ring,
6261#ifdef __BIG_ENDIAN
6262			  (2 << 0) |
6263#endif
6264			  (ib->gpu_addr & 0xFFFFFFFC));
6265	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
6266	amdgpu_ring_write(ring, control);
6267}
6268
6269static void gfx_v8_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
 
6270					  struct amdgpu_ib *ib,
6271					  unsigned vmid, bool ctx_switch)
6272{
 
6273	u32 control = INDIRECT_BUFFER_VALID | ib->length_dw | (vmid << 24);
6274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6275	amdgpu_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
6276	amdgpu_ring_write(ring,
6277#ifdef __BIG_ENDIAN
6278				(2 << 0) |
6279#endif
6280				(ib->gpu_addr & 0xFFFFFFFC));
6281	amdgpu_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
6282	amdgpu_ring_write(ring, control);
6283}
6284
6285static void gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring, u64 addr,
6286					 u64 seq, unsigned flags)
6287{
6288	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6289	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
 
6290
6291	/* EVENT_WRITE_EOP - flush caches, send int */
 
 
6292	amdgpu_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
6293	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6294				 EOP_TC_ACTION_EN |
6295				 EOP_TC_WB_ACTION_EN |
6296				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6297				 EVENT_INDEX(5)));
6298	amdgpu_ring_write(ring, addr & 0xfffffffc);
6299	amdgpu_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6300			  DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6301	amdgpu_ring_write(ring, lower_32_bits(seq));
6302	amdgpu_ring_write(ring, upper_32_bits(seq));
6303
6304}
6305
6306static void gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
6307{
6308	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
6309	uint32_t seq = ring->fence_drv.sync_seq;
6310	uint64_t addr = ring->fence_drv.gpu_addr;
6311
6312	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6313	amdgpu_ring_write(ring, (WAIT_REG_MEM_MEM_SPACE(1) | /* memory */
6314				 WAIT_REG_MEM_FUNCTION(3) | /* equal */
6315				 WAIT_REG_MEM_ENGINE(usepfp))); /* pfp or me */
6316	amdgpu_ring_write(ring, addr & 0xfffffffc);
6317	amdgpu_ring_write(ring, upper_32_bits(addr) & 0xffffffff);
6318	amdgpu_ring_write(ring, seq);
6319	amdgpu_ring_write(ring, 0xffffffff);
6320	amdgpu_ring_write(ring, 4); /* poll interval */
6321}
6322
6323static void gfx_v8_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
6324					unsigned vmid, uint64_t pd_addr)
6325{
6326	int usepfp = (ring->funcs->type == AMDGPU_RING_TYPE_GFX);
6327
6328	amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
6329
6330	/* wait for the invalidate to complete */
6331	amdgpu_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
6332	amdgpu_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
6333				 WAIT_REG_MEM_FUNCTION(0) |  /* always */
6334				 WAIT_REG_MEM_ENGINE(0))); /* me */
6335	amdgpu_ring_write(ring, mmVM_INVALIDATE_REQUEST);
6336	amdgpu_ring_write(ring, 0);
6337	amdgpu_ring_write(ring, 0); /* ref */
6338	amdgpu_ring_write(ring, 0); /* mask */
6339	amdgpu_ring_write(ring, 0x20); /* poll interval */
6340
6341	/* compute doesn't have PFP */
6342	if (usepfp) {
6343		/* sync PFP to ME, otherwise we might get invalid PFP reads */
6344		amdgpu_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
6345		amdgpu_ring_write(ring, 0x0);
6346	}
6347}
6348
6349static u64 gfx_v8_0_ring_get_wptr_compute(struct amdgpu_ring *ring)
6350{
6351	return ring->adev->wb.wb[ring->wptr_offs];
6352}
6353
6354static void gfx_v8_0_ring_set_wptr_compute(struct amdgpu_ring *ring)
6355{
6356	struct amdgpu_device *adev = ring->adev;
6357
6358	/* XXX check if swapping is necessary on BE */
6359	adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);
6360	WDOORBELL32(ring->doorbell_index, lower_32_bits(ring->wptr));
6361}
6362
6363static void gfx_v8_0_ring_set_pipe_percent(struct amdgpu_ring *ring,
6364					   bool acquire)
6365{
6366	struct amdgpu_device *adev = ring->adev;
6367	int pipe_num, tmp, reg;
6368	int pipe_percent = acquire ? SPI_WCL_PIPE_PERCENT_GFX__VALUE_MASK : 0x1;
6369
6370	pipe_num = ring->me * adev->gfx.mec.num_pipe_per_mec + ring->pipe;
6371
6372	/* first me only has 2 entries, GFX and HP3D */
6373	if (ring->me > 0)
6374		pipe_num -= 2;
6375
6376	reg = mmSPI_WCL_PIPE_PERCENT_GFX + pipe_num;
6377	tmp = RREG32(reg);
6378	tmp = REG_SET_FIELD(tmp, SPI_WCL_PIPE_PERCENT_GFX, VALUE, pipe_percent);
6379	WREG32(reg, tmp);
6380}
6381
6382static void gfx_v8_0_pipe_reserve_resources(struct amdgpu_device *adev,
6383					    struct amdgpu_ring *ring,
6384					    bool acquire)
6385{
6386	int i, pipe;
6387	bool reserve;
6388	struct amdgpu_ring *iring;
6389
6390	mutex_lock(&adev->gfx.pipe_reserve_mutex);
6391	pipe = amdgpu_gfx_queue_to_bit(adev, ring->me, ring->pipe, 0);
6392	if (acquire)
6393		set_bit(pipe, adev->gfx.pipe_reserve_bitmap);
6394	else
6395		clear_bit(pipe, adev->gfx.pipe_reserve_bitmap);
6396
6397	if (!bitmap_weight(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES)) {
6398		/* Clear all reservations - everyone reacquires all resources */
6399		for (i = 0; i < adev->gfx.num_gfx_rings; ++i)
6400			gfx_v8_0_ring_set_pipe_percent(&adev->gfx.gfx_ring[i],
6401						       true);
6402
6403		for (i = 0; i < adev->gfx.num_compute_rings; ++i)
6404			gfx_v8_0_ring_set_pipe_percent(&adev->gfx.compute_ring[i],
6405						       true);
6406	} else {
6407		/* Lower all pipes without a current reservation */
6408		for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
6409			iring = &adev->gfx.gfx_ring[i];
6410			pipe = amdgpu_gfx_queue_to_bit(adev,
6411						       iring->me,
6412						       iring->pipe,
6413						       0);
6414			reserve = test_bit(pipe, adev->gfx.pipe_reserve_bitmap);
6415			gfx_v8_0_ring_set_pipe_percent(iring, reserve);
6416		}
6417
6418		for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
6419			iring = &adev->gfx.compute_ring[i];
6420			pipe = amdgpu_gfx_queue_to_bit(adev,
6421						       iring->me,
6422						       iring->pipe,
6423						       0);
6424			reserve = test_bit(pipe, adev->gfx.pipe_reserve_bitmap);
6425			gfx_v8_0_ring_set_pipe_percent(iring, reserve);
6426		}
6427	}
6428
6429	mutex_unlock(&adev->gfx.pipe_reserve_mutex);
6430}
6431
6432static void gfx_v8_0_hqd_set_priority(struct amdgpu_device *adev,
6433				      struct amdgpu_ring *ring,
6434				      bool acquire)
6435{
6436	uint32_t pipe_priority = acquire ? 0x2 : 0x0;
6437	uint32_t queue_priority = acquire ? 0xf : 0x0;
6438
6439	mutex_lock(&adev->srbm_mutex);
6440	vi_srbm_select(adev, ring->me, ring->pipe, ring->queue, 0);
6441
6442	WREG32(mmCP_HQD_PIPE_PRIORITY, pipe_priority);
6443	WREG32(mmCP_HQD_QUEUE_PRIORITY, queue_priority);
6444
6445	vi_srbm_select(adev, 0, 0, 0, 0);
6446	mutex_unlock(&adev->srbm_mutex);
6447}
6448static void gfx_v8_0_ring_set_priority_compute(struct amdgpu_ring *ring,
6449					       enum drm_sched_priority priority)
6450{
6451	struct amdgpu_device *adev = ring->adev;
6452	bool acquire = priority == DRM_SCHED_PRIORITY_HIGH_HW;
6453
6454	if (ring->funcs->type != AMDGPU_RING_TYPE_COMPUTE)
6455		return;
6456
6457	gfx_v8_0_hqd_set_priority(adev, ring, acquire);
6458	gfx_v8_0_pipe_reserve_resources(adev, ring, acquire);
6459}
6460
6461static void gfx_v8_0_ring_emit_fence_compute(struct amdgpu_ring *ring,
6462					     u64 addr, u64 seq,
6463					     unsigned flags)
6464{
6465	bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
6466	bool int_sel = flags & AMDGPU_FENCE_FLAG_INT;
6467
6468	/* RELEASE_MEM - flush caches, send int */
6469	amdgpu_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
6470	amdgpu_ring_write(ring, (EOP_TCL1_ACTION_EN |
6471				 EOP_TC_ACTION_EN |
6472				 EOP_TC_WB_ACTION_EN |
6473				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
6474				 EVENT_INDEX(5)));
6475	amdgpu_ring_write(ring, DATA_SEL(write64bit ? 2 : 1) | INT_SEL(int_sel ? 2 : 0));
6476	amdgpu_ring_write(ring, addr & 0xfffffffc);
6477	amdgpu_ring_write(ring, upper_32_bits(addr));
6478	amdgpu_ring_write(ring, lower_32_bits(seq));
6479	amdgpu_ring_write(ring, upper_32_bits(seq));
6480}
6481
6482static void gfx_v8_0_ring_emit_fence_kiq(struct amdgpu_ring *ring, u64 addr,
6483					 u64 seq, unsigned int flags)
6484{
6485	/* we only allocate 32bit for each seq wb address */
6486	BUG_ON(flags & AMDGPU_FENCE_FLAG_64BIT);
6487
6488	/* write fence seq to the "addr" */
6489	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6490	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
6491				 WRITE_DATA_DST_SEL(5) | WR_CONFIRM));
6492	amdgpu_ring_write(ring, lower_32_bits(addr));
6493	amdgpu_ring_write(ring, upper_32_bits(addr));
6494	amdgpu_ring_write(ring, lower_32_bits(seq));
6495
6496	if (flags & AMDGPU_FENCE_FLAG_INT) {
6497		/* set register to trigger INT */
6498		amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6499		amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |
6500					 WRITE_DATA_DST_SEL(0) | WR_CONFIRM));
6501		amdgpu_ring_write(ring, mmCPC_INT_STATUS);
6502		amdgpu_ring_write(ring, 0);
6503		amdgpu_ring_write(ring, 0x20000000); /* src_id is 178 */
6504	}
6505}
6506
6507static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
6508{
6509	amdgpu_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
6510	amdgpu_ring_write(ring, 0);
6511}
6512
6513static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
6514{
6515	uint32_t dw2 = 0;
6516
6517	if (amdgpu_sriov_vf(ring->adev))
6518		gfx_v8_0_ring_emit_ce_meta(ring);
6519
6520	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
6521	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
6522		gfx_v8_0_ring_emit_vgt_flush(ring);
6523		/* set load_global_config & load_global_uconfig */
6524		dw2 |= 0x8001;
6525		/* set load_cs_sh_regs */
6526		dw2 |= 0x01000000;
6527		/* set load_per_context_state & load_gfx_sh_regs for GFX */
6528		dw2 |= 0x10002;
6529
6530		/* set load_ce_ram if preamble presented */
6531		if (AMDGPU_PREAMBLE_IB_PRESENT & flags)
6532			dw2 |= 0x10000000;
6533	} else {
6534		/* still load_ce_ram if this is the first time preamble presented
6535		 * although there is no context switch happens.
6536		 */
6537		if (AMDGPU_PREAMBLE_IB_PRESENT_FIRST & flags)
6538			dw2 |= 0x10000000;
6539	}
6540
6541	amdgpu_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
6542	amdgpu_ring_write(ring, dw2);
6543	amdgpu_ring_write(ring, 0);
6544}
6545
6546static unsigned gfx_v8_0_ring_emit_init_cond_exec(struct amdgpu_ring *ring)
 
6547{
6548	unsigned ret;
6549
6550	amdgpu_ring_write(ring, PACKET3(PACKET3_COND_EXEC, 3));
6551	amdgpu_ring_write(ring, lower_32_bits(ring->cond_exe_gpu_addr));
6552	amdgpu_ring_write(ring, upper_32_bits(ring->cond_exe_gpu_addr));
6553	amdgpu_ring_write(ring, 0); /* discard following DWs if *cond_exec_gpu_addr==0 */
 
6554	ret = ring->wptr & ring->buf_mask;
6555	amdgpu_ring_write(ring, 0x55aa55aa); /* patch dummy value later */
 
6556	return ret;
6557}
6558
6559static void gfx_v8_0_ring_emit_patch_cond_exec(struct amdgpu_ring *ring, unsigned offset)
6560{
6561	unsigned cur;
6562
6563	BUG_ON(offset > ring->buf_mask);
6564	BUG_ON(ring->ring[offset] != 0x55aa55aa);
6565
6566	cur = (ring->wptr & ring->buf_mask) - 1;
6567	if (likely(cur > offset))
6568		ring->ring[offset] = cur - offset;
6569	else
6570		ring->ring[offset] = (ring->ring_size >> 2) - offset + cur;
6571}
6572
6573static void gfx_v8_0_ring_emit_rreg(struct amdgpu_ring *ring, uint32_t reg)
6574{
6575	struct amdgpu_device *adev = ring->adev;
6576
6577	amdgpu_ring_write(ring, PACKET3(PACKET3_COPY_DATA, 4));
6578	amdgpu_ring_write(ring, 0 |	/* src: register*/
6579				(5 << 8) |	/* dst: memory */
6580				(1 << 20));	/* write confirm */
6581	amdgpu_ring_write(ring, reg);
6582	amdgpu_ring_write(ring, 0);
6583	amdgpu_ring_write(ring, lower_32_bits(adev->wb.gpu_addr +
6584				adev->virt.reg_val_offs * 4));
6585	amdgpu_ring_write(ring, upper_32_bits(adev->wb.gpu_addr +
6586				adev->virt.reg_val_offs * 4));
6587}
6588
6589static void gfx_v8_0_ring_emit_wreg(struct amdgpu_ring *ring, uint32_t reg,
6590				  uint32_t val)
6591{
6592	uint32_t cmd;
6593
6594	switch (ring->funcs->type) {
6595	case AMDGPU_RING_TYPE_GFX:
6596		cmd = WRITE_DATA_ENGINE_SEL(1) | WR_CONFIRM;
6597		break;
6598	case AMDGPU_RING_TYPE_KIQ:
6599		cmd = 1 << 16; /* no inc addr */
6600		break;
6601	default:
6602		cmd = WR_CONFIRM;
6603		break;
6604	}
6605
6606	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
6607	amdgpu_ring_write(ring, cmd);
6608	amdgpu_ring_write(ring, reg);
6609	amdgpu_ring_write(ring, 0);
6610	amdgpu_ring_write(ring, val);
6611}
6612
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6613static void gfx_v8_0_set_gfx_eop_interrupt_state(struct amdgpu_device *adev,
6614						 enum amdgpu_interrupt_state state)
6615{
6616	WREG32_FIELD(CP_INT_CNTL_RING0, TIME_STAMP_INT_ENABLE,
6617		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6618}
6619
6620static void gfx_v8_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
6621						     int me, int pipe,
6622						     enum amdgpu_interrupt_state state)
6623{
6624	u32 mec_int_cntl, mec_int_cntl_reg;
6625
6626	/*
6627	 * amdgpu controls only the first MEC. That's why this function only
6628	 * handles the setting of interrupts for this specific MEC. All other
6629	 * pipes' interrupts are set by amdkfd.
6630	 */
6631
6632	if (me == 1) {
6633		switch (pipe) {
6634		case 0:
6635			mec_int_cntl_reg = mmCP_ME1_PIPE0_INT_CNTL;
6636			break;
6637		case 1:
6638			mec_int_cntl_reg = mmCP_ME1_PIPE1_INT_CNTL;
6639			break;
6640		case 2:
6641			mec_int_cntl_reg = mmCP_ME1_PIPE2_INT_CNTL;
6642			break;
6643		case 3:
6644			mec_int_cntl_reg = mmCP_ME1_PIPE3_INT_CNTL;
6645			break;
6646		default:
6647			DRM_DEBUG("invalid pipe %d\n", pipe);
6648			return;
6649		}
6650	} else {
6651		DRM_DEBUG("invalid me %d\n", me);
6652		return;
6653	}
6654
6655	switch (state) {
6656	case AMDGPU_IRQ_STATE_DISABLE:
6657		mec_int_cntl = RREG32(mec_int_cntl_reg);
6658		mec_int_cntl &= ~CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6659		WREG32(mec_int_cntl_reg, mec_int_cntl);
6660		break;
6661	case AMDGPU_IRQ_STATE_ENABLE:
6662		mec_int_cntl = RREG32(mec_int_cntl_reg);
6663		mec_int_cntl |= CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK;
6664		WREG32(mec_int_cntl_reg, mec_int_cntl);
6665		break;
6666	default:
6667		break;
6668	}
6669}
6670
6671static int gfx_v8_0_set_priv_reg_fault_state(struct amdgpu_device *adev,
6672					     struct amdgpu_irq_src *source,
6673					     unsigned type,
6674					     enum amdgpu_interrupt_state state)
6675{
6676	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_REG_INT_ENABLE,
6677		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6678
6679	return 0;
6680}
6681
6682static int gfx_v8_0_set_priv_inst_fault_state(struct amdgpu_device *adev,
6683					      struct amdgpu_irq_src *source,
6684					      unsigned type,
6685					      enum amdgpu_interrupt_state state)
6686{
6687	WREG32_FIELD(CP_INT_CNTL_RING0, PRIV_INSTR_INT_ENABLE,
6688		     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6689
6690	return 0;
6691}
6692
6693static int gfx_v8_0_set_eop_interrupt_state(struct amdgpu_device *adev,
6694					    struct amdgpu_irq_src *src,
6695					    unsigned type,
6696					    enum amdgpu_interrupt_state state)
6697{
6698	switch (type) {
6699	case AMDGPU_CP_IRQ_GFX_EOP:
6700		gfx_v8_0_set_gfx_eop_interrupt_state(adev, state);
6701		break;
6702	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP:
6703		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 0, state);
6704		break;
6705	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP:
6706		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 1, state);
6707		break;
6708	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP:
6709		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 2, state);
6710		break;
6711	case AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP:
6712		gfx_v8_0_set_compute_eop_interrupt_state(adev, 1, 3, state);
6713		break;
6714	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP:
6715		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 0, state);
6716		break;
6717	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP:
6718		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 1, state);
6719		break;
6720	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP:
6721		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 2, state);
6722		break;
6723	case AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP:
6724		gfx_v8_0_set_compute_eop_interrupt_state(adev, 2, 3, state);
6725		break;
6726	default:
6727		break;
6728	}
6729	return 0;
6730}
6731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6732static int gfx_v8_0_eop_irq(struct amdgpu_device *adev,
6733			    struct amdgpu_irq_src *source,
6734			    struct amdgpu_iv_entry *entry)
6735{
6736	int i;
6737	u8 me_id, pipe_id, queue_id;
6738	struct amdgpu_ring *ring;
6739
6740	DRM_DEBUG("IH: CP EOP\n");
6741	me_id = (entry->ring_id & 0x0c) >> 2;
6742	pipe_id = (entry->ring_id & 0x03) >> 0;
6743	queue_id = (entry->ring_id & 0x70) >> 4;
6744
6745	switch (me_id) {
6746	case 0:
6747		amdgpu_fence_process(&adev->gfx.gfx_ring[0]);
6748		break;
6749	case 1:
6750	case 2:
6751		for (i = 0; i < adev->gfx.num_compute_rings; i++) {
6752			ring = &adev->gfx.compute_ring[i];
6753			/* Per-queue interrupt is supported for MEC starting from VI.
6754			  * The interrupt can only be enabled/disabled per pipe instead of per queue.
6755			  */
6756			if ((ring->me == me_id) && (ring->pipe == pipe_id) && (ring->queue == queue_id))
6757				amdgpu_fence_process(ring);
6758		}
6759		break;
6760	}
6761	return 0;
6762}
6763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6764static int gfx_v8_0_priv_reg_irq(struct amdgpu_device *adev,
6765				 struct amdgpu_irq_src *source,
6766				 struct amdgpu_iv_entry *entry)
6767{
6768	DRM_ERROR("Illegal register access in command stream\n");
6769	schedule_work(&adev->reset_work);
6770	return 0;
6771}
6772
6773static int gfx_v8_0_priv_inst_irq(struct amdgpu_device *adev,
6774				  struct amdgpu_irq_src *source,
6775				  struct amdgpu_iv_entry *entry)
6776{
6777	DRM_ERROR("Illegal instruction in command stream\n");
6778	schedule_work(&adev->reset_work);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6779	return 0;
6780}
6781
6782static int gfx_v8_0_kiq_set_interrupt_state(struct amdgpu_device *adev,
6783					    struct amdgpu_irq_src *src,
6784					    unsigned int type,
6785					    enum amdgpu_interrupt_state state)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6786{
6787	struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
 
6788
6789	switch (type) {
6790	case AMDGPU_CP_KIQ_IRQ_DRIVER0:
6791		WREG32_FIELD(CPC_INT_CNTL, GENERIC2_INT_ENABLE,
6792			     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6793		if (ring->me == 1)
6794			WREG32_FIELD_OFFSET(CP_ME1_PIPE0_INT_CNTL,
6795				     ring->pipe,
6796				     GENERIC2_INT_ENABLE,
6797				     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6798		else
6799			WREG32_FIELD_OFFSET(CP_ME2_PIPE0_INT_CNTL,
6800				     ring->pipe,
6801				     GENERIC2_INT_ENABLE,
6802				     state == AMDGPU_IRQ_STATE_DISABLE ? 0 : 1);
6803		break;
6804	default:
6805		BUG(); /* kiq only support GENERIC2_INT now */
6806		break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6807	}
6808	return 0;
6809}
6810
6811static int gfx_v8_0_kiq_irq(struct amdgpu_device *adev,
6812			    struct amdgpu_irq_src *source,
6813			    struct amdgpu_iv_entry *entry)
6814{
6815	u8 me_id, pipe_id, queue_id;
6816	struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6817
6818	me_id = (entry->ring_id & 0x0c) >> 2;
6819	pipe_id = (entry->ring_id & 0x03) >> 0;
6820	queue_id = (entry->ring_id & 0x70) >> 4;
6821	DRM_DEBUG("IH: CPC GENERIC2_INT, me:%d, pipe:%d, queue:%d\n",
6822		   me_id, pipe_id, queue_id);
 
6823
6824	amdgpu_fence_process(ring);
6825	return 0;
6826}
6827
6828static const struct amd_ip_funcs gfx_v8_0_ip_funcs = {
6829	.name = "gfx_v8_0",
6830	.early_init = gfx_v8_0_early_init,
6831	.late_init = gfx_v8_0_late_init,
6832	.sw_init = gfx_v8_0_sw_init,
6833	.sw_fini = gfx_v8_0_sw_fini,
6834	.hw_init = gfx_v8_0_hw_init,
6835	.hw_fini = gfx_v8_0_hw_fini,
6836	.suspend = gfx_v8_0_suspend,
6837	.resume = gfx_v8_0_resume,
6838	.is_idle = gfx_v8_0_is_idle,
6839	.wait_for_idle = gfx_v8_0_wait_for_idle,
6840	.check_soft_reset = gfx_v8_0_check_soft_reset,
6841	.pre_soft_reset = gfx_v8_0_pre_soft_reset,
6842	.soft_reset = gfx_v8_0_soft_reset,
6843	.post_soft_reset = gfx_v8_0_post_soft_reset,
6844	.set_clockgating_state = gfx_v8_0_set_clockgating_state,
6845	.set_powergating_state = gfx_v8_0_set_powergating_state,
6846	.get_clockgating_state = gfx_v8_0_get_clockgating_state,
6847};
6848
6849static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_gfx = {
6850	.type = AMDGPU_RING_TYPE_GFX,
6851	.align_mask = 0xff,
6852	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
6853	.support_64bit_ptrs = false,
6854	.get_rptr = gfx_v8_0_ring_get_rptr,
6855	.get_wptr = gfx_v8_0_ring_get_wptr_gfx,
6856	.set_wptr = gfx_v8_0_ring_set_wptr_gfx,
6857	.emit_frame_size = /* maximum 215dw if count 16 IBs in */
6858		5 +  /* COND_EXEC */
6859		7 +  /* PIPELINE_SYNC */
6860		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 9 + /* VM_FLUSH */
6861		8 +  /* FENCE for VM_FLUSH */
6862		20 + /* GDS switch */
6863		4 + /* double SWITCH_BUFFER,
6864		       the first COND_EXEC jump to the place just
6865			   prior to this double SWITCH_BUFFER  */
6866		5 + /* COND_EXEC */
6867		7 +	 /*	HDP_flush */
6868		4 +	 /*	VGT_flush */
6869		14 + /*	CE_META */
6870		31 + /*	DE_META */
6871		3 + /* CNTX_CTRL */
6872		5 + /* HDP_INVL */
6873		8 + 8 + /* FENCE x2 */
6874		2, /* SWITCH_BUFFER */
 
6875	.emit_ib_size =	4, /* gfx_v8_0_ring_emit_ib_gfx */
6876	.emit_ib = gfx_v8_0_ring_emit_ib_gfx,
6877	.emit_fence = gfx_v8_0_ring_emit_fence_gfx,
6878	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
6879	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
6880	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
6881	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
6882	.test_ring = gfx_v8_0_ring_test_ring,
6883	.test_ib = gfx_v8_0_ring_test_ib,
6884	.insert_nop = amdgpu_ring_insert_nop,
6885	.pad_ib = amdgpu_ring_generic_pad_ib,
6886	.emit_switch_buffer = gfx_v8_ring_emit_sb,
6887	.emit_cntxcntl = gfx_v8_ring_emit_cntxcntl,
6888	.init_cond_exec = gfx_v8_0_ring_emit_init_cond_exec,
6889	.patch_cond_exec = gfx_v8_0_ring_emit_patch_cond_exec,
6890	.emit_wreg = gfx_v8_0_ring_emit_wreg,
 
 
 
6891};
6892
6893static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_compute = {
6894	.type = AMDGPU_RING_TYPE_COMPUTE,
6895	.align_mask = 0xff,
6896	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
6897	.support_64bit_ptrs = false,
6898	.get_rptr = gfx_v8_0_ring_get_rptr,
6899	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
6900	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
6901	.emit_frame_size =
6902		20 + /* gfx_v8_0_ring_emit_gds_switch */
6903		7 + /* gfx_v8_0_ring_emit_hdp_flush */
6904		5 + /* hdp_invalidate */
6905		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
6906		VI_FLUSH_GPU_TLB_NUM_WREG * 5 + 7 + /* gfx_v8_0_ring_emit_vm_flush */
6907		7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_compute x3 for user fence, vm fence */
6908	.emit_ib_size =	4, /* gfx_v8_0_ring_emit_ib_compute */
 
 
 
6909	.emit_ib = gfx_v8_0_ring_emit_ib_compute,
6910	.emit_fence = gfx_v8_0_ring_emit_fence_compute,
6911	.emit_pipeline_sync = gfx_v8_0_ring_emit_pipeline_sync,
6912	.emit_vm_flush = gfx_v8_0_ring_emit_vm_flush,
6913	.emit_gds_switch = gfx_v8_0_ring_emit_gds_switch,
6914	.emit_hdp_flush = gfx_v8_0_ring_emit_hdp_flush,
6915	.test_ring = gfx_v8_0_ring_test_ring,
6916	.test_ib = gfx_v8_0_ring_test_ib,
6917	.insert_nop = amdgpu_ring_insert_nop,
6918	.pad_ib = amdgpu_ring_generic_pad_ib,
6919	.set_priority = gfx_v8_0_ring_set_priority_compute,
6920	.emit_wreg = gfx_v8_0_ring_emit_wreg,
 
 
 
6921};
6922
6923static const struct amdgpu_ring_funcs gfx_v8_0_ring_funcs_kiq = {
6924	.type = AMDGPU_RING_TYPE_KIQ,
6925	.align_mask = 0xff,
6926	.nop = PACKET3(PACKET3_NOP, 0x3FFF),
6927	.support_64bit_ptrs = false,
6928	.get_rptr = gfx_v8_0_ring_get_rptr,
6929	.get_wptr = gfx_v8_0_ring_get_wptr_compute,
6930	.set_wptr = gfx_v8_0_ring_set_wptr_compute,
6931	.emit_frame_size =
6932		20 + /* gfx_v8_0_ring_emit_gds_switch */
6933		7 + /* gfx_v8_0_ring_emit_hdp_flush */
6934		5 + /* hdp_invalidate */
6935		7 + /* gfx_v8_0_ring_emit_pipeline_sync */
6936		17 + /* gfx_v8_0_ring_emit_vm_flush */
6937		7 + 7 + 7, /* gfx_v8_0_ring_emit_fence_kiq x3 for user fence, vm fence */
6938	.emit_ib_size =	4, /* gfx_v8_0_ring_emit_ib_compute */
6939	.emit_ib = gfx_v8_0_ring_emit_ib_compute,
6940	.emit_fence = gfx_v8_0_ring_emit_fence_kiq,
6941	.test_ring = gfx_v8_0_ring_test_ring,
6942	.test_ib = gfx_v8_0_ring_test_ib,
6943	.insert_nop = amdgpu_ring_insert_nop,
6944	.pad_ib = amdgpu_ring_generic_pad_ib,
6945	.emit_rreg = gfx_v8_0_ring_emit_rreg,
6946	.emit_wreg = gfx_v8_0_ring_emit_wreg,
6947};
6948
6949static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev)
6950{
6951	int i;
6952
6953	adev->gfx.kiq.ring.funcs = &gfx_v8_0_ring_funcs_kiq;
6954
6955	for (i = 0; i < adev->gfx.num_gfx_rings; i++)
6956		adev->gfx.gfx_ring[i].funcs = &gfx_v8_0_ring_funcs_gfx;
6957
6958	for (i = 0; i < adev->gfx.num_compute_rings; i++)
6959		adev->gfx.compute_ring[i].funcs = &gfx_v8_0_ring_funcs_compute;
6960}
6961
6962static const struct amdgpu_irq_src_funcs gfx_v8_0_eop_irq_funcs = {
6963	.set = gfx_v8_0_set_eop_interrupt_state,
6964	.process = gfx_v8_0_eop_irq,
6965};
6966
6967static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_reg_irq_funcs = {
6968	.set = gfx_v8_0_set_priv_reg_fault_state,
6969	.process = gfx_v8_0_priv_reg_irq,
6970};
6971
6972static const struct amdgpu_irq_src_funcs gfx_v8_0_priv_inst_irq_funcs = {
6973	.set = gfx_v8_0_set_priv_inst_fault_state,
6974	.process = gfx_v8_0_priv_inst_irq,
6975};
6976
6977static const struct amdgpu_irq_src_funcs gfx_v8_0_kiq_irq_funcs = {
6978	.set = gfx_v8_0_kiq_set_interrupt_state,
6979	.process = gfx_v8_0_kiq_irq,
 
 
 
 
 
6980};
6981
6982static void gfx_v8_0_set_irq_funcs(struct amdgpu_device *adev)
6983{
6984	adev->gfx.eop_irq.num_types = AMDGPU_CP_IRQ_LAST;
6985	adev->gfx.eop_irq.funcs = &gfx_v8_0_eop_irq_funcs;
6986
6987	adev->gfx.priv_reg_irq.num_types = 1;
6988	adev->gfx.priv_reg_irq.funcs = &gfx_v8_0_priv_reg_irq_funcs;
6989
6990	adev->gfx.priv_inst_irq.num_types = 1;
6991	adev->gfx.priv_inst_irq.funcs = &gfx_v8_0_priv_inst_irq_funcs;
6992
6993	adev->gfx.kiq.irq.num_types = AMDGPU_CP_KIQ_IRQ_LAST;
6994	adev->gfx.kiq.irq.funcs = &gfx_v8_0_kiq_irq_funcs;
 
 
 
6995}
6996
6997static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev)
6998{
6999	adev->gfx.rlc.funcs = &iceland_rlc_funcs;
7000}
7001
7002static void gfx_v8_0_set_gds_init(struct amdgpu_device *adev)
7003{
7004	/* init asci gds info */
7005	adev->gds.mem.total_size = RREG32(mmGDS_VMID0_SIZE);
7006	adev->gds.gws.total_size = 64;
7007	adev->gds.oa.total_size = 16;
7008
7009	if (adev->gds.mem.total_size == 64 * 1024) {
7010		adev->gds.mem.gfx_partition_size = 4096;
7011		adev->gds.mem.cs_partition_size = 4096;
7012
7013		adev->gds.gws.gfx_partition_size = 4;
7014		adev->gds.gws.cs_partition_size = 4;
7015
7016		adev->gds.oa.gfx_partition_size = 4;
7017		adev->gds.oa.cs_partition_size = 1;
7018	} else {
7019		adev->gds.mem.gfx_partition_size = 1024;
7020		adev->gds.mem.cs_partition_size = 1024;
7021
7022		adev->gds.gws.gfx_partition_size = 16;
7023		adev->gds.gws.cs_partition_size = 16;
7024
7025		adev->gds.oa.gfx_partition_size = 4;
7026		adev->gds.oa.cs_partition_size = 4;
7027	}
7028}
7029
7030static void gfx_v8_0_set_user_cu_inactive_bitmap(struct amdgpu_device *adev,
7031						 u32 bitmap)
7032{
7033	u32 data;
7034
7035	if (!bitmap)
7036		return;
7037
7038	data = bitmap << GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS__SHIFT;
7039	data &= GC_USER_SHADER_ARRAY_CONFIG__INACTIVE_CUS_MASK;
7040
7041	WREG32(mmGC_USER_SHADER_ARRAY_CONFIG, data);
7042}
7043
7044static u32 gfx_v8_0_get_cu_active_bitmap(struct amdgpu_device *adev)
7045{
7046	u32 data, mask;
7047
7048	data =  RREG32(mmCC_GC_SHADER_ARRAY_CONFIG) |
7049		RREG32(mmGC_USER_SHADER_ARRAY_CONFIG);
7050
7051	mask = amdgpu_gfx_create_bitmask(adev->gfx.config.max_cu_per_sh);
7052
7053	return ~REG_GET_FIELD(data, CC_GC_SHADER_ARRAY_CONFIG, INACTIVE_CUS) & mask;
7054}
7055
7056static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
7057{
7058	int i, j, k, counter, active_cu_number = 0;
7059	u32 mask, bitmap, ao_bitmap, ao_cu_mask = 0;
7060	struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info;
7061	unsigned disable_masks[4 * 2];
7062	u32 ao_cu_num;
7063
7064	memset(cu_info, 0, sizeof(*cu_info));
7065
7066	if (adev->flags & AMD_IS_APU)
7067		ao_cu_num = 2;
7068	else
7069		ao_cu_num = adev->gfx.config.max_cu_per_sh;
7070
7071	amdgpu_gfx_parse_disable_cu(disable_masks, 4, 2);
7072
7073	mutex_lock(&adev->grbm_idx_mutex);
7074	for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
7075		for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
7076			mask = 1;
7077			ao_bitmap = 0;
7078			counter = 0;
7079			gfx_v8_0_select_se_sh(adev, i, j, 0xffffffff);
7080			if (i < 4 && j < 2)
7081				gfx_v8_0_set_user_cu_inactive_bitmap(
7082					adev, disable_masks[i * 2 + j]);
7083			bitmap = gfx_v8_0_get_cu_active_bitmap(adev);
7084			cu_info->bitmap[i][j] = bitmap;
7085
7086			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
7087				if (bitmap & mask) {
7088					if (counter < ao_cu_num)
7089						ao_bitmap |= mask;
7090					counter ++;
7091				}
7092				mask <<= 1;
7093			}
7094			active_cu_number += counter;
7095			if (i < 2 && j < 2)
7096				ao_cu_mask |= (ao_bitmap << (i * 16 + j * 8));
7097			cu_info->ao_cu_bitmap[i][j] = ao_bitmap;
7098		}
7099	}
7100	gfx_v8_0_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
7101	mutex_unlock(&adev->grbm_idx_mutex);
7102
7103	cu_info->number = active_cu_number;
7104	cu_info->ao_cu_mask = ao_cu_mask;
7105	cu_info->simd_per_cu = NUM_SIMD_PER_CU;
7106	cu_info->max_waves_per_simd = 10;
7107	cu_info->max_scratch_slots_per_cu = 32;
7108	cu_info->wave_front_size = 64;
7109	cu_info->lds_size = 64;
7110}
7111
7112const struct amdgpu_ip_block_version gfx_v8_0_ip_block =
7113{
7114	.type = AMD_IP_BLOCK_TYPE_GFX,
7115	.major = 8,
7116	.minor = 0,
7117	.rev = 0,
7118	.funcs = &gfx_v8_0_ip_funcs,
7119};
7120
7121const struct amdgpu_ip_block_version gfx_v8_1_ip_block =
7122{
7123	.type = AMD_IP_BLOCK_TYPE_GFX,
7124	.major = 8,
7125	.minor = 1,
7126	.rev = 0,
7127	.funcs = &gfx_v8_0_ip_funcs,
7128};
7129
7130static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
7131{
7132	uint64_t ce_payload_addr;
7133	int cnt_ce;
7134	union {
7135		struct vi_ce_ib_state regular;
7136		struct vi_ce_ib_state_chained_ib chained;
7137	} ce_payload = {};
7138
7139	if (ring->adev->virt.chained_ib_support) {
7140		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
7141			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
7142		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
7143	} else {
7144		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
7145			offsetof(struct vi_gfx_meta_data, ce_payload);
7146		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
7147	}
7148
7149	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_ce));
7150	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
7151				WRITE_DATA_DST_SEL(8) |
7152				WR_CONFIRM) |
7153				WRITE_DATA_CACHE_POLICY(0));
7154	amdgpu_ring_write(ring, lower_32_bits(ce_payload_addr));
7155	amdgpu_ring_write(ring, upper_32_bits(ce_payload_addr));
7156	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
7157}
7158
7159static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
7160{
7161	uint64_t de_payload_addr, gds_addr, csa_addr;
7162	int cnt_de;
7163	union {
7164		struct vi_de_ib_state regular;
7165		struct vi_de_ib_state_chained_ib chained;
7166	} de_payload = {};
7167
7168	csa_addr = amdgpu_csa_vaddr(ring->adev);
7169	gds_addr = csa_addr + 4096;
7170	if (ring->adev->virt.chained_ib_support) {
7171		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
7172		de_payload.chained.gds_backup_addrhi = upper_32_bits(gds_addr);
7173		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data_chained_ib, de_payload);
7174		cnt_de = (sizeof(de_payload.chained) >> 2) + 4 - 2;
7175	} else {
7176		de_payload.regular.gds_backup_addrlo = lower_32_bits(gds_addr);
7177		de_payload.regular.gds_backup_addrhi = upper_32_bits(gds_addr);
7178		de_payload_addr = csa_addr + offsetof(struct vi_gfx_meta_data, de_payload);
7179		cnt_de = (sizeof(de_payload.regular) >> 2) + 4 - 2;
7180	}
7181
7182	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt_de));
7183	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(1) |
7184				WRITE_DATA_DST_SEL(8) |
7185				WR_CONFIRM) |
7186				WRITE_DATA_CACHE_POLICY(0));
7187	amdgpu_ring_write(ring, lower_32_bits(de_payload_addr));
7188	amdgpu_ring_write(ring, upper_32_bits(de_payload_addr));
7189	amdgpu_ring_write_multiple(ring, (void *)&de_payload, cnt_de - 2);
7190}