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