Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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> |
Alex Deucher | e9eea90 | 2019-07-31 10:39:40 -0500 | [diff] [blame] | 26 | #include <linux/pci.h> |
| 27 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 28 | #include "amdgpu.h" |
| 29 | #include "amdgpu_atombios.h" |
| 30 | #include "amdgpu_ih.h" |
| 31 | #include "amdgpu_uvd.h" |
| 32 | #include "amdgpu_vce.h" |
| 33 | #include "amdgpu_ucode.h" |
| 34 | #include "amdgpu_psp.h" |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 35 | #include "amdgpu_smu.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 36 | #include "atom.h" |
| 37 | #include "amd_pcie.h" |
| 38 | |
| 39 | #include "gc/gc_10_1_0_offset.h" |
| 40 | #include "gc/gc_10_1_0_sh_mask.h" |
| 41 | #include "hdp/hdp_5_0_0_offset.h" |
| 42 | #include "hdp/hdp_5_0_0_sh_mask.h" |
| 43 | |
| 44 | #include "soc15.h" |
| 45 | #include "soc15_common.h" |
| 46 | #include "gmc_v10_0.h" |
| 47 | #include "gfxhub_v2_0.h" |
| 48 | #include "mmhub_v2_0.h" |
| 49 | #include "nv.h" |
| 50 | #include "navi10_ih.h" |
| 51 | #include "gfx_v10_0.h" |
| 52 | #include "sdma_v5_0.h" |
| 53 | #include "vcn_v2_0.h" |
| 54 | #include "dce_virtual.h" |
| 55 | #include "mes_v10_1.h" |
| 56 | |
| 57 | static const struct amd_ip_funcs nv_common_ip_funcs; |
| 58 | |
| 59 | /* |
| 60 | * Indirect registers accessor |
| 61 | */ |
| 62 | static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg) |
| 63 | { |
| 64 | unsigned long flags, address, data; |
| 65 | u32 r; |
| 66 | address = adev->nbio_funcs->get_pcie_index_offset(adev); |
| 67 | data = adev->nbio_funcs->get_pcie_data_offset(adev); |
| 68 | |
| 69 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 70 | WREG32(address, reg); |
| 71 | (void)RREG32(address); |
| 72 | r = RREG32(data); |
| 73 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 74 | return r; |
| 75 | } |
| 76 | |
| 77 | static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 78 | { |
| 79 | unsigned long flags, address, data; |
| 80 | |
| 81 | address = adev->nbio_funcs->get_pcie_index_offset(adev); |
| 82 | data = adev->nbio_funcs->get_pcie_data_offset(adev); |
| 83 | |
| 84 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 85 | WREG32(address, reg); |
| 86 | (void)RREG32(address); |
| 87 | WREG32(data, v); |
| 88 | (void)RREG32(data); |
| 89 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 90 | } |
| 91 | |
| 92 | static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg) |
| 93 | { |
| 94 | unsigned long flags, address, data; |
| 95 | u32 r; |
| 96 | |
| 97 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 98 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 99 | |
| 100 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 101 | WREG32(address, (reg)); |
| 102 | r = RREG32(data); |
| 103 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 104 | return r; |
| 105 | } |
| 106 | |
| 107 | static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 108 | { |
| 109 | unsigned long flags, address, data; |
| 110 | |
| 111 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 112 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 113 | |
| 114 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 115 | WREG32(address, (reg)); |
| 116 | WREG32(data, (v)); |
| 117 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 118 | } |
| 119 | |
| 120 | static u32 nv_get_config_memsize(struct amdgpu_device *adev) |
| 121 | { |
| 122 | return adev->nbio_funcs->get_memsize(adev); |
| 123 | } |
| 124 | |
| 125 | static u32 nv_get_xclk(struct amdgpu_device *adev) |
| 126 | { |
Tao Zhou | 462a70d | 2019-05-14 11:37:32 +0800 | [diff] [blame] | 127 | return adev->clock.spll.reference_freq; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
| 131 | void nv_grbm_select(struct amdgpu_device *adev, |
| 132 | u32 me, u32 pipe, u32 queue, u32 vmid) |
| 133 | { |
| 134 | u32 grbm_gfx_cntl = 0; |
| 135 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe); |
| 136 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me); |
| 137 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid); |
| 138 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue); |
| 139 | |
| 140 | WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl); |
| 141 | } |
| 142 | |
| 143 | static void nv_vga_set_state(struct amdgpu_device *adev, bool state) |
| 144 | { |
| 145 | /* todo */ |
| 146 | } |
| 147 | |
| 148 | static bool nv_read_disabled_bios(struct amdgpu_device *adev) |
| 149 | { |
| 150 | /* todo */ |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | static bool nv_read_bios_from_rom(struct amdgpu_device *adev, |
| 155 | u8 *bios, u32 length_bytes) |
| 156 | { |
| 157 | /* TODO: will implement it when SMU header is available */ |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | static struct soc15_allowed_register_entry nv_allowed_read_registers[] = { |
| 162 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)}, |
| 163 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)}, |
| 164 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)}, |
| 165 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)}, |
| 166 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)}, |
| 167 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)}, |
| 168 | #if 0 /* TODO: will set it when SDMA header is available */ |
| 169 | { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)}, |
| 170 | { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)}, |
| 171 | #endif |
| 172 | { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)}, |
| 173 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)}, |
| 174 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)}, |
| 175 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)}, |
| 176 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)}, |
| 177 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)}, |
| 178 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)}, |
| 179 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)}, |
| 180 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)}, |
| 181 | { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)}, |
| 182 | }; |
| 183 | |
| 184 | static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num, |
| 185 | u32 sh_num, u32 reg_offset) |
| 186 | { |
| 187 | uint32_t val; |
| 188 | |
| 189 | mutex_lock(&adev->grbm_idx_mutex); |
| 190 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 191 | amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff); |
| 192 | |
| 193 | val = RREG32(reg_offset); |
| 194 | |
| 195 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 196 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 197 | mutex_unlock(&adev->grbm_idx_mutex); |
| 198 | return val; |
| 199 | } |
| 200 | |
| 201 | static uint32_t nv_get_register_value(struct amdgpu_device *adev, |
| 202 | bool indexed, u32 se_num, |
| 203 | u32 sh_num, u32 reg_offset) |
| 204 | { |
| 205 | if (indexed) { |
| 206 | return nv_read_indexed_register(adev, se_num, sh_num, reg_offset); |
| 207 | } else { |
| 208 | if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) |
| 209 | return adev->gfx.config.gb_addr_config; |
| 210 | return RREG32(reg_offset); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | static int nv_read_register(struct amdgpu_device *adev, u32 se_num, |
| 215 | u32 sh_num, u32 reg_offset, u32 *value) |
| 216 | { |
| 217 | uint32_t i; |
| 218 | struct soc15_allowed_register_entry *en; |
| 219 | |
| 220 | *value = 0; |
| 221 | for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) { |
| 222 | en = &nv_allowed_read_registers[i]; |
| 223 | if (reg_offset != |
| 224 | (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset)) |
| 225 | continue; |
| 226 | |
| 227 | *value = nv_get_register_value(adev, |
| 228 | nv_allowed_read_registers[i].grbm_indexed, |
| 229 | se_num, sh_num, reg_offset); |
| 230 | return 0; |
| 231 | } |
| 232 | return -EINVAL; |
| 233 | } |
| 234 | |
| 235 | #if 0 |
| 236 | static void nv_gpu_pci_config_reset(struct amdgpu_device *adev) |
| 237 | { |
| 238 | u32 i; |
| 239 | |
| 240 | dev_info(adev->dev, "GPU pci config reset\n"); |
| 241 | |
| 242 | /* disable BM */ |
| 243 | pci_clear_master(adev->pdev); |
| 244 | /* reset */ |
| 245 | amdgpu_pci_config_reset(adev); |
| 246 | |
| 247 | udelay(100); |
| 248 | |
| 249 | /* wait for asic to come out of reset */ |
| 250 | for (i = 0; i < adev->usec_timeout; i++) { |
| 251 | u32 memsize = nbio_v2_3_get_memsize(adev); |
| 252 | if (memsize != 0xffffffff) |
| 253 | break; |
| 254 | udelay(1); |
| 255 | } |
| 256 | |
| 257 | } |
| 258 | #endif |
| 259 | |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 260 | static int nv_asic_mode1_reset(struct amdgpu_device *adev) |
| 261 | { |
| 262 | u32 i; |
| 263 | int ret = 0; |
| 264 | |
| 265 | amdgpu_atombios_scratch_regs_engine_hung(adev, true); |
| 266 | |
| 267 | dev_info(adev->dev, "GPU mode1 reset\n"); |
| 268 | |
| 269 | /* disable BM */ |
| 270 | pci_clear_master(adev->pdev); |
| 271 | |
| 272 | pci_save_state(adev->pdev); |
| 273 | |
| 274 | ret = psp_gpu_reset(adev); |
| 275 | if (ret) |
| 276 | dev_err(adev->dev, "GPU mode1 reset failed\n"); |
| 277 | |
| 278 | pci_restore_state(adev->pdev); |
| 279 | |
| 280 | /* wait for asic to come out of reset */ |
| 281 | for (i = 0; i < adev->usec_timeout; i++) { |
| 282 | u32 memsize = adev->nbio_funcs->get_memsize(adev); |
| 283 | |
| 284 | if (memsize != 0xffffffff) |
| 285 | break; |
| 286 | udelay(1); |
| 287 | } |
| 288 | |
| 289 | amdgpu_atombios_scratch_regs_engine_hung(adev, false); |
| 290 | |
| 291 | return ret; |
| 292 | } |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 293 | |
| 294 | static enum amd_reset_method |
| 295 | nv_asic_reset_method(struct amdgpu_device *adev) |
| 296 | { |
| 297 | struct smu_context *smu = &adev->smu; |
| 298 | |
| 299 | if (smu_baco_is_support(smu)) |
| 300 | return AMD_RESET_METHOD_BACO; |
| 301 | else |
| 302 | return AMD_RESET_METHOD_MODE1; |
| 303 | } |
| 304 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 305 | static int nv_asic_reset(struct amdgpu_device *adev) |
| 306 | { |
| 307 | |
| 308 | /* FIXME: it doesn't work since vega10 */ |
| 309 | #if 0 |
| 310 | amdgpu_atombios_scratch_regs_engine_hung(adev, true); |
| 311 | |
| 312 | nv_gpu_pci_config_reset(adev); |
| 313 | |
| 314 | amdgpu_atombios_scratch_regs_engine_hung(adev, false); |
| 315 | #endif |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 316 | int ret = 0; |
| 317 | struct smu_context *smu = &adev->smu; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 318 | |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 319 | if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 320 | ret = smu_baco_reset(smu); |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 321 | else |
| 322 | ret = nv_asic_mode1_reset(adev); |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 323 | |
| 324 | return ret; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk) |
| 328 | { |
| 329 | /* todo */ |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk) |
| 334 | { |
| 335 | /* todo */ |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static void nv_pcie_gen3_enable(struct amdgpu_device *adev) |
| 340 | { |
| 341 | if (pci_is_root_bus(adev->pdev->bus)) |
| 342 | return; |
| 343 | |
| 344 | if (amdgpu_pcie_gen2 == 0) |
| 345 | return; |
| 346 | |
| 347 | if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 348 | CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3))) |
| 349 | return; |
| 350 | |
| 351 | /* todo */ |
| 352 | } |
| 353 | |
| 354 | static void nv_program_aspm(struct amdgpu_device *adev) |
| 355 | { |
| 356 | |
| 357 | if (amdgpu_aspm == 0) |
| 358 | return; |
| 359 | |
| 360 | /* todo */ |
| 361 | } |
| 362 | |
| 363 | static void nv_enable_doorbell_aperture(struct amdgpu_device *adev, |
| 364 | bool enable) |
| 365 | { |
| 366 | adev->nbio_funcs->enable_doorbell_aperture(adev, enable); |
| 367 | adev->nbio_funcs->enable_doorbell_selfring_aperture(adev, enable); |
| 368 | } |
| 369 | |
| 370 | static const struct amdgpu_ip_block_version nv_common_ip_block = |
| 371 | { |
| 372 | .type = AMD_IP_BLOCK_TYPE_COMMON, |
| 373 | .major = 1, |
| 374 | .minor = 0, |
| 375 | .rev = 0, |
| 376 | .funcs = &nv_common_ip_funcs, |
| 377 | }; |
| 378 | |
| 379 | int nv_set_ip_blocks(struct amdgpu_device *adev) |
| 380 | { |
| 381 | /* Set IP register base before any HW register access */ |
| 382 | switch (adev->asic_type) { |
| 383 | case CHIP_NAVI10: |
| 384 | navi10_reg_base_init(adev); |
| 385 | break; |
Xiaojie Yuan | a0f6d926 | 2018-12-17 18:24:03 +0800 | [diff] [blame] | 386 | case CHIP_NAVI14: |
| 387 | navi14_reg_base_init(adev); |
| 388 | break; |
Xiaojie Yuan | 03d0a07 | 2019-05-14 15:22:53 +0800 | [diff] [blame] | 389 | case CHIP_NAVI12: |
| 390 | navi12_reg_base_init(adev); |
| 391 | break; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 392 | default: |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | |
| 396 | adev->nbio_funcs = &nbio_v2_3_funcs; |
| 397 | |
| 398 | adev->nbio_funcs->detect_hw_virt(adev); |
| 399 | |
| 400 | switch (adev->asic_type) { |
| 401 | case CHIP_NAVI10: |
Alex Deucher | d1daf85 | 2019-07-02 14:42:25 -0500 | [diff] [blame] | 402 | case CHIP_NAVI14: |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 403 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
| 404 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
| 405 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
| 406 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
| 407 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP && |
| 408 | is_support_sw_smu(adev)) |
| 409 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
| 410 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 411 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Alex Deucher | f8a7976 | 2019-07-05 15:39:39 -0500 | [diff] [blame] | 412 | #if defined(CONFIG_DRM_AMD_DC) |
Harry Wentland | b4f199c | 2019-02-26 16:25:27 -0500 | [diff] [blame] | 413 | else if (amdgpu_device_has_dc_support(adev)) |
| 414 | amdgpu_device_ip_block_add(adev, &dm_ip_block); |
Alex Deucher | f8a7976 | 2019-07-05 15:39:39 -0500 | [diff] [blame] | 415 | #endif |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 416 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
| 417 | amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block); |
| 418 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && |
| 419 | is_support_sw_smu(adev)) |
| 420 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
| 421 | amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block); |
| 422 | if (adev->enable_mes) |
| 423 | amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block); |
| 424 | break; |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 425 | case CHIP_NAVI12: |
| 426 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
| 427 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
| 428 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
Xiaojie Yuan | 6b66ae2 | 2019-07-18 02:54:29 +0800 | [diff] [blame^] | 429 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
Xiaojie Yuan | 7f47efe | 2019-07-16 03:26:49 +0800 | [diff] [blame] | 430 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP && |
| 431 | is_support_sw_smu(adev)) |
| 432 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Xiaojie Yuan | 7990202 | 2019-06-26 19:19:57 +0800 | [diff] [blame] | 433 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 434 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 435 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
| 436 | amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block); |
Xiaojie Yuan | 7f47efe | 2019-07-16 03:26:49 +0800 | [diff] [blame] | 437 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && |
| 438 | is_support_sw_smu(adev)) |
| 439 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 440 | break; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 441 | default: |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static uint32_t nv_get_rev_id(struct amdgpu_device *adev) |
| 449 | { |
| 450 | return adev->nbio_funcs->get_rev_id(adev); |
| 451 | } |
| 452 | |
| 453 | static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) |
| 454 | { |
| 455 | adev->nbio_funcs->hdp_flush(adev, ring); |
| 456 | } |
| 457 | |
| 458 | static void nv_invalidate_hdp(struct amdgpu_device *adev, |
| 459 | struct amdgpu_ring *ring) |
| 460 | { |
| 461 | if (!ring || !ring->funcs->emit_wreg) { |
| 462 | WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1); |
| 463 | } else { |
| 464 | amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET( |
| 465 | HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | static bool nv_need_full_reset(struct amdgpu_device *adev) |
| 470 | { |
| 471 | return true; |
| 472 | } |
| 473 | |
| 474 | static void nv_get_pcie_usage(struct amdgpu_device *adev, |
| 475 | uint64_t *count0, |
| 476 | uint64_t *count1) |
| 477 | { |
| 478 | /*TODO*/ |
| 479 | } |
| 480 | |
| 481 | static bool nv_need_reset_on_init(struct amdgpu_device *adev) |
| 482 | { |
| 483 | #if 0 |
| 484 | u32 sol_reg; |
| 485 | |
| 486 | if (adev->flags & AMD_IS_APU) |
| 487 | return false; |
| 488 | |
| 489 | /* Check sOS sign of life register to confirm sys driver and sOS |
| 490 | * are already been loaded. |
| 491 | */ |
| 492 | sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81); |
| 493 | if (sol_reg) |
| 494 | return true; |
| 495 | #endif |
| 496 | /* TODO: re-enable it when mode1 reset is functional */ |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | static void nv_init_doorbell_index(struct amdgpu_device *adev) |
| 501 | { |
| 502 | adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ; |
| 503 | adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0; |
| 504 | adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1; |
| 505 | adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2; |
| 506 | adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3; |
| 507 | adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4; |
| 508 | adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5; |
| 509 | adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6; |
| 510 | adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7; |
| 511 | adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START; |
| 512 | adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END; |
| 513 | adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0; |
| 514 | adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1; |
| 515 | adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0; |
| 516 | adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1; |
| 517 | adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH; |
| 518 | adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1; |
| 519 | adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3; |
| 520 | adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5; |
| 521 | adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7; |
| 522 | adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP; |
| 523 | adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP; |
| 524 | |
| 525 | adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1; |
| 526 | adev->doorbell_index.sdma_doorbell_range = 20; |
| 527 | } |
| 528 | |
| 529 | static const struct amdgpu_asic_funcs nv_asic_funcs = |
| 530 | { |
| 531 | .read_disabled_bios = &nv_read_disabled_bios, |
| 532 | .read_bios_from_rom = &nv_read_bios_from_rom, |
| 533 | .read_register = &nv_read_register, |
| 534 | .reset = &nv_asic_reset, |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 535 | .reset_method = &nv_asic_reset_method, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 536 | .set_vga_state = &nv_vga_set_state, |
| 537 | .get_xclk = &nv_get_xclk, |
| 538 | .set_uvd_clocks = &nv_set_uvd_clocks, |
| 539 | .set_vce_clocks = &nv_set_vce_clocks, |
| 540 | .get_config_memsize = &nv_get_config_memsize, |
| 541 | .flush_hdp = &nv_flush_hdp, |
| 542 | .invalidate_hdp = &nv_invalidate_hdp, |
| 543 | .init_doorbell_index = &nv_init_doorbell_index, |
| 544 | .need_full_reset = &nv_need_full_reset, |
| 545 | .get_pcie_usage = &nv_get_pcie_usage, |
| 546 | .need_reset_on_init = &nv_need_reset_on_init, |
| 547 | }; |
| 548 | |
| 549 | static int nv_common_early_init(void *handle) |
| 550 | { |
| 551 | bool psp_enabled = false; |
| 552 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 553 | |
| 554 | adev->smc_rreg = NULL; |
| 555 | adev->smc_wreg = NULL; |
| 556 | adev->pcie_rreg = &nv_pcie_rreg; |
| 557 | adev->pcie_wreg = &nv_pcie_wreg; |
| 558 | |
| 559 | /* TODO: will add them during VCN v2 implementation */ |
| 560 | adev->uvd_ctx_rreg = NULL; |
| 561 | adev->uvd_ctx_wreg = NULL; |
| 562 | |
| 563 | adev->didt_rreg = &nv_didt_rreg; |
| 564 | adev->didt_wreg = &nv_didt_wreg; |
| 565 | |
| 566 | adev->asic_funcs = &nv_asic_funcs; |
| 567 | |
| 568 | if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) && |
| 569 | (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP))) |
| 570 | psp_enabled = true; |
| 571 | |
| 572 | adev->rev_id = nv_get_rev_id(adev); |
| 573 | adev->external_rev_id = 0xff; |
| 574 | switch (adev->asic_type) { |
| 575 | case CHIP_NAVI10: |
| 576 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 577 | AMD_CG_SUPPORT_GFX_CGCG | |
| 578 | AMD_CG_SUPPORT_IH_CG | |
| 579 | AMD_CG_SUPPORT_HDP_MGCG | |
| 580 | AMD_CG_SUPPORT_HDP_LS | |
| 581 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 582 | AMD_CG_SUPPORT_SDMA_LS | |
| 583 | AMD_CG_SUPPORT_MC_MGCG | |
| 584 | AMD_CG_SUPPORT_MC_LS | |
| 585 | AMD_CG_SUPPORT_ATHUB_MGCG | |
| 586 | AMD_CG_SUPPORT_ATHUB_LS | |
| 587 | AMD_CG_SUPPORT_VCN_MGCG | |
| 588 | AMD_CG_SUPPORT_BIF_MGCG | |
| 589 | AMD_CG_SUPPORT_BIF_LS; |
Leo Liu | 157710e | 2019-05-15 13:58:20 -0400 | [diff] [blame] | 590 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Huang Rui | c12d410 | 2019-06-14 16:12:51 +0800 | [diff] [blame] | 591 | AMD_PG_SUPPORT_VCN_DPG | |
Huang Rui | a201b6a | 2019-06-14 16:19:36 +0800 | [diff] [blame] | 592 | AMD_PG_SUPPORT_MMHUB | |
| 593 | AMD_PG_SUPPORT_ATHUB; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 594 | adev->external_rev_id = adev->rev_id + 0x1; |
| 595 | break; |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 596 | case CHIP_NAVI14: |
Xiaojie Yuan | d0c39f8 | 2019-03-20 16:12:54 +0800 | [diff] [blame] | 597 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 598 | AMD_CG_SUPPORT_GFX_CGCG | |
| 599 | AMD_CG_SUPPORT_IH_CG | |
| 600 | AMD_CG_SUPPORT_HDP_MGCG | |
| 601 | AMD_CG_SUPPORT_HDP_LS | |
| 602 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 603 | AMD_CG_SUPPORT_SDMA_LS | |
| 604 | AMD_CG_SUPPORT_MC_MGCG | |
| 605 | AMD_CG_SUPPORT_MC_LS | |
| 606 | AMD_CG_SUPPORT_ATHUB_MGCG | |
| 607 | AMD_CG_SUPPORT_ATHUB_LS | |
| 608 | AMD_CG_SUPPORT_VCN_MGCG | |
| 609 | AMD_CG_SUPPORT_BIF_MGCG | |
| 610 | AMD_CG_SUPPORT_BIF_LS; |
Xiaojie Yuan | 0377b08 | 2019-07-02 12:52:52 -0500 | [diff] [blame] | 611 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
| 612 | AMD_PG_SUPPORT_VCN_DPG; |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 613 | adev->external_rev_id = adev->rev_id + 0x1; /* ??? */ |
| 614 | break; |
Xiaojie Yuan | 74b5e50 | 2019-05-16 19:47:33 +0800 | [diff] [blame] | 615 | case CHIP_NAVI12: |
| 616 | adev->cg_flags = 0; |
| 617 | adev->pg_flags = 0; |
| 618 | adev->external_rev_id = adev->rev_id + 0xa; |
| 619 | break; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 620 | default: |
| 621 | /* FIXME: not supported yet */ |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static int nv_common_late_init(void *handle) |
| 629 | { |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static int nv_common_sw_init(void *handle) |
| 634 | { |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static int nv_common_sw_fini(void *handle) |
| 639 | { |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int nv_common_hw_init(void *handle) |
| 644 | { |
| 645 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 646 | |
| 647 | /* enable pcie gen2/3 link */ |
| 648 | nv_pcie_gen3_enable(adev); |
| 649 | /* enable aspm */ |
| 650 | nv_program_aspm(adev); |
| 651 | /* setup nbio registers */ |
| 652 | adev->nbio_funcs->init_registers(adev); |
| 653 | /* enable the doorbell aperture */ |
| 654 | nv_enable_doorbell_aperture(adev, true); |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static int nv_common_hw_fini(void *handle) |
| 660 | { |
| 661 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 662 | |
| 663 | /* disable the doorbell aperture */ |
| 664 | nv_enable_doorbell_aperture(adev, false); |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static int nv_common_suspend(void *handle) |
| 670 | { |
| 671 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 672 | |
| 673 | return nv_common_hw_fini(adev); |
| 674 | } |
| 675 | |
| 676 | static int nv_common_resume(void *handle) |
| 677 | { |
| 678 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 679 | |
| 680 | return nv_common_hw_init(adev); |
| 681 | } |
| 682 | |
| 683 | static bool nv_common_is_idle(void *handle) |
| 684 | { |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | static int nv_common_wait_for_idle(void *handle) |
| 689 | { |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int nv_common_soft_reset(void *handle) |
| 694 | { |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev, |
| 699 | bool enable) |
| 700 | { |
| 701 | uint32_t hdp_clk_cntl, hdp_clk_cntl1; |
| 702 | uint32_t hdp_mem_pwr_cntl; |
| 703 | |
| 704 | if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | |
| 705 | AMD_CG_SUPPORT_HDP_DS | |
| 706 | AMD_CG_SUPPORT_HDP_SD))) |
| 707 | return; |
| 708 | |
| 709 | hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 710 | hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL); |
| 711 | |
| 712 | /* Before doing clock/power mode switch, |
| 713 | * forced on IPH & RC clock */ |
| 714 | hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL, |
| 715 | IPH_MEM_CLK_SOFT_OVERRIDE, 1); |
| 716 | hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL, |
| 717 | RC_MEM_CLK_SOFT_OVERRIDE, 1); |
| 718 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl); |
| 719 | |
| 720 | /* HDP 5.0 doesn't support dynamic power mode switch, |
| 721 | * disable clock and power gating before any changing */ |
| 722 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 723 | IPH_MEM_POWER_CTRL_EN, 0); |
| 724 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 725 | IPH_MEM_POWER_LS_EN, 0); |
| 726 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 727 | IPH_MEM_POWER_DS_EN, 0); |
| 728 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 729 | IPH_MEM_POWER_SD_EN, 0); |
| 730 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 731 | RC_MEM_POWER_CTRL_EN, 0); |
| 732 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 733 | RC_MEM_POWER_LS_EN, 0); |
| 734 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 735 | RC_MEM_POWER_DS_EN, 0); |
| 736 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 737 | RC_MEM_POWER_SD_EN, 0); |
| 738 | WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl); |
| 739 | |
| 740 | /* only one clock gating mode (LS/DS/SD) can be enabled */ |
| 741 | if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) { |
| 742 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 743 | HDP_MEM_POWER_CTRL, |
| 744 | IPH_MEM_POWER_LS_EN, enable); |
| 745 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 746 | HDP_MEM_POWER_CTRL, |
| 747 | RC_MEM_POWER_LS_EN, enable); |
| 748 | } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) { |
| 749 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 750 | HDP_MEM_POWER_CTRL, |
| 751 | IPH_MEM_POWER_DS_EN, enable); |
| 752 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 753 | HDP_MEM_POWER_CTRL, |
| 754 | RC_MEM_POWER_DS_EN, enable); |
| 755 | } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) { |
| 756 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 757 | HDP_MEM_POWER_CTRL, |
| 758 | IPH_MEM_POWER_SD_EN, enable); |
| 759 | /* RC should not use shut down mode, fallback to ds */ |
| 760 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 761 | HDP_MEM_POWER_CTRL, |
| 762 | RC_MEM_POWER_DS_EN, enable); |
| 763 | } |
| 764 | |
| 765 | WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl); |
| 766 | |
| 767 | /* restore IPH & RC clock override after clock/power mode changing */ |
| 768 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1); |
| 769 | } |
| 770 | |
| 771 | static void nv_update_hdp_clock_gating(struct amdgpu_device *adev, |
| 772 | bool enable) |
| 773 | { |
| 774 | uint32_t hdp_clk_cntl; |
| 775 | |
| 776 | if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG)) |
| 777 | return; |
| 778 | |
| 779 | hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 780 | |
| 781 | if (enable) { |
| 782 | hdp_clk_cntl &= |
| 783 | ~(uint32_t) |
| 784 | (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 785 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 786 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 787 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 788 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 789 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK); |
| 790 | } else { |
| 791 | hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 792 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 793 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 794 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 795 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 796 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK; |
| 797 | } |
| 798 | |
| 799 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl); |
| 800 | } |
| 801 | |
| 802 | static int nv_common_set_clockgating_state(void *handle, |
| 803 | enum amd_clockgating_state state) |
| 804 | { |
| 805 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 806 | |
| 807 | if (amdgpu_sriov_vf(adev)) |
| 808 | return 0; |
| 809 | |
| 810 | switch (adev->asic_type) { |
| 811 | case CHIP_NAVI10: |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 812 | case CHIP_NAVI14: |
Xiaojie Yuan | 7e17e58 | 2019-05-16 19:51:12 +0800 | [diff] [blame] | 813 | case CHIP_NAVI12: |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 814 | adev->nbio_funcs->update_medium_grain_clock_gating(adev, |
| 815 | state == AMD_CG_STATE_GATE ? true : false); |
| 816 | adev->nbio_funcs->update_medium_grain_light_sleep(adev, |
| 817 | state == AMD_CG_STATE_GATE ? true : false); |
| 818 | nv_update_hdp_mem_power_gating(adev, |
| 819 | state == AMD_CG_STATE_GATE ? true : false); |
| 820 | nv_update_hdp_clock_gating(adev, |
| 821 | state == AMD_CG_STATE_GATE ? true : false); |
| 822 | break; |
| 823 | default: |
| 824 | break; |
| 825 | } |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | static int nv_common_set_powergating_state(void *handle, |
| 830 | enum amd_powergating_state state) |
| 831 | { |
| 832 | /* TODO */ |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static void nv_common_get_clockgating_state(void *handle, u32 *flags) |
| 837 | { |
| 838 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 839 | uint32_t tmp; |
| 840 | |
| 841 | if (amdgpu_sriov_vf(adev)) |
| 842 | *flags = 0; |
| 843 | |
| 844 | adev->nbio_funcs->get_clockgating_state(adev, flags); |
| 845 | |
| 846 | /* AMD_CG_SUPPORT_HDP_MGCG */ |
| 847 | tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 848 | if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 849 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 850 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 851 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 852 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 853 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK))) |
| 854 | *flags |= AMD_CG_SUPPORT_HDP_MGCG; |
| 855 | |
| 856 | /* AMD_CG_SUPPORT_HDP_LS/DS/SD */ |
| 857 | tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL); |
| 858 | if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK) |
| 859 | *flags |= AMD_CG_SUPPORT_HDP_LS; |
| 860 | else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK) |
| 861 | *flags |= AMD_CG_SUPPORT_HDP_DS; |
| 862 | else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK) |
| 863 | *flags |= AMD_CG_SUPPORT_HDP_SD; |
| 864 | |
| 865 | return; |
| 866 | } |
| 867 | |
| 868 | static const struct amd_ip_funcs nv_common_ip_funcs = { |
| 869 | .name = "nv_common", |
| 870 | .early_init = nv_common_early_init, |
| 871 | .late_init = nv_common_late_init, |
| 872 | .sw_init = nv_common_sw_init, |
| 873 | .sw_fini = nv_common_sw_fini, |
| 874 | .hw_init = nv_common_hw_init, |
| 875 | .hw_fini = nv_common_hw_fini, |
| 876 | .suspend = nv_common_suspend, |
| 877 | .resume = nv_common_resume, |
| 878 | .is_idle = nv_common_is_idle, |
| 879 | .wait_for_idle = nv_common_wait_for_idle, |
| 880 | .soft_reset = nv_common_soft_reset, |
| 881 | .set_clockgating_state = nv_common_set_clockgating_state, |
| 882 | .set_powergating_state = nv_common_set_powergating_state, |
| 883 | .get_clockgating_state = nv_common_get_clockgating_state, |
| 884 | }; |