Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 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 | */ |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 23 | #include <linux/slab.h> |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 24 | #include "drmP.h" |
| 25 | #include "amdgpu.h" |
| 26 | #include "amdgpu_atombios.h" |
| 27 | #include "amdgpu_ih.h" |
| 28 | #include "amdgpu_uvd.h" |
| 29 | #include "amdgpu_vce.h" |
| 30 | #include "amdgpu_ucode.h" |
| 31 | #include "atom.h" |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 32 | #include "amd_pcie.h" |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 33 | |
| 34 | #include "gmc/gmc_8_1_d.h" |
| 35 | #include "gmc/gmc_8_1_sh_mask.h" |
| 36 | |
| 37 | #include "oss/oss_3_0_d.h" |
| 38 | #include "oss/oss_3_0_sh_mask.h" |
| 39 | |
| 40 | #include "bif/bif_5_0_d.h" |
| 41 | #include "bif/bif_5_0_sh_mask.h" |
| 42 | |
| 43 | #include "gca/gfx_8_0_d.h" |
| 44 | #include "gca/gfx_8_0_sh_mask.h" |
| 45 | |
| 46 | #include "smu/smu_7_1_1_d.h" |
| 47 | #include "smu/smu_7_1_1_sh_mask.h" |
| 48 | |
| 49 | #include "uvd/uvd_5_0_d.h" |
| 50 | #include "uvd/uvd_5_0_sh_mask.h" |
| 51 | |
| 52 | #include "vce/vce_3_0_d.h" |
| 53 | #include "vce/vce_3_0_sh_mask.h" |
| 54 | |
| 55 | #include "dce/dce_10_0_d.h" |
| 56 | #include "dce/dce_10_0_sh_mask.h" |
| 57 | |
| 58 | #include "vid.h" |
| 59 | #include "vi.h" |
| 60 | #include "vi_dpm.h" |
| 61 | #include "gmc_v8_0.h" |
Ken Wang | 429c45d | 2016-02-03 19:16:54 +0800 | [diff] [blame] | 62 | #include "gmc_v7_0.h" |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 63 | #include "gfx_v8_0.h" |
| 64 | #include "sdma_v2_4.h" |
| 65 | #include "sdma_v3_0.h" |
| 66 | #include "dce_v10_0.h" |
| 67 | #include "dce_v11_0.h" |
| 68 | #include "iceland_ih.h" |
| 69 | #include "tonga_ih.h" |
| 70 | #include "cz_ih.h" |
| 71 | #include "uvd_v5_0.h" |
| 72 | #include "uvd_v6_0.h" |
| 73 | #include "vce_v3_0.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 74 | #include "amdgpu_powerplay.h" |
Maruthi Bayyavarapu | a8fe58c | 2015-09-22 17:05:20 -0400 | [diff] [blame] | 75 | #if defined(CONFIG_DRM_AMD_ACP) |
| 76 | #include "amdgpu_acp.h" |
| 77 | #endif |
Emily Deng | e9ed3a6 | 2016-08-08 11:36:45 +0800 | [diff] [blame] | 78 | #include "dce_virtual.h" |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Indirect registers accessor |
| 82 | */ |
| 83 | static u32 vi_pcie_rreg(struct amdgpu_device *adev, u32 reg) |
| 84 | { |
| 85 | unsigned long flags; |
| 86 | u32 r; |
| 87 | |
| 88 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 89 | WREG32(mmPCIE_INDEX, reg); |
| 90 | (void)RREG32(mmPCIE_INDEX); |
| 91 | r = RREG32(mmPCIE_DATA); |
| 92 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 93 | return r; |
| 94 | } |
| 95 | |
| 96 | static void vi_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 97 | { |
| 98 | unsigned long flags; |
| 99 | |
| 100 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 101 | WREG32(mmPCIE_INDEX, reg); |
| 102 | (void)RREG32(mmPCIE_INDEX); |
| 103 | WREG32(mmPCIE_DATA, v); |
| 104 | (void)RREG32(mmPCIE_DATA); |
| 105 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 106 | } |
| 107 | |
| 108 | static u32 vi_smc_rreg(struct amdgpu_device *adev, u32 reg) |
| 109 | { |
| 110 | unsigned long flags; |
| 111 | u32 r; |
| 112 | |
| 113 | spin_lock_irqsave(&adev->smc_idx_lock, flags); |
Monk Liu | 4bc10d1 | 2016-03-29 11:01:51 +0800 | [diff] [blame] | 114 | WREG32(mmSMC_IND_INDEX_11, (reg)); |
| 115 | r = RREG32(mmSMC_IND_DATA_11); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 116 | spin_unlock_irqrestore(&adev->smc_idx_lock, flags); |
| 117 | return r; |
| 118 | } |
| 119 | |
| 120 | static void vi_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 121 | { |
| 122 | unsigned long flags; |
| 123 | |
| 124 | spin_lock_irqsave(&adev->smc_idx_lock, flags); |
Monk Liu | 4bc10d1 | 2016-03-29 11:01:51 +0800 | [diff] [blame] | 125 | WREG32(mmSMC_IND_INDEX_11, (reg)); |
| 126 | WREG32(mmSMC_IND_DATA_11, (v)); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 127 | spin_unlock_irqrestore(&adev->smc_idx_lock, flags); |
| 128 | } |
| 129 | |
Alex Deucher | 7b92cdb | 2015-07-10 16:21:10 -0400 | [diff] [blame] | 130 | /* smu_8_0_d.h */ |
| 131 | #define mmMP0PUB_IND_INDEX 0x180 |
| 132 | #define mmMP0PUB_IND_DATA 0x181 |
| 133 | |
| 134 | static u32 cz_smc_rreg(struct amdgpu_device *adev, u32 reg) |
| 135 | { |
| 136 | unsigned long flags; |
| 137 | u32 r; |
| 138 | |
| 139 | spin_lock_irqsave(&adev->smc_idx_lock, flags); |
| 140 | WREG32(mmMP0PUB_IND_INDEX, (reg)); |
| 141 | r = RREG32(mmMP0PUB_IND_DATA); |
| 142 | spin_unlock_irqrestore(&adev->smc_idx_lock, flags); |
| 143 | return r; |
| 144 | } |
| 145 | |
| 146 | static void cz_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 147 | { |
| 148 | unsigned long flags; |
| 149 | |
| 150 | spin_lock_irqsave(&adev->smc_idx_lock, flags); |
| 151 | WREG32(mmMP0PUB_IND_INDEX, (reg)); |
| 152 | WREG32(mmMP0PUB_IND_DATA, (v)); |
| 153 | spin_unlock_irqrestore(&adev->smc_idx_lock, flags); |
| 154 | } |
| 155 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 156 | static u32 vi_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg) |
| 157 | { |
| 158 | unsigned long flags; |
| 159 | u32 r; |
| 160 | |
| 161 | spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags); |
| 162 | WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff)); |
| 163 | r = RREG32(mmUVD_CTX_DATA); |
| 164 | spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags); |
| 165 | return r; |
| 166 | } |
| 167 | |
| 168 | static void vi_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 169 | { |
| 170 | unsigned long flags; |
| 171 | |
| 172 | spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags); |
| 173 | WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff)); |
| 174 | WREG32(mmUVD_CTX_DATA, (v)); |
| 175 | spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags); |
| 176 | } |
| 177 | |
| 178 | static u32 vi_didt_rreg(struct amdgpu_device *adev, u32 reg) |
| 179 | { |
| 180 | unsigned long flags; |
| 181 | u32 r; |
| 182 | |
| 183 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 184 | WREG32(mmDIDT_IND_INDEX, (reg)); |
| 185 | r = RREG32(mmDIDT_IND_DATA); |
| 186 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 187 | return r; |
| 188 | } |
| 189 | |
| 190 | static void vi_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 191 | { |
| 192 | unsigned long flags; |
| 193 | |
| 194 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 195 | WREG32(mmDIDT_IND_INDEX, (reg)); |
| 196 | WREG32(mmDIDT_IND_DATA, (v)); |
| 197 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 198 | } |
| 199 | |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 200 | static u32 vi_gc_cac_rreg(struct amdgpu_device *adev, u32 reg) |
| 201 | { |
| 202 | unsigned long flags; |
| 203 | u32 r; |
| 204 | |
| 205 | spin_lock_irqsave(&adev->gc_cac_idx_lock, flags); |
| 206 | WREG32(mmGC_CAC_IND_INDEX, (reg)); |
| 207 | r = RREG32(mmGC_CAC_IND_DATA); |
| 208 | spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags); |
| 209 | return r; |
| 210 | } |
| 211 | |
| 212 | static void vi_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 213 | { |
| 214 | unsigned long flags; |
| 215 | |
| 216 | spin_lock_irqsave(&adev->gc_cac_idx_lock, flags); |
| 217 | WREG32(mmGC_CAC_IND_INDEX, (reg)); |
| 218 | WREG32(mmGC_CAC_IND_DATA, (v)); |
| 219 | spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags); |
| 220 | } |
| 221 | |
| 222 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 223 | static const u32 tonga_mgcg_cgcg_init[] = |
| 224 | { |
| 225 | mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100, |
| 226 | mmPCIE_INDEX, 0xffffffff, 0x0140001c, |
| 227 | mmPCIE_DATA, 0x000f0000, 0x00000000, |
| 228 | mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C, |
| 229 | mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 230 | mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100, |
| 231 | mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, |
| 232 | }; |
| 233 | |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 234 | static const u32 fiji_mgcg_cgcg_init[] = |
| 235 | { |
| 236 | mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100, |
| 237 | mmPCIE_INDEX, 0xffffffff, 0x0140001c, |
| 238 | mmPCIE_DATA, 0x000f0000, 0x00000000, |
| 239 | mmSMC_IND_INDEX_4, 0xffffffff, 0xC060000C, |
| 240 | mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100, |
| 241 | mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100, |
| 242 | mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, |
| 243 | }; |
| 244 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 245 | static const u32 iceland_mgcg_cgcg_init[] = |
| 246 | { |
| 247 | mmPCIE_INDEX, 0xffffffff, ixPCIE_CNTL2, |
| 248 | mmPCIE_DATA, 0x000f0000, 0x00000000, |
| 249 | mmSMC_IND_INDEX_4, 0xffffffff, ixCGTT_ROM_CLK_CTRL0, |
| 250 | mmSMC_IND_DATA_4, 0xc0000fff, 0x00000100, |
| 251 | mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, |
| 252 | }; |
| 253 | |
| 254 | static const u32 cz_mgcg_cgcg_init[] = |
| 255 | { |
| 256 | mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00600100, |
| 257 | mmPCIE_INDEX, 0xffffffff, 0x0140001c, |
| 258 | mmPCIE_DATA, 0x000f0000, 0x00000000, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 259 | mmCGTT_DRM_CLK_CTRL0, 0xff000fff, 0x00000100, |
| 260 | mmHDP_XDP_CGTT_BLK_CTRL, 0xc0000fff, 0x00000104, |
| 261 | }; |
| 262 | |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 263 | static const u32 stoney_mgcg_cgcg_init[] = |
| 264 | { |
| 265 | mmCGTT_DRM_CLK_CTRL0, 0xffffffff, 0x00000100, |
| 266 | mmHDP_XDP_CGTT_BLK_CTRL, 0xffffffff, 0x00000104, |
| 267 | mmHDP_HOST_PATH_CNTL, 0xffffffff, 0x0f000027, |
| 268 | }; |
| 269 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 270 | static void vi_init_golden_registers(struct amdgpu_device *adev) |
| 271 | { |
| 272 | /* Some of the registers might be dependent on GRBM_GFX_INDEX */ |
| 273 | mutex_lock(&adev->grbm_idx_mutex); |
| 274 | |
| 275 | switch (adev->asic_type) { |
| 276 | case CHIP_TOPAZ: |
| 277 | amdgpu_program_register_sequence(adev, |
| 278 | iceland_mgcg_cgcg_init, |
| 279 | (const u32)ARRAY_SIZE(iceland_mgcg_cgcg_init)); |
| 280 | break; |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 281 | case CHIP_FIJI: |
| 282 | amdgpu_program_register_sequence(adev, |
| 283 | fiji_mgcg_cgcg_init, |
| 284 | (const u32)ARRAY_SIZE(fiji_mgcg_cgcg_init)); |
| 285 | break; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 286 | case CHIP_TONGA: |
| 287 | amdgpu_program_register_sequence(adev, |
| 288 | tonga_mgcg_cgcg_init, |
| 289 | (const u32)ARRAY_SIZE(tonga_mgcg_cgcg_init)); |
| 290 | break; |
| 291 | case CHIP_CARRIZO: |
| 292 | amdgpu_program_register_sequence(adev, |
| 293 | cz_mgcg_cgcg_init, |
| 294 | (const u32)ARRAY_SIZE(cz_mgcg_cgcg_init)); |
| 295 | break; |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 296 | case CHIP_STONEY: |
| 297 | amdgpu_program_register_sequence(adev, |
| 298 | stoney_mgcg_cgcg_init, |
| 299 | (const u32)ARRAY_SIZE(stoney_mgcg_cgcg_init)); |
| 300 | break; |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 301 | case CHIP_POLARIS11: |
| 302 | case CHIP_POLARIS10: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 303 | case CHIP_POLARIS12: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 304 | default: |
| 305 | break; |
| 306 | } |
| 307 | mutex_unlock(&adev->grbm_idx_mutex); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * vi_get_xclk - get the xclk |
| 312 | * |
| 313 | * @adev: amdgpu_device pointer |
| 314 | * |
| 315 | * Returns the reference clock used by the gfx engine |
| 316 | * (VI). |
| 317 | */ |
| 318 | static u32 vi_get_xclk(struct amdgpu_device *adev) |
| 319 | { |
| 320 | u32 reference_clock = adev->clock.spll.reference_freq; |
| 321 | u32 tmp; |
| 322 | |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 323 | if (adev->flags & AMD_IS_APU) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 324 | return reference_clock; |
| 325 | |
| 326 | tmp = RREG32_SMC(ixCG_CLKPIN_CNTL_2); |
| 327 | if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL_2, MUX_TCLK_TO_XCLK)) |
| 328 | return 1000; |
| 329 | |
| 330 | tmp = RREG32_SMC(ixCG_CLKPIN_CNTL); |
| 331 | if (REG_GET_FIELD(tmp, CG_CLKPIN_CNTL, XTALIN_DIVIDE)) |
| 332 | return reference_clock / 4; |
| 333 | |
| 334 | return reference_clock; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * vi_srbm_select - select specific register instances |
| 339 | * |
| 340 | * @adev: amdgpu_device pointer |
| 341 | * @me: selected ME (micro engine) |
| 342 | * @pipe: pipe |
| 343 | * @queue: queue |
| 344 | * @vmid: VMID |
| 345 | * |
| 346 | * Switches the currently active registers instances. Some |
| 347 | * registers are instanced per VMID, others are instanced per |
| 348 | * me/pipe/queue combination. |
| 349 | */ |
| 350 | void vi_srbm_select(struct amdgpu_device *adev, |
| 351 | u32 me, u32 pipe, u32 queue, u32 vmid) |
| 352 | { |
| 353 | u32 srbm_gfx_cntl = 0; |
| 354 | srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, PIPEID, pipe); |
| 355 | srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, MEID, me); |
| 356 | srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, VMID, vmid); |
| 357 | srbm_gfx_cntl = REG_SET_FIELD(srbm_gfx_cntl, SRBM_GFX_CNTL, QUEUEID, queue); |
| 358 | WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl); |
| 359 | } |
| 360 | |
| 361 | static void vi_vga_set_state(struct amdgpu_device *adev, bool state) |
| 362 | { |
| 363 | /* todo */ |
| 364 | } |
| 365 | |
| 366 | static bool vi_read_disabled_bios(struct amdgpu_device *adev) |
| 367 | { |
| 368 | u32 bus_cntl; |
| 369 | u32 d1vga_control = 0; |
| 370 | u32 d2vga_control = 0; |
| 371 | u32 vga_render_control = 0; |
| 372 | u32 rom_cntl; |
| 373 | bool r; |
| 374 | |
| 375 | bus_cntl = RREG32(mmBUS_CNTL); |
| 376 | if (adev->mode_info.num_crtc) { |
| 377 | d1vga_control = RREG32(mmD1VGA_CONTROL); |
| 378 | d2vga_control = RREG32(mmD2VGA_CONTROL); |
| 379 | vga_render_control = RREG32(mmVGA_RENDER_CONTROL); |
| 380 | } |
| 381 | rom_cntl = RREG32_SMC(ixROM_CNTL); |
| 382 | |
| 383 | /* enable the rom */ |
| 384 | WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK)); |
| 385 | if (adev->mode_info.num_crtc) { |
| 386 | /* Disable VGA mode */ |
| 387 | WREG32(mmD1VGA_CONTROL, |
| 388 | (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK | |
| 389 | D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK))); |
| 390 | WREG32(mmD2VGA_CONTROL, |
| 391 | (d2vga_control & ~(D2VGA_CONTROL__D2VGA_MODE_ENABLE_MASK | |
| 392 | D2VGA_CONTROL__D2VGA_TIMING_SELECT_MASK))); |
| 393 | WREG32(mmVGA_RENDER_CONTROL, |
| 394 | (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK)); |
| 395 | } |
| 396 | WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK); |
| 397 | |
| 398 | r = amdgpu_read_bios(adev); |
| 399 | |
| 400 | /* restore regs */ |
| 401 | WREG32(mmBUS_CNTL, bus_cntl); |
| 402 | if (adev->mode_info.num_crtc) { |
| 403 | WREG32(mmD1VGA_CONTROL, d1vga_control); |
| 404 | WREG32(mmD2VGA_CONTROL, d2vga_control); |
| 405 | WREG32(mmVGA_RENDER_CONTROL, vga_render_control); |
| 406 | } |
| 407 | WREG32_SMC(ixROM_CNTL, rom_cntl); |
| 408 | return r; |
| 409 | } |
Alex Deucher | 95addb2a | 2015-11-24 10:37:54 -0500 | [diff] [blame] | 410 | |
| 411 | static bool vi_read_bios_from_rom(struct amdgpu_device *adev, |
| 412 | u8 *bios, u32 length_bytes) |
| 413 | { |
| 414 | u32 *dw_ptr; |
| 415 | unsigned long flags; |
| 416 | u32 i, length_dw; |
| 417 | |
| 418 | if (bios == NULL) |
| 419 | return false; |
| 420 | if (length_bytes == 0) |
| 421 | return false; |
| 422 | /* APU vbios image is part of sbios image */ |
| 423 | if (adev->flags & AMD_IS_APU) |
| 424 | return false; |
| 425 | |
| 426 | dw_ptr = (u32 *)bios; |
| 427 | length_dw = ALIGN(length_bytes, 4) / 4; |
| 428 | /* take the smc lock since we are using the smc index */ |
| 429 | spin_lock_irqsave(&adev->smc_idx_lock, flags); |
| 430 | /* set rom index to 0 */ |
Monk Liu | 4bc10d1 | 2016-03-29 11:01:51 +0800 | [diff] [blame] | 431 | WREG32(mmSMC_IND_INDEX_11, ixROM_INDEX); |
| 432 | WREG32(mmSMC_IND_DATA_11, 0); |
Alex Deucher | 95addb2a | 2015-11-24 10:37:54 -0500 | [diff] [blame] | 433 | /* set index to data for continous read */ |
Monk Liu | 4bc10d1 | 2016-03-29 11:01:51 +0800 | [diff] [blame] | 434 | WREG32(mmSMC_IND_INDEX_11, ixROM_DATA); |
Alex Deucher | 95addb2a | 2015-11-24 10:37:54 -0500 | [diff] [blame] | 435 | for (i = 0; i < length_dw; i++) |
Monk Liu | 4bc10d1 | 2016-03-29 11:01:51 +0800 | [diff] [blame] | 436 | dw_ptr[i] = RREG32(mmSMC_IND_DATA_11); |
Alex Deucher | 95addb2a | 2015-11-24 10:37:54 -0500 | [diff] [blame] | 437 | spin_unlock_irqrestore(&adev->smc_idx_lock, flags); |
| 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 442 | static void vi_detect_hw_virtualization(struct amdgpu_device *adev) |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 443 | { |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 444 | uint32_t reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER); |
| 445 | /* bit0: 0 means pf and 1 means vf */ |
| 446 | /* bit31: 0 means disable IOV and 1 means enable */ |
| 447 | if (reg & 1) |
Xiangliang Yu | 5a5099c | 2017-01-09 18:06:57 -0500 | [diff] [blame] | 448 | adev->virt.caps |= AMDGPU_SRIOV_CAPS_IS_VF; |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 449 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 450 | if (reg & 0x80000000) |
Xiangliang Yu | 5a5099c | 2017-01-09 18:06:57 -0500 | [diff] [blame] | 451 | adev->virt.caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV; |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 452 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 453 | if (reg == 0) { |
| 454 | if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */ |
Xiangliang Yu | 5a5099c | 2017-01-09 18:06:57 -0500 | [diff] [blame] | 455 | adev->virt.caps |= AMDGPU_PASSTHROUGH_MODE; |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 456 | } |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 457 | } |
| 458 | |
Nils Wallménius | eca2240 | 2016-03-19 16:12:17 +0100 | [diff] [blame] | 459 | static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 460 | {mmGB_MACROTILE_MODE7, true}, |
| 461 | }; |
| 462 | |
Nils Wallménius | eca2240 | 2016-03-19 16:12:17 +0100 | [diff] [blame] | 463 | static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 464 | {mmGB_TILE_MODE7, true}, |
| 465 | {mmGB_TILE_MODE12, true}, |
| 466 | {mmGB_TILE_MODE17, true}, |
| 467 | {mmGB_TILE_MODE23, true}, |
| 468 | {mmGB_MACROTILE_MODE7, true}, |
| 469 | }; |
| 470 | |
Nils Wallménius | eca2240 | 2016-03-19 16:12:17 +0100 | [diff] [blame] | 471 | static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 472 | {mmGRBM_STATUS, false}, |
Marek Olšák | c7890fe | 2015-07-11 12:08:46 +0200 | [diff] [blame] | 473 | {mmGRBM_STATUS2, false}, |
| 474 | {mmGRBM_STATUS_SE0, false}, |
| 475 | {mmGRBM_STATUS_SE1, false}, |
| 476 | {mmGRBM_STATUS_SE2, false}, |
| 477 | {mmGRBM_STATUS_SE3, false}, |
| 478 | {mmSRBM_STATUS, false}, |
| 479 | {mmSRBM_STATUS2, false}, |
| 480 | {mmSRBM_STATUS3, false}, |
| 481 | {mmSDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET, false}, |
| 482 | {mmSDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET, false}, |
| 483 | {mmCP_STAT, false}, |
| 484 | {mmCP_STALLED_STAT1, false}, |
| 485 | {mmCP_STALLED_STAT2, false}, |
| 486 | {mmCP_STALLED_STAT3, false}, |
| 487 | {mmCP_CPF_BUSY_STAT, false}, |
| 488 | {mmCP_CPF_STALLED_STAT1, false}, |
| 489 | {mmCP_CPF_STATUS, false}, |
| 490 | {mmCP_CPC_BUSY_STAT, false}, |
| 491 | {mmCP_CPC_STALLED_STAT1, false}, |
| 492 | {mmCP_CPC_STATUS, false}, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 493 | {mmGB_ADDR_CONFIG, false}, |
| 494 | {mmMC_ARB_RAMCFG, false}, |
| 495 | {mmGB_TILE_MODE0, false}, |
| 496 | {mmGB_TILE_MODE1, false}, |
| 497 | {mmGB_TILE_MODE2, false}, |
| 498 | {mmGB_TILE_MODE3, false}, |
| 499 | {mmGB_TILE_MODE4, false}, |
| 500 | {mmGB_TILE_MODE5, false}, |
| 501 | {mmGB_TILE_MODE6, false}, |
| 502 | {mmGB_TILE_MODE7, false}, |
| 503 | {mmGB_TILE_MODE8, false}, |
| 504 | {mmGB_TILE_MODE9, false}, |
| 505 | {mmGB_TILE_MODE10, false}, |
| 506 | {mmGB_TILE_MODE11, false}, |
| 507 | {mmGB_TILE_MODE12, false}, |
| 508 | {mmGB_TILE_MODE13, false}, |
| 509 | {mmGB_TILE_MODE14, false}, |
| 510 | {mmGB_TILE_MODE15, false}, |
| 511 | {mmGB_TILE_MODE16, false}, |
| 512 | {mmGB_TILE_MODE17, false}, |
| 513 | {mmGB_TILE_MODE18, false}, |
| 514 | {mmGB_TILE_MODE19, false}, |
| 515 | {mmGB_TILE_MODE20, false}, |
| 516 | {mmGB_TILE_MODE21, false}, |
| 517 | {mmGB_TILE_MODE22, false}, |
| 518 | {mmGB_TILE_MODE23, false}, |
| 519 | {mmGB_TILE_MODE24, false}, |
| 520 | {mmGB_TILE_MODE25, false}, |
| 521 | {mmGB_TILE_MODE26, false}, |
| 522 | {mmGB_TILE_MODE27, false}, |
| 523 | {mmGB_TILE_MODE28, false}, |
| 524 | {mmGB_TILE_MODE29, false}, |
| 525 | {mmGB_TILE_MODE30, false}, |
| 526 | {mmGB_TILE_MODE31, false}, |
| 527 | {mmGB_MACROTILE_MODE0, false}, |
| 528 | {mmGB_MACROTILE_MODE1, false}, |
| 529 | {mmGB_MACROTILE_MODE2, false}, |
| 530 | {mmGB_MACROTILE_MODE3, false}, |
| 531 | {mmGB_MACROTILE_MODE4, false}, |
| 532 | {mmGB_MACROTILE_MODE5, false}, |
| 533 | {mmGB_MACROTILE_MODE6, false}, |
| 534 | {mmGB_MACROTILE_MODE7, false}, |
| 535 | {mmGB_MACROTILE_MODE8, false}, |
| 536 | {mmGB_MACROTILE_MODE9, false}, |
| 537 | {mmGB_MACROTILE_MODE10, false}, |
| 538 | {mmGB_MACROTILE_MODE11, false}, |
| 539 | {mmGB_MACROTILE_MODE12, false}, |
| 540 | {mmGB_MACROTILE_MODE13, false}, |
| 541 | {mmGB_MACROTILE_MODE14, false}, |
| 542 | {mmGB_MACROTILE_MODE15, false}, |
| 543 | {mmCC_RB_BACKEND_DISABLE, false, true}, |
| 544 | {mmGC_USER_RB_BACKEND_DISABLE, false, true}, |
| 545 | {mmGB_BACKEND_MAP, false, false}, |
| 546 | {mmPA_SC_RASTER_CONFIG, false, true}, |
| 547 | {mmPA_SC_RASTER_CONFIG_1, false, true}, |
| 548 | }; |
| 549 | |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 550 | static uint32_t vi_get_register_value(struct amdgpu_device *adev, |
| 551 | bool indexed, u32 se_num, |
| 552 | u32 sh_num, u32 reg_offset) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 553 | { |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 554 | if (indexed) { |
| 555 | uint32_t val; |
| 556 | unsigned se_idx = (se_num == 0xffffffff) ? 0 : se_num; |
| 557 | unsigned sh_idx = (sh_num == 0xffffffff) ? 0 : sh_num; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 558 | |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 559 | switch (reg_offset) { |
| 560 | case mmCC_RB_BACKEND_DISABLE: |
| 561 | return adev->gfx.config.rb_config[se_idx][sh_idx].rb_backend_disable; |
| 562 | case mmGC_USER_RB_BACKEND_DISABLE: |
| 563 | return adev->gfx.config.rb_config[se_idx][sh_idx].user_rb_backend_disable; |
| 564 | case mmPA_SC_RASTER_CONFIG: |
| 565 | return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config; |
| 566 | case mmPA_SC_RASTER_CONFIG_1: |
| 567 | return adev->gfx.config.rb_config[se_idx][sh_idx].raster_config_1; |
| 568 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 569 | |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 570 | mutex_lock(&adev->grbm_idx_mutex); |
| 571 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 572 | amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 573 | |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 574 | val = RREG32(reg_offset); |
| 575 | |
| 576 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 577 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 578 | mutex_unlock(&adev->grbm_idx_mutex); |
| 579 | return val; |
| 580 | } else { |
| 581 | unsigned idx; |
| 582 | |
| 583 | switch (reg_offset) { |
| 584 | case mmGB_ADDR_CONFIG: |
| 585 | return adev->gfx.config.gb_addr_config; |
| 586 | case mmMC_ARB_RAMCFG: |
| 587 | return adev->gfx.config.mc_arb_ramcfg; |
| 588 | case mmGB_TILE_MODE0: |
| 589 | case mmGB_TILE_MODE1: |
| 590 | case mmGB_TILE_MODE2: |
| 591 | case mmGB_TILE_MODE3: |
| 592 | case mmGB_TILE_MODE4: |
| 593 | case mmGB_TILE_MODE5: |
| 594 | case mmGB_TILE_MODE6: |
| 595 | case mmGB_TILE_MODE7: |
| 596 | case mmGB_TILE_MODE8: |
| 597 | case mmGB_TILE_MODE9: |
| 598 | case mmGB_TILE_MODE10: |
| 599 | case mmGB_TILE_MODE11: |
| 600 | case mmGB_TILE_MODE12: |
| 601 | case mmGB_TILE_MODE13: |
| 602 | case mmGB_TILE_MODE14: |
| 603 | case mmGB_TILE_MODE15: |
| 604 | case mmGB_TILE_MODE16: |
| 605 | case mmGB_TILE_MODE17: |
| 606 | case mmGB_TILE_MODE18: |
| 607 | case mmGB_TILE_MODE19: |
| 608 | case mmGB_TILE_MODE20: |
| 609 | case mmGB_TILE_MODE21: |
| 610 | case mmGB_TILE_MODE22: |
| 611 | case mmGB_TILE_MODE23: |
| 612 | case mmGB_TILE_MODE24: |
| 613 | case mmGB_TILE_MODE25: |
| 614 | case mmGB_TILE_MODE26: |
| 615 | case mmGB_TILE_MODE27: |
| 616 | case mmGB_TILE_MODE28: |
| 617 | case mmGB_TILE_MODE29: |
| 618 | case mmGB_TILE_MODE30: |
| 619 | case mmGB_TILE_MODE31: |
| 620 | idx = (reg_offset - mmGB_TILE_MODE0); |
| 621 | return adev->gfx.config.tile_mode_array[idx]; |
| 622 | case mmGB_MACROTILE_MODE0: |
| 623 | case mmGB_MACROTILE_MODE1: |
| 624 | case mmGB_MACROTILE_MODE2: |
| 625 | case mmGB_MACROTILE_MODE3: |
| 626 | case mmGB_MACROTILE_MODE4: |
| 627 | case mmGB_MACROTILE_MODE5: |
| 628 | case mmGB_MACROTILE_MODE6: |
| 629 | case mmGB_MACROTILE_MODE7: |
| 630 | case mmGB_MACROTILE_MODE8: |
| 631 | case mmGB_MACROTILE_MODE9: |
| 632 | case mmGB_MACROTILE_MODE10: |
| 633 | case mmGB_MACROTILE_MODE11: |
| 634 | case mmGB_MACROTILE_MODE12: |
| 635 | case mmGB_MACROTILE_MODE13: |
| 636 | case mmGB_MACROTILE_MODE14: |
| 637 | case mmGB_MACROTILE_MODE15: |
| 638 | idx = (reg_offset - mmGB_MACROTILE_MODE0); |
| 639 | return adev->gfx.config.macrotile_mode_array[idx]; |
| 640 | default: |
| 641 | return RREG32(reg_offset); |
| 642 | } |
| 643 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static int vi_read_register(struct amdgpu_device *adev, u32 se_num, |
| 647 | u32 sh_num, u32 reg_offset, u32 *value) |
| 648 | { |
Nils Wallménius | eca2240 | 2016-03-19 16:12:17 +0100 | [diff] [blame] | 649 | const struct amdgpu_allowed_register_entry *asic_register_table = NULL; |
| 650 | const struct amdgpu_allowed_register_entry *asic_register_entry; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 651 | uint32_t size, i; |
| 652 | |
| 653 | *value = 0; |
| 654 | switch (adev->asic_type) { |
| 655 | case CHIP_TOPAZ: |
| 656 | asic_register_table = tonga_allowed_read_registers; |
| 657 | size = ARRAY_SIZE(tonga_allowed_read_registers); |
| 658 | break; |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 659 | case CHIP_FIJI: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 660 | case CHIP_TONGA: |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 661 | case CHIP_POLARIS11: |
| 662 | case CHIP_POLARIS10: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 663 | case CHIP_POLARIS12: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 664 | case CHIP_CARRIZO: |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 665 | case CHIP_STONEY: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 666 | asic_register_table = cz_allowed_read_registers; |
| 667 | size = ARRAY_SIZE(cz_allowed_read_registers); |
| 668 | break; |
| 669 | default: |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
| 673 | if (asic_register_table) { |
| 674 | for (i = 0; i < size; i++) { |
| 675 | asic_register_entry = asic_register_table + i; |
| 676 | if (reg_offset != asic_register_entry->reg_offset) |
| 677 | continue; |
| 678 | if (!asic_register_entry->untouched) |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 679 | *value = vi_get_register_value(adev, |
| 680 | asic_register_entry->grbm_indexed, |
| 681 | se_num, sh_num, reg_offset); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | for (i = 0; i < ARRAY_SIZE(vi_allowed_read_registers); i++) { |
| 687 | if (reg_offset != vi_allowed_read_registers[i].reg_offset) |
| 688 | continue; |
| 689 | |
| 690 | if (!vi_allowed_read_registers[i].untouched) |
Alex Deucher | db9635c | 2016-10-10 12:05:32 -0400 | [diff] [blame] | 691 | *value = vi_get_register_value(adev, |
| 692 | vi_allowed_read_registers[i].grbm_indexed, |
| 693 | se_num, sh_num, reg_offset); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 694 | return 0; |
| 695 | } |
| 696 | return -EINVAL; |
| 697 | } |
| 698 | |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 699 | static int vi_gpu_pci_config_reset(struct amdgpu_device *adev) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 700 | { |
Alex Deucher | a2c5c69 | 2015-10-14 09:39:37 -0400 | [diff] [blame] | 701 | u32 i; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 702 | |
| 703 | dev_info(adev->dev, "GPU pci config reset\n"); |
| 704 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 705 | /* disable BM */ |
| 706 | pci_clear_master(adev->pdev); |
| 707 | /* reset */ |
| 708 | amdgpu_pci_config_reset(adev); |
| 709 | |
| 710 | udelay(100); |
| 711 | |
| 712 | /* wait for asic to come out of reset */ |
| 713 | for (i = 0; i < adev->usec_timeout; i++) { |
Chunming Zhou | b314f9a | 2016-06-06 13:50:18 +0800 | [diff] [blame] | 714 | if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff) { |
| 715 | /* enable BM */ |
| 716 | pci_set_master(adev->pdev); |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 717 | return 0; |
Chunming Zhou | b314f9a | 2016-06-06 13:50:18 +0800 | [diff] [blame] | 718 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 719 | udelay(1); |
| 720 | } |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 721 | return -EINVAL; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 724 | /** |
| 725 | * vi_asic_reset - soft reset GPU |
| 726 | * |
| 727 | * @adev: amdgpu_device pointer |
| 728 | * |
| 729 | * Look up which blocks are hung and attempt |
| 730 | * to reset them. |
| 731 | * Returns 0 for success. |
| 732 | */ |
| 733 | static int vi_asic_reset(struct amdgpu_device *adev) |
| 734 | { |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 735 | int r; |
| 736 | |
Alex Deucher | 72a5743 | 2016-10-21 15:45:22 -0400 | [diff] [blame] | 737 | amdgpu_atombios_scratch_regs_engine_hung(adev, true); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 738 | |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 739 | r = vi_gpu_pci_config_reset(adev); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 740 | |
Alex Deucher | 72a5743 | 2016-10-21 15:45:22 -0400 | [diff] [blame] | 741 | amdgpu_atombios_scratch_regs_engine_hung(adev, false); |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 742 | |
Chunming Zhou | 89a3182 | 2016-06-06 13:06:45 +0800 | [diff] [blame] | 743 | return r; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static int vi_set_uvd_clock(struct amdgpu_device *adev, u32 clock, |
| 747 | u32 cntl_reg, u32 status_reg) |
| 748 | { |
| 749 | int r, i; |
| 750 | struct atom_clock_dividers dividers; |
| 751 | uint32_t tmp; |
| 752 | |
| 753 | r = amdgpu_atombios_get_clock_dividers(adev, |
| 754 | COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, |
| 755 | clock, false, ÷rs); |
| 756 | if (r) |
| 757 | return r; |
| 758 | |
| 759 | tmp = RREG32_SMC(cntl_reg); |
| 760 | tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK | |
| 761 | CG_DCLK_CNTL__DCLK_DIVIDER_MASK); |
| 762 | tmp |= dividers.post_divider; |
| 763 | WREG32_SMC(cntl_reg, tmp); |
| 764 | |
| 765 | for (i = 0; i < 100; i++) { |
| 766 | if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK) |
| 767 | break; |
| 768 | mdelay(10); |
| 769 | } |
| 770 | if (i == 100) |
| 771 | return -ETIMEDOUT; |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static int vi_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk) |
| 777 | { |
| 778 | int r; |
| 779 | |
| 780 | r = vi_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS); |
| 781 | if (r) |
| 782 | return r; |
| 783 | |
| 784 | r = vi_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS); |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | static int vi_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk) |
| 790 | { |
| 791 | /* todo */ |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static void vi_pcie_gen3_enable(struct amdgpu_device *adev) |
| 797 | { |
Alex Deucher | e79d5c0 | 2015-10-06 09:38:45 -0400 | [diff] [blame] | 798 | if (pci_is_root_bus(adev->pdev->bus)) |
| 799 | return; |
| 800 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 801 | if (amdgpu_pcie_gen2 == 0) |
| 802 | return; |
| 803 | |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 804 | if (adev->flags & AMD_IS_APU) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 805 | return; |
| 806 | |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 807 | if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 808 | CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3))) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 809 | return; |
| 810 | |
| 811 | /* todo */ |
| 812 | } |
| 813 | |
| 814 | static void vi_program_aspm(struct amdgpu_device *adev) |
| 815 | { |
| 816 | |
| 817 | if (amdgpu_aspm == 0) |
| 818 | return; |
| 819 | |
| 820 | /* todo */ |
| 821 | } |
| 822 | |
| 823 | static void vi_enable_doorbell_aperture(struct amdgpu_device *adev, |
| 824 | bool enable) |
| 825 | { |
| 826 | u32 tmp; |
| 827 | |
| 828 | /* not necessary on CZ */ |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 829 | if (adev->flags & AMD_IS_APU) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 830 | return; |
| 831 | |
| 832 | tmp = RREG32(mmBIF_DOORBELL_APER_EN); |
| 833 | if (enable) |
| 834 | tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 1); |
| 835 | else |
| 836 | tmp = REG_SET_FIELD(tmp, BIF_DOORBELL_APER_EN, BIF_DOORBELL_APER_EN, 0); |
| 837 | |
| 838 | WREG32(mmBIF_DOORBELL_APER_EN, tmp); |
| 839 | } |
| 840 | |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 841 | #define ATI_REV_ID_FUSE_MACRO__ADDRESS 0xC0014044 |
| 842 | #define ATI_REV_ID_FUSE_MACRO__SHIFT 9 |
| 843 | #define ATI_REV_ID_FUSE_MACRO__MASK 0x00001E00 |
| 844 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 845 | static uint32_t vi_get_rev_id(struct amdgpu_device *adev) |
| 846 | { |
Flora Cui | abdfb85 | 2015-11-20 11:40:53 +0800 | [diff] [blame] | 847 | if (adev->flags & AMD_IS_APU) |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 848 | return (RREG32_SMC(ATI_REV_ID_FUSE_MACRO__ADDRESS) & ATI_REV_ID_FUSE_MACRO__MASK) |
| 849 | >> ATI_REV_ID_FUSE_MACRO__SHIFT; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 850 | else |
Flora Cui | abdfb85 | 2015-11-20 11:40:53 +0800 | [diff] [blame] | 851 | return (RREG32(mmPCIE_EFUSE4) & PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID_MASK) |
| 852 | >> PCIE_EFUSE4__STRAP_BIF_ATI_REV_ID__SHIFT; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static const struct amdgpu_asic_funcs vi_asic_funcs = |
| 856 | { |
| 857 | .read_disabled_bios = &vi_read_disabled_bios, |
Alex Deucher | 95addb2a | 2015-11-24 10:37:54 -0500 | [diff] [blame] | 858 | .read_bios_from_rom = &vi_read_bios_from_rom, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 859 | .read_register = &vi_read_register, |
| 860 | .reset = &vi_asic_reset, |
| 861 | .set_vga_state = &vi_vga_set_state, |
| 862 | .get_xclk = &vi_get_xclk, |
| 863 | .set_uvd_clocks = &vi_set_uvd_clocks, |
| 864 | .set_vce_clocks = &vi_set_vce_clocks, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 865 | }; |
| 866 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 867 | static int vi_common_early_init(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 868 | { |
| 869 | bool smc_enabled = false; |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 870 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 871 | |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 872 | if (adev->flags & AMD_IS_APU) { |
Alex Deucher | 7b92cdb | 2015-07-10 16:21:10 -0400 | [diff] [blame] | 873 | adev->smc_rreg = &cz_smc_rreg; |
| 874 | adev->smc_wreg = &cz_smc_wreg; |
| 875 | } else { |
| 876 | adev->smc_rreg = &vi_smc_rreg; |
| 877 | adev->smc_wreg = &vi_smc_wreg; |
| 878 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 879 | adev->pcie_rreg = &vi_pcie_rreg; |
| 880 | adev->pcie_wreg = &vi_pcie_wreg; |
| 881 | adev->uvd_ctx_rreg = &vi_uvd_ctx_rreg; |
| 882 | adev->uvd_ctx_wreg = &vi_uvd_ctx_wreg; |
| 883 | adev->didt_rreg = &vi_didt_rreg; |
| 884 | adev->didt_wreg = &vi_didt_wreg; |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 885 | adev->gc_cac_rreg = &vi_gc_cac_rreg; |
| 886 | adev->gc_cac_wreg = &vi_gc_cac_wreg; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 887 | |
| 888 | adev->asic_funcs = &vi_asic_funcs; |
| 889 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 890 | if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_SMC) && |
| 891 | (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_SMC))) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 892 | smc_enabled = true; |
| 893 | |
| 894 | adev->rev_id = vi_get_rev_id(adev); |
| 895 | adev->external_rev_id = 0xFF; |
| 896 | switch (adev->asic_type) { |
| 897 | case CHIP_TOPAZ: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 898 | adev->cg_flags = 0; |
| 899 | adev->pg_flags = 0; |
| 900 | adev->external_rev_id = 0x1; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 901 | break; |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 902 | case CHIP_FIJI: |
Alex Deucher | 14698b6 | 2016-04-07 18:38:00 -0400 | [diff] [blame] | 903 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 904 | AMD_CG_SUPPORT_GFX_MGLS | |
| 905 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 906 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 907 | AMD_CG_SUPPORT_GFX_CGTS | |
| 908 | AMD_CG_SUPPORT_GFX_CGTS_LS | |
| 909 | AMD_CG_SUPPORT_GFX_CGCG | |
Alex Deucher | e08d53c | 2016-04-08 00:42:51 -0400 | [diff] [blame] | 910 | AMD_CG_SUPPORT_GFX_CGLS | |
| 911 | AMD_CG_SUPPORT_SDMA_MGCG | |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 912 | AMD_CG_SUPPORT_SDMA_LS | |
| 913 | AMD_CG_SUPPORT_BIF_LS | |
| 914 | AMD_CG_SUPPORT_HDP_MGCG | |
| 915 | AMD_CG_SUPPORT_HDP_LS | |
Alex Deucher | 3fde56b | 2016-04-08 01:01:18 -0400 | [diff] [blame] | 916 | AMD_CG_SUPPORT_ROM_MGCG | |
| 917 | AMD_CG_SUPPORT_MC_MGCG | |
Rex Zhu | 79abf1a | 2016-11-09 14:30:25 +0800 | [diff] [blame] | 918 | AMD_CG_SUPPORT_MC_LS | |
| 919 | AMD_CG_SUPPORT_UVD_MGCG; |
Flora Cui | b6bc28f | 2015-11-02 21:21:34 +0800 | [diff] [blame] | 920 | adev->pg_flags = 0; |
| 921 | adev->external_rev_id = adev->rev_id + 0x3c; |
| 922 | break; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 923 | case CHIP_TONGA: |
Rex Zhu | ca18b84 | 2016-12-07 18:22:38 +0800 | [diff] [blame] | 924 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 925 | AMD_CG_SUPPORT_GFX_CGCG | |
| 926 | AMD_CG_SUPPORT_GFX_CGLS | |
| 927 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 928 | AMD_CG_SUPPORT_SDMA_LS | |
| 929 | AMD_CG_SUPPORT_BIF_LS | |
| 930 | AMD_CG_SUPPORT_HDP_MGCG | |
| 931 | AMD_CG_SUPPORT_HDP_LS | |
| 932 | AMD_CG_SUPPORT_ROM_MGCG | |
| 933 | AMD_CG_SUPPORT_MC_MGCG | |
| 934 | AMD_CG_SUPPORT_MC_LS | |
| 935 | AMD_CG_SUPPORT_DRM_LS | |
| 936 | AMD_CG_SUPPORT_UVD_MGCG; |
Rex Zhu | 5497140 | 2016-12-07 16:06:38 +0800 | [diff] [blame] | 937 | adev->pg_flags = 0; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 938 | adev->external_rev_id = adev->rev_id + 0x14; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 939 | break; |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 940 | case CHIP_POLARIS11: |
Rex Zhu | ca18b84 | 2016-12-07 18:22:38 +0800 | [diff] [blame] | 941 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 942 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 943 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 944 | AMD_CG_SUPPORT_GFX_CGCG | |
| 945 | AMD_CG_SUPPORT_GFX_CGLS | |
| 946 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
| 947 | AMD_CG_SUPPORT_GFX_3D_CGLS | |
| 948 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 949 | AMD_CG_SUPPORT_SDMA_LS | |
| 950 | AMD_CG_SUPPORT_BIF_MGCG | |
| 951 | AMD_CG_SUPPORT_BIF_LS | |
| 952 | AMD_CG_SUPPORT_HDP_MGCG | |
| 953 | AMD_CG_SUPPORT_HDP_LS | |
| 954 | AMD_CG_SUPPORT_ROM_MGCG | |
| 955 | AMD_CG_SUPPORT_MC_MGCG | |
| 956 | AMD_CG_SUPPORT_MC_LS | |
| 957 | AMD_CG_SUPPORT_DRM_LS | |
| 958 | AMD_CG_SUPPORT_UVD_MGCG | |
Maruthi Srinivas Bayyavarapu | ecc2cf7 | 2016-11-17 17:29:50 +0530 | [diff] [blame] | 959 | AMD_CG_SUPPORT_VCE_MGCG; |
Flora Cui | c0c1f57 | 2015-12-07 18:33:10 +0800 | [diff] [blame] | 960 | adev->pg_flags = 0; |
| 961 | adev->external_rev_id = adev->rev_id + 0x5A; |
| 962 | break; |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 963 | case CHIP_POLARIS10: |
Rex Zhu | ca18b84 | 2016-12-07 18:22:38 +0800 | [diff] [blame] | 964 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 965 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 966 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 967 | AMD_CG_SUPPORT_GFX_CGCG | |
| 968 | AMD_CG_SUPPORT_GFX_CGLS | |
| 969 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
| 970 | AMD_CG_SUPPORT_GFX_3D_CGLS | |
| 971 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 972 | AMD_CG_SUPPORT_SDMA_LS | |
| 973 | AMD_CG_SUPPORT_BIF_MGCG | |
| 974 | AMD_CG_SUPPORT_BIF_LS | |
| 975 | AMD_CG_SUPPORT_HDP_MGCG | |
| 976 | AMD_CG_SUPPORT_HDP_LS | |
| 977 | AMD_CG_SUPPORT_ROM_MGCG | |
| 978 | AMD_CG_SUPPORT_MC_MGCG | |
| 979 | AMD_CG_SUPPORT_MC_LS | |
| 980 | AMD_CG_SUPPORT_DRM_LS | |
| 981 | AMD_CG_SUPPORT_UVD_MGCG | |
Maruthi Srinivas Bayyavarapu | ecc2cf7 | 2016-11-17 17:29:50 +0530 | [diff] [blame] | 982 | AMD_CG_SUPPORT_VCE_MGCG; |
Flora Cui | c0c1f57 | 2015-12-07 18:33:10 +0800 | [diff] [blame] | 983 | adev->pg_flags = 0; |
| 984 | adev->external_rev_id = adev->rev_id + 0x50; |
| 985 | break; |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 986 | case CHIP_POLARIS12: |
| 987 | adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG; |
| 988 | adev->pg_flags = 0; |
| 989 | adev->external_rev_id = adev->rev_id + 0x64; |
| 990 | break; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 991 | case CHIP_CARRIZO: |
Tom St Denis | f0f3a8f | 2016-05-03 10:36:28 -0400 | [diff] [blame] | 992 | adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG | |
| 993 | AMD_CG_SUPPORT_GFX_MGCG | |
Alex Deucher | 70eced9 | 2016-04-07 23:01:48 -0400 | [diff] [blame] | 994 | AMD_CG_SUPPORT_GFX_MGLS | |
| 995 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 996 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 997 | AMD_CG_SUPPORT_GFX_CGTS | |
| 998 | AMD_CG_SUPPORT_GFX_MGLS | |
| 999 | AMD_CG_SUPPORT_GFX_CGTS_LS | |
| 1000 | AMD_CG_SUPPORT_GFX_CGCG | |
Alex Deucher | 03c335d | 2016-04-08 00:26:46 -0400 | [diff] [blame] | 1001 | AMD_CG_SUPPORT_GFX_CGLS | |
| 1002 | AMD_CG_SUPPORT_BIF_LS | |
| 1003 | AMD_CG_SUPPORT_HDP_MGCG | |
Alex Deucher | 6f17a25 | 2016-04-08 00:39:54 -0400 | [diff] [blame] | 1004 | AMD_CG_SUPPORT_HDP_LS | |
| 1005 | AMD_CG_SUPPORT_SDMA_MGCG | |
Tom St Denis | 1af69a2 | 2016-08-03 10:16:17 -0400 | [diff] [blame] | 1006 | AMD_CG_SUPPORT_SDMA_LS | |
| 1007 | AMD_CG_SUPPORT_VCE_MGCG; |
Tom St Denis | f6ade30 | 2016-07-28 09:33:56 -0400 | [diff] [blame] | 1008 | /* rev0 hardware requires workarounds to support PG */ |
Alex Deucher | 0fd4af9 | 2016-02-04 23:31:32 -0500 | [diff] [blame] | 1009 | adev->pg_flags = 0; |
Tom St Denis | f6ade30 | 2016-07-28 09:33:56 -0400 | [diff] [blame] | 1010 | if (adev->rev_id != 0x00) { |
| 1011 | adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG | |
| 1012 | AMD_PG_SUPPORT_GFX_SMG | |
Tom St Denis | 65b4262 | 2016-07-28 09:35:57 -0400 | [diff] [blame] | 1013 | AMD_PG_SUPPORT_GFX_PIPELINE | |
Rex Zhu | 98fccc7 | 2016-12-07 17:48:48 +0800 | [diff] [blame] | 1014 | AMD_PG_SUPPORT_CP | |
Tom St Denis | 2ed0936 | 2016-07-28 09:36:26 -0400 | [diff] [blame] | 1015 | AMD_PG_SUPPORT_UVD | |
| 1016 | AMD_PG_SUPPORT_VCE; |
Tom St Denis | f6ade30 | 2016-07-28 09:33:56 -0400 | [diff] [blame] | 1017 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1018 | adev->external_rev_id = adev->rev_id + 0x1; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1019 | break; |
Tom St Denis | cde6493 | 2016-03-23 13:17:04 -0400 | [diff] [blame] | 1020 | case CHIP_STONEY: |
Alex Deucher | 6469490 | 2016-04-07 23:17:15 -0400 | [diff] [blame] | 1021 | adev->cg_flags = AMD_CG_SUPPORT_UVD_MGCG | |
| 1022 | AMD_CG_SUPPORT_GFX_MGCG | |
Alex Deucher | b6711d1 | 2016-04-13 12:41:50 -0400 | [diff] [blame] | 1023 | AMD_CG_SUPPORT_GFX_MGLS | |
Tom St Denis | 413cf60 | 2016-06-02 08:52:39 -0400 | [diff] [blame] | 1024 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 1025 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 1026 | AMD_CG_SUPPORT_GFX_CGTS | |
| 1027 | AMD_CG_SUPPORT_GFX_MGLS | |
| 1028 | AMD_CG_SUPPORT_GFX_CGTS_LS | |
| 1029 | AMD_CG_SUPPORT_GFX_CGCG | |
| 1030 | AMD_CG_SUPPORT_GFX_CGLS | |
Alex Deucher | b6711d1 | 2016-04-13 12:41:50 -0400 | [diff] [blame] | 1031 | AMD_CG_SUPPORT_BIF_LS | |
| 1032 | AMD_CG_SUPPORT_HDP_MGCG | |
Alex Deucher | 1bf912f | 2016-04-08 00:40:49 -0400 | [diff] [blame] | 1033 | AMD_CG_SUPPORT_HDP_LS | |
| 1034 | AMD_CG_SUPPORT_SDMA_MGCG | |
Tom St Denis | 8ef583e | 2016-08-03 11:34:35 -0400 | [diff] [blame] | 1035 | AMD_CG_SUPPORT_SDMA_LS | |
| 1036 | AMD_CG_SUPPORT_VCE_MGCG; |
Alex Deucher | e6b2a7d | 2016-10-19 13:06:14 -0400 | [diff] [blame] | 1037 | adev->pg_flags = AMD_PG_SUPPORT_GFX_PG | |
Tom St Denis | 4e86be7 | 2016-07-28 09:38:13 -0400 | [diff] [blame] | 1038 | AMD_PG_SUPPORT_GFX_SMG | |
Tom St Denis | c2cdb0428 | 2016-07-28 09:38:29 -0400 | [diff] [blame] | 1039 | AMD_PG_SUPPORT_GFX_PIPELINE | |
Rex Zhu | 98fccc7 | 2016-12-07 17:48:48 +0800 | [diff] [blame] | 1040 | AMD_PG_SUPPORT_CP | |
Tom St Denis | 75419c4 | 2016-07-28 09:38:45 -0400 | [diff] [blame] | 1041 | AMD_PG_SUPPORT_UVD | |
| 1042 | AMD_PG_SUPPORT_VCE; |
Jordan Lazare | a47c78d | 2016-09-01 13:49:33 -0400 | [diff] [blame] | 1043 | adev->external_rev_id = adev->rev_id + 0x61; |
Tom St Denis | cde6493 | 2016-03-23 13:17:04 -0400 | [diff] [blame] | 1044 | break; |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1045 | default: |
| 1046 | /* FIXME: not supported yet */ |
| 1047 | return -EINVAL; |
| 1048 | } |
| 1049 | |
Flora Cui | a3d08fa | 2015-11-02 21:15:55 +0800 | [diff] [blame] | 1050 | if (amdgpu_smc_load_fw && smc_enabled) |
| 1051 | adev->firmware.smu_load = true; |
| 1052 | |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 1053 | amdgpu_get_pcie_info(adev); |
| 1054 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1055 | return 0; |
| 1056 | } |
| 1057 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1058 | static int vi_common_sw_init(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1059 | { |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1063 | static int vi_common_sw_fini(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1064 | { |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1068 | static int vi_common_hw_init(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1069 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1070 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1071 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1072 | /* move the golden regs per IP block */ |
| 1073 | vi_init_golden_registers(adev); |
| 1074 | /* enable pcie gen2/3 link */ |
| 1075 | vi_pcie_gen3_enable(adev); |
| 1076 | /* enable aspm */ |
| 1077 | vi_program_aspm(adev); |
| 1078 | /* enable the doorbell aperture */ |
| 1079 | vi_enable_doorbell_aperture(adev, true); |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1084 | static int vi_common_hw_fini(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1085 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1086 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1087 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1088 | /* enable the doorbell aperture */ |
| 1089 | vi_enable_doorbell_aperture(adev, false); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1094 | static int vi_common_suspend(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1095 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1096 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1097 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1098 | return vi_common_hw_fini(adev); |
| 1099 | } |
| 1100 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1101 | static int vi_common_resume(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1102 | { |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1103 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1104 | |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1105 | return vi_common_hw_init(adev); |
| 1106 | } |
| 1107 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1108 | static bool vi_common_is_idle(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1109 | { |
| 1110 | return true; |
| 1111 | } |
| 1112 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1113 | static int vi_common_wait_for_idle(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1114 | { |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1118 | static int vi_common_soft_reset(void *handle) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1119 | { |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1123 | static void vi_update_bif_medium_grain_light_sleep(struct amdgpu_device *adev, |
| 1124 | bool enable) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1125 | { |
| 1126 | uint32_t temp, data; |
| 1127 | |
| 1128 | temp = data = RREG32_PCIE(ixPCIE_CNTL2); |
| 1129 | |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 1130 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS)) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1131 | data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK | |
| 1132 | PCIE_CNTL2__MST_MEM_LS_EN_MASK | |
| 1133 | PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK; |
| 1134 | else |
| 1135 | data &= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK | |
| 1136 | PCIE_CNTL2__MST_MEM_LS_EN_MASK | |
| 1137 | PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK); |
| 1138 | |
| 1139 | if (temp != data) |
| 1140 | WREG32_PCIE(ixPCIE_CNTL2, data); |
| 1141 | } |
| 1142 | |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1143 | static void vi_update_hdp_medium_grain_clock_gating(struct amdgpu_device *adev, |
| 1144 | bool enable) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1145 | { |
| 1146 | uint32_t temp, data; |
| 1147 | |
| 1148 | temp = data = RREG32(mmHDP_HOST_PATH_CNTL); |
| 1149 | |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 1150 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG)) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1151 | data &= ~HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK; |
| 1152 | else |
| 1153 | data |= HDP_HOST_PATH_CNTL__CLOCK_GATING_DIS_MASK; |
| 1154 | |
| 1155 | if (temp != data) |
| 1156 | WREG32(mmHDP_HOST_PATH_CNTL, data); |
| 1157 | } |
| 1158 | |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1159 | static void vi_update_hdp_light_sleep(struct amdgpu_device *adev, |
| 1160 | bool enable) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1161 | { |
| 1162 | uint32_t temp, data; |
| 1163 | |
| 1164 | temp = data = RREG32(mmHDP_MEM_POWER_LS); |
| 1165 | |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 1166 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS)) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1167 | data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK; |
| 1168 | else |
| 1169 | data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK; |
| 1170 | |
| 1171 | if (temp != data) |
| 1172 | WREG32(mmHDP_MEM_POWER_LS, data); |
| 1173 | } |
| 1174 | |
Rex Zhu | f6f534e | 2016-12-08 10:58:15 +0800 | [diff] [blame] | 1175 | static void vi_update_drm_light_sleep(struct amdgpu_device *adev, |
| 1176 | bool enable) |
| 1177 | { |
| 1178 | uint32_t temp, data; |
| 1179 | |
| 1180 | temp = data = RREG32(0x157a); |
| 1181 | |
| 1182 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS)) |
| 1183 | data |= 1; |
| 1184 | else |
| 1185 | data &= ~1; |
| 1186 | |
| 1187 | if (temp != data) |
| 1188 | WREG32(0x157a, data); |
| 1189 | } |
| 1190 | |
| 1191 | |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1192 | static void vi_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev, |
| 1193 | bool enable) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1194 | { |
| 1195 | uint32_t temp, data; |
| 1196 | |
| 1197 | temp = data = RREG32_SMC(ixCGTT_ROM_CLK_CTRL0); |
| 1198 | |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 1199 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG)) |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1200 | data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK | |
| 1201 | CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK); |
| 1202 | else |
| 1203 | data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK | |
| 1204 | CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK; |
| 1205 | |
| 1206 | if (temp != data) |
| 1207 | WREG32_SMC(ixCGTT_ROM_CLK_CTRL0, data); |
| 1208 | } |
| 1209 | |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1210 | static int vi_common_set_clockgating_state_by_smu(void *handle, |
| 1211 | enum amd_clockgating_state state) |
| 1212 | { |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1213 | uint32_t msg_id, pp_state = 0; |
| 1214 | uint32_t pp_support_state = 0; |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1215 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1216 | void *pp_handle = adev->powerplay.pp_handle; |
| 1217 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1218 | if (adev->cg_flags & (AMD_CG_SUPPORT_MC_LS | AMD_CG_SUPPORT_MC_MGCG)) { |
| 1219 | if (adev->cg_flags & AMD_CG_SUPPORT_MC_LS) { |
| 1220 | pp_support_state = AMD_CG_SUPPORT_MC_LS; |
| 1221 | pp_state = PP_STATE_LS; |
| 1222 | } |
| 1223 | if (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG) { |
| 1224 | pp_support_state |= AMD_CG_SUPPORT_MC_MGCG; |
| 1225 | pp_state |= PP_STATE_CG; |
| 1226 | } |
| 1227 | if (state == AMD_CG_STATE_UNGATE) |
| 1228 | pp_state = 0; |
| 1229 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1230 | PP_BLOCK_SYS_MC, |
| 1231 | pp_support_state, |
| 1232 | pp_state); |
| 1233 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1234 | } |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1235 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1236 | if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS | AMD_CG_SUPPORT_SDMA_MGCG)) { |
| 1237 | if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_LS) { |
| 1238 | pp_support_state = AMD_CG_SUPPORT_SDMA_LS; |
| 1239 | pp_state = PP_STATE_LS; |
| 1240 | } |
| 1241 | if (adev->cg_flags & AMD_CG_SUPPORT_SDMA_MGCG) { |
| 1242 | pp_support_state |= AMD_CG_SUPPORT_SDMA_MGCG; |
| 1243 | pp_state |= PP_STATE_CG; |
| 1244 | } |
| 1245 | if (state == AMD_CG_STATE_UNGATE) |
| 1246 | pp_state = 0; |
| 1247 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1248 | PP_BLOCK_SYS_SDMA, |
| 1249 | pp_support_state, |
| 1250 | pp_state); |
| 1251 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1252 | } |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1253 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1254 | if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_MGCG)) { |
| 1255 | if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) { |
| 1256 | pp_support_state = AMD_CG_SUPPORT_HDP_LS; |
| 1257 | pp_state = PP_STATE_LS; |
| 1258 | } |
| 1259 | if (adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG) { |
| 1260 | pp_support_state |= AMD_CG_SUPPORT_HDP_MGCG; |
| 1261 | pp_state |= PP_STATE_CG; |
| 1262 | } |
| 1263 | if (state == AMD_CG_STATE_UNGATE) |
| 1264 | pp_state = 0; |
| 1265 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1266 | PP_BLOCK_SYS_HDP, |
| 1267 | pp_support_state, |
| 1268 | pp_state); |
| 1269 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1270 | } |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1271 | |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1272 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1273 | if (adev->cg_flags & AMD_CG_SUPPORT_BIF_LS) { |
| 1274 | if (state == AMD_CG_STATE_UNGATE) |
| 1275 | pp_state = 0; |
| 1276 | else |
| 1277 | pp_state = PP_STATE_LS; |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1278 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1279 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1280 | PP_BLOCK_SYS_BIF, |
| 1281 | PP_STATE_SUPPORT_LS, |
| 1282 | pp_state); |
| 1283 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1284 | } |
| 1285 | if (adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG) { |
| 1286 | if (state == AMD_CG_STATE_UNGATE) |
| 1287 | pp_state = 0; |
| 1288 | else |
| 1289 | pp_state = PP_STATE_CG; |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1290 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1291 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1292 | PP_BLOCK_SYS_BIF, |
| 1293 | PP_STATE_SUPPORT_CG, |
| 1294 | pp_state); |
| 1295 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1296 | } |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1297 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1298 | if (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS) { |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1299 | |
Rex Zhu | 8a19e7f | 2016-12-07 19:11:49 +0800 | [diff] [blame] | 1300 | if (state == AMD_CG_STATE_UNGATE) |
| 1301 | pp_state = 0; |
| 1302 | else |
| 1303 | pp_state = PP_STATE_LS; |
| 1304 | |
| 1305 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1306 | PP_BLOCK_SYS_DRM, |
| 1307 | PP_STATE_SUPPORT_LS, |
| 1308 | pp_state); |
| 1309 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1310 | } |
| 1311 | |
| 1312 | if (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG) { |
| 1313 | |
| 1314 | if (state == AMD_CG_STATE_UNGATE) |
| 1315 | pp_state = 0; |
| 1316 | else |
| 1317 | pp_state = PP_STATE_CG; |
| 1318 | |
| 1319 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 1320 | PP_BLOCK_SYS_ROM, |
| 1321 | PP_STATE_SUPPORT_CG, |
| 1322 | pp_state); |
| 1323 | amd_set_clockgating_by_smu(pp_handle, msg_id); |
| 1324 | } |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1325 | return 0; |
| 1326 | } |
| 1327 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1328 | static int vi_common_set_clockgating_state(void *handle, |
Alex Deucher | c90766c | 2016-04-08 00:52:58 -0400 | [diff] [blame] | 1329 | enum amd_clockgating_state state) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1330 | { |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1331 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1332 | |
| 1333 | switch (adev->asic_type) { |
| 1334 | case CHIP_FIJI: |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1335 | vi_update_bif_medium_grain_light_sleep(adev, |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1336 | state == AMD_CG_STATE_GATE ? true : false); |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1337 | vi_update_hdp_medium_grain_clock_gating(adev, |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1338 | state == AMD_CG_STATE_GATE ? true : false); |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1339 | vi_update_hdp_light_sleep(adev, |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1340 | state == AMD_CG_STATE_GATE ? true : false); |
Alex Deucher | 76f10b9 | 2016-04-08 01:37:44 -0400 | [diff] [blame] | 1341 | vi_update_rom_medium_grain_clock_gating(adev, |
| 1342 | state == AMD_CG_STATE_GATE ? true : false); |
| 1343 | break; |
| 1344 | case CHIP_CARRIZO: |
| 1345 | case CHIP_STONEY: |
| 1346 | vi_update_bif_medium_grain_light_sleep(adev, |
| 1347 | state == AMD_CG_STATE_GATE ? true : false); |
| 1348 | vi_update_hdp_medium_grain_clock_gating(adev, |
| 1349 | state == AMD_CG_STATE_GATE ? true : false); |
| 1350 | vi_update_hdp_light_sleep(adev, |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1351 | state == AMD_CG_STATE_GATE ? true : false); |
Rex Zhu | f6f534e | 2016-12-08 10:58:15 +0800 | [diff] [blame] | 1352 | vi_update_drm_light_sleep(adev, |
| 1353 | state == AMD_CG_STATE_GATE ? true : false); |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1354 | break; |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1355 | case CHIP_TONGA: |
| 1356 | case CHIP_POLARIS10: |
| 1357 | case CHIP_POLARIS11: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 1358 | case CHIP_POLARIS12: |
Rex Zhu | 1bb08f9 | 2016-09-18 16:54:00 +0800 | [diff] [blame] | 1359 | vi_common_set_clockgating_state_by_smu(adev, state); |
Eric Huang | 6cec265 | 2015-11-12 16:59:47 -0500 | [diff] [blame] | 1360 | default: |
| 1361 | break; |
| 1362 | } |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1363 | return 0; |
| 1364 | } |
| 1365 | |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1366 | static int vi_common_set_powergating_state(void *handle, |
| 1367 | enum amd_powergating_state state) |
| 1368 | { |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1372 | static const struct amd_ip_funcs vi_common_ip_funcs = { |
Tom St Denis | 88a907d | 2016-05-04 14:28:35 -0400 | [diff] [blame] | 1373 | .name = "vi_common", |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1374 | .early_init = vi_common_early_init, |
| 1375 | .late_init = NULL, |
| 1376 | .sw_init = vi_common_sw_init, |
| 1377 | .sw_fini = vi_common_sw_fini, |
| 1378 | .hw_init = vi_common_hw_init, |
| 1379 | .hw_fini = vi_common_hw_fini, |
| 1380 | .suspend = vi_common_suspend, |
| 1381 | .resume = vi_common_resume, |
| 1382 | .is_idle = vi_common_is_idle, |
| 1383 | .wait_for_idle = vi_common_wait_for_idle, |
| 1384 | .soft_reset = vi_common_soft_reset, |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1385 | .set_clockgating_state = vi_common_set_clockgating_state, |
| 1386 | .set_powergating_state = vi_common_set_powergating_state, |
| 1387 | }; |
| 1388 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1389 | static const struct amdgpu_ip_block_version vi_common_ip_block = |
| 1390 | { |
| 1391 | .type = AMD_IP_BLOCK_TYPE_COMMON, |
| 1392 | .major = 1, |
| 1393 | .minor = 0, |
| 1394 | .rev = 0, |
| 1395 | .funcs = &vi_common_ip_funcs, |
| 1396 | }; |
| 1397 | |
| 1398 | int vi_set_ip_blocks(struct amdgpu_device *adev) |
| 1399 | { |
Xiangliang Yu | 91caa08 | 2017-01-09 11:49:27 +0800 | [diff] [blame^] | 1400 | /* in early init stage, vbios code won't work */ |
| 1401 | vi_detect_hw_virtualization(adev); |
| 1402 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1403 | switch (adev->asic_type) { |
| 1404 | case CHIP_TOPAZ: |
| 1405 | /* topaz has no DCE, UVD, VCE */ |
| 1406 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1407 | amdgpu_ip_block_add(adev, &gmc_v7_4_ip_block); |
| 1408 | amdgpu_ip_block_add(adev, &iceland_ih_ip_block); |
| 1409 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
| 1410 | if (adev->enable_virtual_display) |
| 1411 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1412 | amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block); |
| 1413 | amdgpu_ip_block_add(adev, &sdma_v2_4_ip_block); |
| 1414 | break; |
| 1415 | case CHIP_FIJI: |
| 1416 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1417 | amdgpu_ip_block_add(adev, &gmc_v8_5_ip_block); |
| 1418 | amdgpu_ip_block_add(adev, &tonga_ih_ip_block); |
| 1419 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
Xiangliang Yu | 91caa08 | 2017-01-09 11:49:27 +0800 | [diff] [blame^] | 1420 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1421 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1422 | else |
| 1423 | amdgpu_ip_block_add(adev, &dce_v10_1_ip_block); |
| 1424 | amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block); |
| 1425 | amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block); |
Xiangliang Yu | 91caa08 | 2017-01-09 11:49:27 +0800 | [diff] [blame^] | 1426 | if (!amdgpu_sriov_vf(adev)) { |
| 1427 | amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block); |
| 1428 | amdgpu_ip_block_add(adev, &vce_v3_0_ip_block); |
| 1429 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1430 | break; |
| 1431 | case CHIP_TONGA: |
| 1432 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1433 | amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block); |
| 1434 | amdgpu_ip_block_add(adev, &tonga_ih_ip_block); |
| 1435 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
Xiangliang Yu | 91caa08 | 2017-01-09 11:49:27 +0800 | [diff] [blame^] | 1436 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1437 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1438 | else |
| 1439 | amdgpu_ip_block_add(adev, &dce_v10_0_ip_block); |
| 1440 | amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block); |
| 1441 | amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block); |
Xiangliang Yu | 91caa08 | 2017-01-09 11:49:27 +0800 | [diff] [blame^] | 1442 | if (!amdgpu_sriov_vf(adev)) { |
| 1443 | amdgpu_ip_block_add(adev, &uvd_v5_0_ip_block); |
| 1444 | amdgpu_ip_block_add(adev, &vce_v3_0_ip_block); |
| 1445 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1446 | break; |
| 1447 | case CHIP_POLARIS11: |
| 1448 | case CHIP_POLARIS10: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 1449 | case CHIP_POLARIS12: |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1450 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1451 | amdgpu_ip_block_add(adev, &gmc_v8_1_ip_block); |
| 1452 | amdgpu_ip_block_add(adev, &tonga_ih_ip_block); |
| 1453 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
| 1454 | if (adev->enable_virtual_display) |
| 1455 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1456 | else |
| 1457 | amdgpu_ip_block_add(adev, &dce_v11_2_ip_block); |
| 1458 | amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block); |
| 1459 | amdgpu_ip_block_add(adev, &sdma_v3_1_ip_block); |
| 1460 | amdgpu_ip_block_add(adev, &uvd_v6_3_ip_block); |
| 1461 | amdgpu_ip_block_add(adev, &vce_v3_4_ip_block); |
| 1462 | break; |
| 1463 | case CHIP_CARRIZO: |
| 1464 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1465 | amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block); |
| 1466 | amdgpu_ip_block_add(adev, &cz_ih_ip_block); |
| 1467 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
| 1468 | if (adev->enable_virtual_display) |
| 1469 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1470 | else |
| 1471 | amdgpu_ip_block_add(adev, &dce_v11_0_ip_block); |
| 1472 | amdgpu_ip_block_add(adev, &gfx_v8_0_ip_block); |
| 1473 | amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block); |
| 1474 | amdgpu_ip_block_add(adev, &uvd_v6_0_ip_block); |
| 1475 | amdgpu_ip_block_add(adev, &vce_v3_1_ip_block); |
| 1476 | #if defined(CONFIG_DRM_AMD_ACP) |
| 1477 | amdgpu_ip_block_add(adev, &acp_ip_block); |
| 1478 | #endif |
| 1479 | break; |
| 1480 | case CHIP_STONEY: |
| 1481 | amdgpu_ip_block_add(adev, &vi_common_ip_block); |
| 1482 | amdgpu_ip_block_add(adev, &gmc_v8_0_ip_block); |
| 1483 | amdgpu_ip_block_add(adev, &cz_ih_ip_block); |
| 1484 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
| 1485 | if (adev->enable_virtual_display) |
| 1486 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
| 1487 | else |
| 1488 | amdgpu_ip_block_add(adev, &dce_v11_0_ip_block); |
| 1489 | amdgpu_ip_block_add(adev, &gfx_v8_1_ip_block); |
| 1490 | amdgpu_ip_block_add(adev, &sdma_v3_0_ip_block); |
| 1491 | amdgpu_ip_block_add(adev, &uvd_v6_2_ip_block); |
| 1492 | amdgpu_ip_block_add(adev, &vce_v3_4_ip_block); |
| 1493 | #if defined(CONFIG_DRM_AMD_ACP) |
| 1494 | amdgpu_ip_block_add(adev, &acp_ip_block); |
| 1495 | #endif |
| 1496 | break; |
| 1497 | default: |
| 1498 | /* FIXME: not supported yet */ |
| 1499 | return -EINVAL; |
| 1500 | } |
| 1501 | |
| 1502 | return 0; |
| 1503 | } |