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" |
Alex Deucher | 29bc37b | 2019-11-13 14:27:54 -0500 | [diff] [blame] | 43 | #include "smuio/smuio_11_0_0_offset.h" |
Alex Deucher | 3967ae6 | 2020-05-28 17:28:17 -0400 | [diff] [blame] | 44 | #include "mp/mp_11_0_offset.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 45 | |
| 46 | #include "soc15.h" |
| 47 | #include "soc15_common.h" |
| 48 | #include "gmc_v10_0.h" |
| 49 | #include "gfxhub_v2_0.h" |
| 50 | #include "mmhub_v2_0.h" |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 51 | #include "nbio_v2_3.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 52 | #include "nv.h" |
| 53 | #include "navi10_ih.h" |
| 54 | #include "gfx_v10_0.h" |
| 55 | #include "sdma_v5_0.h" |
Likun Gao | 157e72e | 2019-06-17 13:38:29 +0800 | [diff] [blame] | 56 | #include "sdma_v5_2.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 57 | #include "vcn_v2_0.h" |
Leo Liu | 5be45a2 | 2019-11-08 15:01:42 -0500 | [diff] [blame] | 58 | #include "jpeg_v2_0.h" |
Leo Liu | b8f1058 | 2020-03-24 16:30:24 -0400 | [diff] [blame] | 59 | #include "vcn_v3_0.h" |
Leo Liu | 4d72dd1 | 2020-03-24 16:31:23 -0400 | [diff] [blame] | 60 | #include "jpeg_v3_0.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 61 | #include "dce_virtual.h" |
| 62 | #include "mes_v10_1.h" |
Jiange Zhao | b05b690 | 2019-09-11 17:29:07 +0800 | [diff] [blame] | 63 | #include "mxgpu_nv.h" |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 64 | |
| 65 | static const struct amd_ip_funcs nv_common_ip_funcs; |
| 66 | |
| 67 | /* |
| 68 | * Indirect registers accessor |
| 69 | */ |
| 70 | static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg) |
| 71 | { |
| 72 | unsigned long flags, address, data; |
| 73 | u32 r; |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 74 | address = adev->nbio.funcs->get_pcie_index_offset(adev); |
| 75 | data = adev->nbio.funcs->get_pcie_data_offset(adev); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 76 | |
| 77 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 78 | WREG32(address, reg); |
| 79 | (void)RREG32(address); |
| 80 | r = RREG32(data); |
| 81 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 82 | return r; |
| 83 | } |
| 84 | |
| 85 | static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 86 | { |
| 87 | unsigned long flags, address, data; |
| 88 | |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 89 | address = adev->nbio.funcs->get_pcie_index_offset(adev); |
| 90 | data = adev->nbio.funcs->get_pcie_data_offset(adev); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 91 | |
| 92 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 93 | WREG32(address, reg); |
| 94 | (void)RREG32(address); |
| 95 | WREG32(data, v); |
| 96 | (void)RREG32(data); |
| 97 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 98 | } |
| 99 | |
| 100 | static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg) |
| 101 | { |
| 102 | unsigned long flags, address, data; |
| 103 | u32 r; |
| 104 | |
| 105 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 106 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 107 | |
| 108 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 109 | WREG32(address, (reg)); |
| 110 | r = RREG32(data); |
| 111 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 112 | return r; |
| 113 | } |
| 114 | |
| 115 | static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 116 | { |
| 117 | unsigned long flags, address, data; |
| 118 | |
| 119 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 120 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 121 | |
| 122 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 123 | WREG32(address, (reg)); |
| 124 | WREG32(data, (v)); |
| 125 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 126 | } |
| 127 | |
| 128 | static u32 nv_get_config_memsize(struct amdgpu_device *adev) |
| 129 | { |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 130 | return adev->nbio.funcs->get_memsize(adev); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static u32 nv_get_xclk(struct amdgpu_device *adev) |
| 134 | { |
Tao Zhou | 462a70d | 2019-05-14 11:37:32 +0800 | [diff] [blame] | 135 | return adev->clock.spll.reference_freq; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
| 139 | void nv_grbm_select(struct amdgpu_device *adev, |
| 140 | u32 me, u32 pipe, u32 queue, u32 vmid) |
| 141 | { |
| 142 | u32 grbm_gfx_cntl = 0; |
| 143 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe); |
| 144 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me); |
| 145 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid); |
| 146 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue); |
| 147 | |
| 148 | WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl); |
| 149 | } |
| 150 | |
| 151 | static void nv_vga_set_state(struct amdgpu_device *adev, bool state) |
| 152 | { |
| 153 | /* todo */ |
| 154 | } |
| 155 | |
| 156 | static bool nv_read_disabled_bios(struct amdgpu_device *adev) |
| 157 | { |
| 158 | /* todo */ |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | static bool nv_read_bios_from_rom(struct amdgpu_device *adev, |
| 163 | u8 *bios, u32 length_bytes) |
| 164 | { |
Alex Deucher | 29bc37b | 2019-11-13 14:27:54 -0500 | [diff] [blame] | 165 | u32 *dw_ptr; |
| 166 | u32 i, length_dw; |
| 167 | |
| 168 | if (bios == NULL) |
| 169 | return false; |
| 170 | if (length_bytes == 0) |
| 171 | return false; |
| 172 | /* APU vbios image is part of sbios image */ |
| 173 | if (adev->flags & AMD_IS_APU) |
| 174 | return false; |
| 175 | |
| 176 | dw_ptr = (u32 *)bios; |
| 177 | length_dw = ALIGN(length_bytes, 4) / 4; |
| 178 | |
| 179 | /* set rom index to 0 */ |
| 180 | WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0); |
| 181 | /* read out the rom data */ |
| 182 | for (i = 0; i < length_dw; i++) |
| 183 | dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA)); |
| 184 | |
| 185 | return true; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static struct soc15_allowed_register_entry nv_allowed_read_registers[] = { |
| 189 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)}, |
| 190 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)}, |
| 191 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)}, |
| 192 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)}, |
| 193 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)}, |
| 194 | { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)}, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 195 | { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)}, |
| 196 | { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)}, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 197 | { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)}, |
| 198 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)}, |
| 199 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)}, |
| 200 | { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)}, |
| 201 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)}, |
| 202 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)}, |
| 203 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)}, |
Marek Olšák | 664fe85 | 2019-10-22 17:22:38 -0400 | [diff] [blame] | 204 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)}, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 205 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)}, |
| 206 | { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)}, |
| 207 | { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)}, |
| 208 | }; |
| 209 | |
| 210 | static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num, |
| 211 | u32 sh_num, u32 reg_offset) |
| 212 | { |
| 213 | uint32_t val; |
| 214 | |
| 215 | mutex_lock(&adev->grbm_idx_mutex); |
| 216 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 217 | amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff); |
| 218 | |
| 219 | val = RREG32(reg_offset); |
| 220 | |
| 221 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 222 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 223 | mutex_unlock(&adev->grbm_idx_mutex); |
| 224 | return val; |
| 225 | } |
| 226 | |
| 227 | static uint32_t nv_get_register_value(struct amdgpu_device *adev, |
| 228 | bool indexed, u32 se_num, |
| 229 | u32 sh_num, u32 reg_offset) |
| 230 | { |
| 231 | if (indexed) { |
| 232 | return nv_read_indexed_register(adev, se_num, sh_num, reg_offset); |
| 233 | } else { |
| 234 | if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)) |
| 235 | return adev->gfx.config.gb_addr_config; |
| 236 | return RREG32(reg_offset); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | static int nv_read_register(struct amdgpu_device *adev, u32 se_num, |
| 241 | u32 sh_num, u32 reg_offset, u32 *value) |
| 242 | { |
| 243 | uint32_t i; |
| 244 | struct soc15_allowed_register_entry *en; |
| 245 | |
| 246 | *value = 0; |
| 247 | for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) { |
| 248 | en = &nv_allowed_read_registers[i]; |
| 249 | if (reg_offset != |
| 250 | (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset)) |
| 251 | continue; |
| 252 | |
| 253 | *value = nv_get_register_value(adev, |
| 254 | nv_allowed_read_registers[i].grbm_indexed, |
| 255 | se_num, sh_num, reg_offset); |
| 256 | return 0; |
| 257 | } |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 261 | static int nv_asic_mode1_reset(struct amdgpu_device *adev) |
| 262 | { |
| 263 | u32 i; |
| 264 | int ret = 0; |
| 265 | |
| 266 | amdgpu_atombios_scratch_regs_engine_hung(adev, true); |
| 267 | |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 268 | /* disable BM */ |
| 269 | pci_clear_master(adev->pdev); |
| 270 | |
| 271 | pci_save_state(adev->pdev); |
| 272 | |
Wenhui Sheng | 311531f | 2020-07-13 15:15:11 +0800 | [diff] [blame] | 273 | if (amdgpu_dpm_is_mode1_reset_supported(adev)) { |
| 274 | dev_info(adev->dev, "GPU smu mode1 reset\n"); |
| 275 | ret = amdgpu_dpm_mode1_reset(adev); |
| 276 | } else { |
| 277 | dev_info(adev->dev, "GPU psp mode1 reset\n"); |
| 278 | ret = psp_gpu_reset(adev); |
| 279 | } |
| 280 | |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 281 | if (ret) |
| 282 | dev_err(adev->dev, "GPU mode1 reset failed\n"); |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 283 | pci_restore_state(adev->pdev); |
| 284 | |
| 285 | /* wait for asic to come out of reset */ |
| 286 | for (i = 0; i < adev->usec_timeout; i++) { |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 287 | u32 memsize = adev->nbio.funcs->get_memsize(adev); |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 288 | |
| 289 | if (memsize != 0xffffffff) |
| 290 | break; |
| 291 | udelay(1); |
| 292 | } |
| 293 | |
| 294 | amdgpu_atombios_scratch_regs_engine_hung(adev, false); |
| 295 | |
| 296 | return ret; |
| 297 | } |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 298 | |
Alex Deucher | ac74261 | 2019-11-07 18:12:17 -0500 | [diff] [blame] | 299 | static bool nv_asic_supports_baco(struct amdgpu_device *adev) |
| 300 | { |
| 301 | struct smu_context *smu = &adev->smu; |
| 302 | |
| 303 | if (smu_baco_is_support(smu)) |
| 304 | return true; |
| 305 | else |
| 306 | return false; |
| 307 | } |
| 308 | |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 309 | static enum amd_reset_method |
| 310 | nv_asic_reset_method(struct amdgpu_device *adev) |
| 311 | { |
| 312 | struct smu_context *smu = &adev->smu; |
| 313 | |
Wenhui Sheng | 273da6f | 2020-07-14 16:29:18 +0800 | [diff] [blame] | 314 | if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 || |
| 315 | amdgpu_reset_method == AMD_RESET_METHOD_BACO) |
| 316 | return amdgpu_reset_method; |
| 317 | |
| 318 | if (amdgpu_reset_method != -1) |
| 319 | dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n", |
| 320 | amdgpu_reset_method); |
| 321 | |
Wenhui Sheng | 311531f | 2020-07-13 15:15:11 +0800 | [diff] [blame] | 322 | if (smu_baco_is_support(smu)) |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 323 | return AMD_RESET_METHOD_BACO; |
| 324 | else |
| 325 | return AMD_RESET_METHOD_MODE1; |
| 326 | } |
| 327 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 328 | static int nv_asic_reset(struct amdgpu_device *adev) |
| 329 | { |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 330 | int ret = 0; |
| 331 | struct smu_context *smu = &adev->smu; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 332 | |
Monk Liu | e352625 | 2019-08-27 16:32:55 +0800 | [diff] [blame] | 333 | if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) { |
Wenhui Sheng | 311531f | 2020-07-13 15:15:11 +0800 | [diff] [blame] | 334 | dev_info(adev->dev, "GPU BACO reset\n"); |
| 335 | |
Alex Deucher | 11520f2 | 2019-10-28 15:20:03 -0400 | [diff] [blame] | 336 | ret = smu_baco_enter(smu); |
| 337 | if (ret) |
| 338 | return ret; |
| 339 | ret = smu_baco_exit(smu); |
| 340 | if (ret) |
| 341 | return ret; |
Wenhui Sheng | 311531f | 2020-07-13 15:15:11 +0800 | [diff] [blame] | 342 | } else |
Kevin Wang | 3e2bb60 | 2019-07-05 12:51:45 +0800 | [diff] [blame] | 343 | ret = nv_asic_mode1_reset(adev); |
Kevin Wang | 767acab | 2019-07-05 15:58:46 -0500 | [diff] [blame] | 344 | |
| 345 | return ret; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk) |
| 349 | { |
| 350 | /* todo */ |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk) |
| 355 | { |
| 356 | /* todo */ |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static void nv_pcie_gen3_enable(struct amdgpu_device *adev) |
| 361 | { |
| 362 | if (pci_is_root_bus(adev->pdev->bus)) |
| 363 | return; |
| 364 | |
| 365 | if (amdgpu_pcie_gen2 == 0) |
| 366 | return; |
| 367 | |
| 368 | if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 369 | CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3))) |
| 370 | return; |
| 371 | |
| 372 | /* todo */ |
| 373 | } |
| 374 | |
| 375 | static void nv_program_aspm(struct amdgpu_device *adev) |
| 376 | { |
| 377 | |
| 378 | if (amdgpu_aspm == 0) |
| 379 | return; |
| 380 | |
| 381 | /* todo */ |
| 382 | } |
| 383 | |
| 384 | static void nv_enable_doorbell_aperture(struct amdgpu_device *adev, |
| 385 | bool enable) |
| 386 | { |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 387 | adev->nbio.funcs->enable_doorbell_aperture(adev, enable); |
| 388 | adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static const struct amdgpu_ip_block_version nv_common_ip_block = |
| 392 | { |
| 393 | .type = AMD_IP_BLOCK_TYPE_COMMON, |
| 394 | .major = 1, |
| 395 | .minor = 0, |
| 396 | .rev = 0, |
| 397 | .funcs = &nv_common_ip_funcs, |
| 398 | }; |
| 399 | |
Xiaojie Yuan | b5c7385 | 2019-08-05 16:19:45 +0800 | [diff] [blame] | 400 | static int nv_reg_base_init(struct amdgpu_device *adev) |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 401 | { |
Xiaojie Yuan | b5c7385 | 2019-08-05 16:19:45 +0800 | [diff] [blame] | 402 | int r; |
| 403 | |
| 404 | if (amdgpu_discovery) { |
| 405 | r = amdgpu_discovery_reg_base_init(adev); |
| 406 | if (r) { |
| 407 | DRM_WARN("failed to init reg base from ip discovery table, " |
| 408 | "fallback to legacy init method\n"); |
| 409 | goto legacy_init; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | legacy_init: |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 416 | switch (adev->asic_type) { |
| 417 | case CHIP_NAVI10: |
| 418 | navi10_reg_base_init(adev); |
| 419 | break; |
Xiaojie Yuan | a0f6d926 | 2018-12-17 18:24:03 +0800 | [diff] [blame] | 420 | case CHIP_NAVI14: |
| 421 | navi14_reg_base_init(adev); |
| 422 | break; |
Xiaojie Yuan | 03d0a07 | 2019-05-14 15:22:53 +0800 | [diff] [blame] | 423 | case CHIP_NAVI12: |
| 424 | navi12_reg_base_init(adev); |
| 425 | break; |
Likun Gao | dccdbf3 | 2019-11-07 16:28:14 +0800 | [diff] [blame] | 426 | case CHIP_SIENNA_CICHLID: |
Jiansong Chen | c8c959f | 2020-02-11 14:00:39 +0800 | [diff] [blame] | 427 | case CHIP_NAVY_FLOUNDER: |
Likun Gao | dccdbf3 | 2019-11-07 16:28:14 +0800 | [diff] [blame] | 428 | sienna_cichlid_reg_base_init(adev); |
| 429 | break; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 430 | default: |
| 431 | return -EINVAL; |
| 432 | } |
| 433 | |
Xiaojie Yuan | b5c7385 | 2019-08-05 16:19:45 +0800 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Wenhui Sheng | c129946 | 2020-06-23 11:35:05 +0800 | [diff] [blame] | 437 | void nv_set_virt_ops(struct amdgpu_device *adev) |
| 438 | { |
| 439 | adev->virt.ops = &xgpu_nv_virt_ops; |
| 440 | } |
| 441 | |
Xiaojie Yuan | b5c7385 | 2019-08-05 16:19:45 +0800 | [diff] [blame] | 442 | int nv_set_ip_blocks(struct amdgpu_device *adev) |
| 443 | { |
| 444 | int r; |
| 445 | |
Monk Liu | 122078d | 2020-03-04 23:51:51 +0800 | [diff] [blame] | 446 | adev->nbio.funcs = &nbio_v2_3_funcs; |
| 447 | adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg; |
| 448 | |
Xiaojie Yuan | b5c7385 | 2019-08-05 16:19:45 +0800 | [diff] [blame] | 449 | /* Set IP register base before any HW register access */ |
| 450 | r = nv_reg_base_init(adev); |
| 451 | if (r) |
| 452 | return r; |
| 453 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 454 | switch (adev->asic_type) { |
| 455 | case CHIP_NAVI10: |
Alex Deucher | d1daf85 | 2019-07-02 14:42:25 -0500 | [diff] [blame] | 456 | case CHIP_NAVI14: |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 457 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
| 458 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
| 459 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
| 460 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
| 461 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP && |
Evan Quan | 9530273 | 2020-01-07 16:57:39 +0800 | [diff] [blame] | 462 | !amdgpu_sriov_vf(adev)) |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 463 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
| 464 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 465 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Alex Deucher | f8a7976 | 2019-07-05 15:39:39 -0500 | [diff] [blame] | 466 | #if defined(CONFIG_DRM_AMD_DC) |
Harry Wentland | b4f199c | 2019-02-26 16:25:27 -0500 | [diff] [blame] | 467 | else if (amdgpu_device_has_dc_support(adev)) |
| 468 | amdgpu_device_ip_block_add(adev, &dm_ip_block); |
Alex Deucher | f8a7976 | 2019-07-05 15:39:39 -0500 | [diff] [blame] | 469 | #endif |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 470 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
| 471 | amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block); |
| 472 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && |
Evan Quan | 9530273 | 2020-01-07 16:57:39 +0800 | [diff] [blame] | 473 | !amdgpu_sriov_vf(adev)) |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 474 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
| 475 | amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block); |
Leo Liu | 5be45a2 | 2019-11-08 15:01:42 -0500 | [diff] [blame] | 476 | amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 477 | if (adev->enable_mes) |
| 478 | amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block); |
| 479 | break; |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 480 | case CHIP_NAVI12: |
| 481 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
| 482 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
| 483 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
Xiaojie Yuan | 6b66ae2 | 2019-07-18 02:54:29 +0800 | [diff] [blame] | 484 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
Monk Liu | 79bebab | 2020-04-22 12:09:16 +0800 | [diff] [blame] | 485 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) |
Xiaojie Yuan | 7f47efe | 2019-07-16 03:26:49 +0800 | [diff] [blame] | 486 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Xiaojie Yuan | 7990202 | 2019-06-26 19:19:57 +0800 | [diff] [blame] | 487 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 488 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Petr Cvek | 20c14ee | 2019-08-30 16:31:58 +0200 | [diff] [blame] | 489 | #if defined(CONFIG_DRM_AMD_DC) |
Leo Li | 078655d9 | 2019-07-16 18:12:13 -0400 | [diff] [blame] | 490 | else if (amdgpu_device_has_dc_support(adev)) |
| 491 | amdgpu_device_ip_block_add(adev, &dm_ip_block); |
Petr Cvek | 20c14ee | 2019-08-30 16:31:58 +0200 | [diff] [blame] | 492 | #endif |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 493 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
| 494 | amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block); |
Xiaojie Yuan | 7f47efe | 2019-07-16 03:26:49 +0800 | [diff] [blame] | 495 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && |
Evan Quan | 9530273 | 2020-01-07 16:57:39 +0800 | [diff] [blame] | 496 | !amdgpu_sriov_vf(adev)) |
Xiaojie Yuan | 7f47efe | 2019-07-16 03:26:49 +0800 | [diff] [blame] | 497 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Boyuan Zhang | 1fbed28 | 2019-07-18 10:13:23 -0400 | [diff] [blame] | 498 | amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block); |
Monk Liu | fe44249 | 2020-03-05 21:10:03 +0800 | [diff] [blame] | 499 | if (!amdgpu_sriov_vf(adev)) |
| 500 | amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block); |
Xiaojie Yuan | 44e9e7c | 2019-05-16 19:58:19 +0800 | [diff] [blame] | 501 | break; |
Likun Gao | 2e1ba10 | 2019-04-18 13:49:07 +0800 | [diff] [blame] | 502 | case CHIP_SIENNA_CICHLID: |
| 503 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
Likun Gao | 0b3df16 | 2019-06-16 22:34:59 +0800 | [diff] [blame] | 504 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
Likun Gao | 757b3af | 2019-06-16 22:37:56 +0800 | [diff] [blame] | 505 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
Likun Gao | 56304e7 | 2020-03-24 16:27:43 -0400 | [diff] [blame] | 506 | if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) |
| 507 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
Likun Gao | b07e5c6 | 2020-03-24 16:24:44 -0400 | [diff] [blame] | 508 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP && |
shaoyunl | 38d5bbe | 2020-03-17 11:41:34 -0400 | [diff] [blame] | 509 | is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev)) |
Likun Gao | b07e5c6 | 2020-03-24 16:24:44 -0400 | [diff] [blame] | 510 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Likun Gao | 9a98676 | 2019-08-14 17:39:03 +0800 | [diff] [blame] | 511 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 512 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Bhawanpreet Lakha | 464ab91 | 2020-05-21 12:57:27 -0400 | [diff] [blame] | 513 | #if defined(CONFIG_DRM_AMD_DC) |
| 514 | else if (amdgpu_device_has_dc_support(adev)) |
| 515 | amdgpu_device_ip_block_add(adev, &dm_ip_block); |
| 516 | #endif |
Likun Gao | 933c8a9 | 2020-05-01 10:21:23 -0400 | [diff] [blame] | 517 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
Likun Gao | 157e72e | 2019-06-17 13:38:29 +0800 | [diff] [blame] | 518 | amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block); |
Leo Liu | b8f1058 | 2020-03-24 16:30:24 -0400 | [diff] [blame] | 519 | amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block); |
Jack Zhang | c45fbe1 | 2020-06-23 19:36:24 +0800 | [diff] [blame] | 520 | if (!amdgpu_sriov_vf(adev)) |
| 521 | amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block); |
| 522 | |
Jack Xiao | a346ef8 | 2020-03-24 16:28:43 -0400 | [diff] [blame] | 523 | if (adev->enable_mes) |
| 524 | amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block); |
Likun Gao | 2e1ba10 | 2019-04-18 13:49:07 +0800 | [diff] [blame] | 525 | break; |
Jiansong Chen | 8515e0a | 2020-02-12 21:47:47 +0800 | [diff] [blame] | 526 | case CHIP_NAVY_FLOUNDER: |
| 527 | amdgpu_device_ip_block_add(adev, &nv_common_ip_block); |
Jiansong Chen | fc8f07d | 2020-02-12 22:19:37 +0800 | [diff] [blame] | 528 | amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block); |
Jiansong Chen | 026c396 | 2020-02-12 22:32:01 +0800 | [diff] [blame] | 529 | amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block); |
Jiansong Chen | 7420eab2 | 2020-07-08 17:07:26 -0400 | [diff] [blame] | 530 | if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) |
| 531 | amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block); |
| 532 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP && |
| 533 | is_support_sw_smu(adev)) |
| 534 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Jiansong Chen | 5404f07 | 2020-02-24 14:28:34 +0800 | [diff] [blame] | 535 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 536 | amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block); |
Bhawanpreet Lakha | a6c5308 | 2020-07-08 17:11:12 -0400 | [diff] [blame] | 537 | #if defined(CONFIG_DRM_AMD_DC) |
| 538 | else if (amdgpu_device_has_dc_support(adev)) |
| 539 | amdgpu_device_ip_block_add(adev, &dm_ip_block); |
| 540 | #endif |
Jiansong Chen | 885eb3f | 2020-02-13 15:43:15 +0800 | [diff] [blame] | 541 | amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block); |
Jiansong Chen | df2d15d | 2020-02-14 16:19:13 +0800 | [diff] [blame] | 542 | amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block); |
Boyuan Zhang | 290b4ad | 2020-07-08 16:48:26 -0400 | [diff] [blame] | 543 | amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block); |
| 544 | amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block); |
Jiansong Chen | f4497d1 | 2020-04-15 11:20:19 +0800 | [diff] [blame] | 545 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT && |
| 546 | is_support_sw_smu(adev)) |
| 547 | amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block); |
Jiansong Chen | 8515e0a | 2020-02-12 21:47:47 +0800 | [diff] [blame] | 548 | break; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 549 | default: |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static uint32_t nv_get_rev_id(struct amdgpu_device *adev) |
| 557 | { |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 558 | return adev->nbio.funcs->get_rev_id(adev); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) |
| 562 | { |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 563 | adev->nbio.funcs->hdp_flush(adev, ring); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static void nv_invalidate_hdp(struct amdgpu_device *adev, |
| 567 | struct amdgpu_ring *ring) |
| 568 | { |
| 569 | if (!ring || !ring->funcs->emit_wreg) { |
| 570 | WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1); |
| 571 | } else { |
| 572 | amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET( |
| 573 | HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | static bool nv_need_full_reset(struct amdgpu_device *adev) |
| 578 | { |
| 579 | return true; |
| 580 | } |
| 581 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 582 | static bool nv_need_reset_on_init(struct amdgpu_device *adev) |
| 583 | { |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 584 | u32 sol_reg; |
| 585 | |
| 586 | if (adev->flags & AMD_IS_APU) |
| 587 | return false; |
| 588 | |
| 589 | /* Check sOS sign of life register to confirm sys driver and sOS |
| 590 | * are already been loaded. |
| 591 | */ |
| 592 | sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81); |
| 593 | if (sol_reg) |
| 594 | return true; |
Alex Deucher | 3967ae6 | 2020-05-28 17:28:17 -0400 | [diff] [blame] | 595 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 596 | return false; |
| 597 | } |
| 598 | |
Kevin Wang | 2af81531 | 2019-11-05 18:53:30 +0800 | [diff] [blame] | 599 | static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev) |
| 600 | { |
| 601 | |
| 602 | /* TODO |
| 603 | * dummy implement for pcie_replay_count sysfs interface |
| 604 | * */ |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 609 | static void nv_init_doorbell_index(struct amdgpu_device *adev) |
| 610 | { |
| 611 | adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ; |
| 612 | adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0; |
| 613 | adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1; |
| 614 | adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2; |
| 615 | adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3; |
| 616 | adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4; |
| 617 | adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5; |
| 618 | adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6; |
| 619 | adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7; |
| 620 | adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START; |
| 621 | adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END; |
| 622 | adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0; |
| 623 | adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1; |
Jack Xiao | 2051923 | 2019-04-26 18:58:41 +0800 | [diff] [blame] | 624 | adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 625 | adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0; |
| 626 | adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1; |
Likun Gao | 157e72e | 2019-06-17 13:38:29 +0800 | [diff] [blame] | 627 | adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2; |
| 628 | adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 629 | adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH; |
| 630 | adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1; |
| 631 | adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3; |
| 632 | adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5; |
| 633 | adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7; |
| 634 | adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP; |
| 635 | adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP; |
| 636 | |
| 637 | adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1; |
| 638 | adev->doorbell_index.sdma_doorbell_range = 20; |
| 639 | } |
| 640 | |
| 641 | static const struct amdgpu_asic_funcs nv_asic_funcs = |
| 642 | { |
| 643 | .read_disabled_bios = &nv_read_disabled_bios, |
| 644 | .read_bios_from_rom = &nv_read_bios_from_rom, |
| 645 | .read_register = &nv_read_register, |
| 646 | .reset = &nv_asic_reset, |
Alex Deucher | 2ddc6c3 | 2019-07-23 23:48:21 -0500 | [diff] [blame] | 647 | .reset_method = &nv_asic_reset_method, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 648 | .set_vga_state = &nv_vga_set_state, |
| 649 | .get_xclk = &nv_get_xclk, |
| 650 | .set_uvd_clocks = &nv_set_uvd_clocks, |
| 651 | .set_vce_clocks = &nv_set_vce_clocks, |
| 652 | .get_config_memsize = &nv_get_config_memsize, |
| 653 | .flush_hdp = &nv_flush_hdp, |
| 654 | .invalidate_hdp = &nv_invalidate_hdp, |
| 655 | .init_doorbell_index = &nv_init_doorbell_index, |
| 656 | .need_full_reset = &nv_need_full_reset, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 657 | .need_reset_on_init = &nv_need_reset_on_init, |
Kevin Wang | 2af81531 | 2019-11-05 18:53:30 +0800 | [diff] [blame] | 658 | .get_pcie_replay_count = &nv_get_pcie_replay_count, |
Alex Deucher | ac74261 | 2019-11-07 18:12:17 -0500 | [diff] [blame] | 659 | .supports_baco = &nv_asic_supports_baco, |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | static int nv_common_early_init(void *handle) |
| 663 | { |
Yong Zhao | 923c087 | 2019-09-27 23:30:05 -0400 | [diff] [blame] | 664 | #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE) |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 665 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 666 | |
Yong Zhao | 923c087 | 2019-09-27 23:30:05 -0400 | [diff] [blame] | 667 | adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET; |
| 668 | adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 669 | adev->smc_rreg = NULL; |
| 670 | adev->smc_wreg = NULL; |
| 671 | adev->pcie_rreg = &nv_pcie_rreg; |
| 672 | adev->pcie_wreg = &nv_pcie_wreg; |
| 673 | |
| 674 | /* TODO: will add them during VCN v2 implementation */ |
| 675 | adev->uvd_ctx_rreg = NULL; |
| 676 | adev->uvd_ctx_wreg = NULL; |
| 677 | |
| 678 | adev->didt_rreg = &nv_didt_rreg; |
| 679 | adev->didt_wreg = &nv_didt_wreg; |
| 680 | |
| 681 | adev->asic_funcs = &nv_asic_funcs; |
| 682 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 683 | adev->rev_id = nv_get_rev_id(adev); |
| 684 | adev->external_rev_id = 0xff; |
| 685 | switch (adev->asic_type) { |
| 686 | case CHIP_NAVI10: |
| 687 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 688 | AMD_CG_SUPPORT_GFX_CGCG | |
| 689 | AMD_CG_SUPPORT_IH_CG | |
| 690 | AMD_CG_SUPPORT_HDP_MGCG | |
| 691 | AMD_CG_SUPPORT_HDP_LS | |
| 692 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 693 | AMD_CG_SUPPORT_SDMA_LS | |
| 694 | AMD_CG_SUPPORT_MC_MGCG | |
| 695 | AMD_CG_SUPPORT_MC_LS | |
| 696 | AMD_CG_SUPPORT_ATHUB_MGCG | |
| 697 | AMD_CG_SUPPORT_ATHUB_LS | |
| 698 | AMD_CG_SUPPORT_VCN_MGCG | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 699 | AMD_CG_SUPPORT_JPEG_MGCG | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 700 | AMD_CG_SUPPORT_BIF_MGCG | |
| 701 | AMD_CG_SUPPORT_BIF_LS; |
Leo Liu | 157710e | 2019-05-15 13:58:20 -0400 | [diff] [blame] | 702 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Huang Rui | c12d410 | 2019-06-14 16:12:51 +0800 | [diff] [blame] | 703 | AMD_PG_SUPPORT_VCN_DPG | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 704 | AMD_PG_SUPPORT_JPEG | |
Huang Rui | a201b6a | 2019-06-14 16:19:36 +0800 | [diff] [blame] | 705 | AMD_PG_SUPPORT_ATHUB; |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 706 | adev->external_rev_id = adev->rev_id + 0x1; |
| 707 | break; |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 708 | case CHIP_NAVI14: |
Xiaojie Yuan | d0c39f8 | 2019-03-20 16:12:54 +0800 | [diff] [blame] | 709 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 710 | AMD_CG_SUPPORT_GFX_CGCG | |
| 711 | AMD_CG_SUPPORT_IH_CG | |
| 712 | AMD_CG_SUPPORT_HDP_MGCG | |
| 713 | AMD_CG_SUPPORT_HDP_LS | |
| 714 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 715 | AMD_CG_SUPPORT_SDMA_LS | |
| 716 | AMD_CG_SUPPORT_MC_MGCG | |
| 717 | AMD_CG_SUPPORT_MC_LS | |
| 718 | AMD_CG_SUPPORT_ATHUB_MGCG | |
| 719 | AMD_CG_SUPPORT_ATHUB_LS | |
| 720 | AMD_CG_SUPPORT_VCN_MGCG | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 721 | AMD_CG_SUPPORT_JPEG_MGCG | |
Xiaojie Yuan | d0c39f8 | 2019-03-20 16:12:54 +0800 | [diff] [blame] | 722 | AMD_CG_SUPPORT_BIF_MGCG | |
| 723 | AMD_CG_SUPPORT_BIF_LS; |
Xiaojie Yuan | 0377b08 | 2019-07-02 12:52:52 -0500 | [diff] [blame] | 724 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 725 | AMD_PG_SUPPORT_JPEG | |
Xiaojie Yuan | 0377b08 | 2019-07-02 12:52:52 -0500 | [diff] [blame] | 726 | AMD_PG_SUPPORT_VCN_DPG; |
tiancyin | 35ef88f | 2019-08-05 17:32:45 +0800 | [diff] [blame] | 727 | adev->external_rev_id = adev->rev_id + 20; |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 728 | break; |
Xiaojie Yuan | 74b5e50 | 2019-05-16 19:47:33 +0800 | [diff] [blame] | 729 | case CHIP_NAVI12: |
Xiaojie Yuan | dca009e | 2019-07-30 11:28:20 +0800 | [diff] [blame] | 730 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 731 | AMD_CG_SUPPORT_GFX_MGLS | |
| 732 | AMD_CG_SUPPORT_GFX_CGCG | |
| 733 | AMD_CG_SUPPORT_GFX_CP_LS | |
Xiaojie Yuan | 5211c37 | 2019-08-01 15:00:28 +0800 | [diff] [blame] | 734 | AMD_CG_SUPPORT_GFX_RLC_LS | |
Xiaojie Yuan | fbe0bc5 | 2019-08-01 15:01:23 +0800 | [diff] [blame] | 735 | AMD_CG_SUPPORT_IH_CG | |
Xiaojie Yuan | 5211c37 | 2019-08-01 15:00:28 +0800 | [diff] [blame] | 736 | AMD_CG_SUPPORT_HDP_MGCG | |
Xiaojie Yuan | 358ab97 | 2019-07-30 12:18:55 +0800 | [diff] [blame] | 737 | AMD_CG_SUPPORT_HDP_LS | |
| 738 | AMD_CG_SUPPORT_SDMA_MGCG | |
Xiaojie Yuan | 8b797b3 | 2019-08-01 15:39:59 +0800 | [diff] [blame] | 739 | AMD_CG_SUPPORT_SDMA_LS | |
| 740 | AMD_CG_SUPPORT_MC_MGCG | |
Xiaojie Yuan | ca51678 | 2019-08-01 15:19:10 +0800 | [diff] [blame] | 741 | AMD_CG_SUPPORT_MC_LS | |
| 742 | AMD_CG_SUPPORT_ATHUB_MGCG | |
Xiaojie Yuan | 65872e5 | 2019-08-01 15:22:59 +0800 | [diff] [blame] | 743 | AMD_CG_SUPPORT_ATHUB_LS | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 744 | AMD_CG_SUPPORT_VCN_MGCG | |
| 745 | AMD_CG_SUPPORT_JPEG_MGCG; |
Xiaojie Yuan | c1653ea | 2019-08-27 11:05:23 +0800 | [diff] [blame] | 746 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Xiaojie Yuan | 5ef3b8a | 2019-08-27 11:06:13 +0800 | [diff] [blame] | 747 | AMD_PG_SUPPORT_VCN_DPG | |
Leo Liu | 099d66e | 2019-11-11 15:09:25 -0500 | [diff] [blame] | 748 | AMD_PG_SUPPORT_JPEG | |
Likun Gao | 1b0443b | 2020-07-06 10:54:26 +0800 | [diff] [blame] | 749 | AMD_PG_SUPPORT_ATHUB; |
Tiecheng Zhou | df5e984 | 2020-01-08 13:44:29 +0800 | [diff] [blame] | 750 | /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0, |
| 751 | * as a consequence, the rev_id and external_rev_id are wrong. |
| 752 | * workaround it by hardcoding rev_id to 0 (default value). |
| 753 | */ |
| 754 | if (amdgpu_sriov_vf(adev)) |
| 755 | adev->rev_id = 0; |
Xiaojie Yuan | 74b5e50 | 2019-05-16 19:47:33 +0800 | [diff] [blame] | 756 | adev->external_rev_id = adev->rev_id + 0xa; |
| 757 | break; |
Likun Gao | 117910e | 2019-03-19 11:04:03 +0800 | [diff] [blame] | 758 | case CHIP_SIENNA_CICHLID: |
Likun Gao | 00194de | 2020-01-24 03:57:55 +0800 | [diff] [blame] | 759 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 760 | AMD_CG_SUPPORT_GFX_CGCG | |
| 761 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
Likun Gao | 98f8ea2 | 2020-03-18 17:33:47 -0400 | [diff] [blame] | 762 | AMD_CG_SUPPORT_MC_MGCG | |
Likun Gao | 00194de | 2020-01-24 03:57:55 +0800 | [diff] [blame] | 763 | AMD_CG_SUPPORT_VCN_MGCG | |
Kenneth Feng | ca36461 | 2020-02-28 11:57:04 +0800 | [diff] [blame] | 764 | AMD_CG_SUPPORT_JPEG_MGCG | |
| 765 | AMD_CG_SUPPORT_HDP_MGCG | |
Kenneth Feng | 3a32c25 | 2020-02-28 14:09:31 +0800 | [diff] [blame] | 766 | AMD_CG_SUPPORT_HDP_LS | |
Kenneth Feng | bcc8367 | 2020-02-28 14:14:00 +0800 | [diff] [blame] | 767 | AMD_CG_SUPPORT_IH_CG | |
| 768 | AMD_CG_SUPPORT_MC_LS; |
Leo Liu | b467c4f | 2019-12-03 09:23:24 -0500 | [diff] [blame] | 769 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Boyuan Zhang | d00b0fa | 2020-04-02 13:28:07 -0400 | [diff] [blame] | 770 | AMD_PG_SUPPORT_VCN_DPG | |
Kenneth Feng | b794616 | 2020-03-26 12:01:15 +0800 | [diff] [blame] | 771 | AMD_PG_SUPPORT_JPEG | |
Likun Gao | 1b0443b | 2020-07-06 10:54:26 +0800 | [diff] [blame] | 772 | AMD_PG_SUPPORT_ATHUB | |
| 773 | AMD_PG_SUPPORT_MMHUB; |
Jack Zhang | c45fbe1 | 2020-06-23 19:36:24 +0800 | [diff] [blame] | 774 | if (amdgpu_sriov_vf(adev)) { |
| 775 | /* hypervisor control CG and PG enablement */ |
| 776 | adev->cg_flags = 0; |
| 777 | adev->pg_flags = 0; |
| 778 | } |
Likun Gao | 117910e | 2019-03-19 11:04:03 +0800 | [diff] [blame] | 779 | adev->external_rev_id = adev->rev_id + 0x28; |
| 780 | break; |
Jiansong Chen | 543aa25 | 2020-02-10 17:00:28 +0800 | [diff] [blame] | 781 | case CHIP_NAVY_FLOUNDER: |
Jiansong Chen | 40582e6 | 2020-07-02 15:34:37 +0800 | [diff] [blame] | 782 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 783 | AMD_CG_SUPPORT_GFX_CGCG | |
| 784 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
| 785 | AMD_CG_SUPPORT_VCN_MGCG | |
Boyuan Zhang | 00740df | 2020-07-01 18:02:32 -0400 | [diff] [blame] | 786 | AMD_CG_SUPPORT_JPEG_MGCG; |
Boyuan Zhang | c6e9dd0 | 2020-07-01 17:59:51 -0400 | [diff] [blame] | 787 | adev->pg_flags = AMD_PG_SUPPORT_VCN | |
Boyuan Zhang | 00740df | 2020-07-01 18:02:32 -0400 | [diff] [blame] | 788 | AMD_PG_SUPPORT_VCN_DPG | |
| 789 | AMD_PG_SUPPORT_JPEG; |
Jiansong Chen | 543aa25 | 2020-02-10 17:00:28 +0800 | [diff] [blame] | 790 | adev->external_rev_id = adev->rev_id + 0x32; |
| 791 | break; |
| 792 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 793 | default: |
| 794 | /* FIXME: not supported yet */ |
| 795 | return -EINVAL; |
| 796 | } |
| 797 | |
Jiange Zhao | b05b690 | 2019-09-11 17:29:07 +0800 | [diff] [blame] | 798 | if (amdgpu_sriov_vf(adev)) { |
| 799 | amdgpu_virt_init_setting(adev); |
| 800 | xgpu_nv_mailbox_set_irq_funcs(adev); |
| 801 | } |
| 802 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | static int nv_common_late_init(void *handle) |
| 807 | { |
Jiange Zhao | b05b690 | 2019-09-11 17:29:07 +0800 | [diff] [blame] | 808 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 809 | |
| 810 | if (amdgpu_sriov_vf(adev)) |
| 811 | xgpu_nv_mailbox_get_irq(adev); |
| 812 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static int nv_common_sw_init(void *handle) |
| 817 | { |
Jiange Zhao | b05b690 | 2019-09-11 17:29:07 +0800 | [diff] [blame] | 818 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 819 | |
| 820 | if (amdgpu_sriov_vf(adev)) |
| 821 | xgpu_nv_mailbox_add_irq_id(adev); |
| 822 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static int nv_common_sw_fini(void *handle) |
| 827 | { |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int nv_common_hw_init(void *handle) |
| 832 | { |
| 833 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 834 | |
| 835 | /* enable pcie gen2/3 link */ |
| 836 | nv_pcie_gen3_enable(adev); |
| 837 | /* enable aspm */ |
| 838 | nv_program_aspm(adev); |
| 839 | /* setup nbio registers */ |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 840 | adev->nbio.funcs->init_registers(adev); |
Yong Zhao | 923c087 | 2019-09-27 23:30:05 -0400 | [diff] [blame] | 841 | /* remap HDP registers to a hole in mmio space, |
| 842 | * for the purpose of expose those registers |
| 843 | * to process space |
| 844 | */ |
| 845 | if (adev->nbio.funcs->remap_hdp_registers) |
| 846 | adev->nbio.funcs->remap_hdp_registers(adev); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 847 | /* enable the doorbell aperture */ |
| 848 | nv_enable_doorbell_aperture(adev, true); |
| 849 | |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int nv_common_hw_fini(void *handle) |
| 854 | { |
| 855 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 856 | |
| 857 | /* disable the doorbell aperture */ |
| 858 | nv_enable_doorbell_aperture(adev, false); |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | static int nv_common_suspend(void *handle) |
| 864 | { |
| 865 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 866 | |
| 867 | return nv_common_hw_fini(adev); |
| 868 | } |
| 869 | |
| 870 | static int nv_common_resume(void *handle) |
| 871 | { |
| 872 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 873 | |
| 874 | return nv_common_hw_init(adev); |
| 875 | } |
| 876 | |
| 877 | static bool nv_common_is_idle(void *handle) |
| 878 | { |
| 879 | return true; |
| 880 | } |
| 881 | |
| 882 | static int nv_common_wait_for_idle(void *handle) |
| 883 | { |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static int nv_common_soft_reset(void *handle) |
| 888 | { |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev, |
| 893 | bool enable) |
| 894 | { |
| 895 | uint32_t hdp_clk_cntl, hdp_clk_cntl1; |
| 896 | uint32_t hdp_mem_pwr_cntl; |
| 897 | |
| 898 | if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | |
| 899 | AMD_CG_SUPPORT_HDP_DS | |
| 900 | AMD_CG_SUPPORT_HDP_SD))) |
| 901 | return; |
| 902 | |
| 903 | hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 904 | hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL); |
| 905 | |
| 906 | /* Before doing clock/power mode switch, |
| 907 | * forced on IPH & RC clock */ |
| 908 | hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL, |
| 909 | IPH_MEM_CLK_SOFT_OVERRIDE, 1); |
| 910 | hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL, |
| 911 | RC_MEM_CLK_SOFT_OVERRIDE, 1); |
| 912 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl); |
| 913 | |
| 914 | /* HDP 5.0 doesn't support dynamic power mode switch, |
| 915 | * disable clock and power gating before any changing */ |
| 916 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 917 | IPH_MEM_POWER_CTRL_EN, 0); |
| 918 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 919 | IPH_MEM_POWER_LS_EN, 0); |
| 920 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 921 | IPH_MEM_POWER_DS_EN, 0); |
| 922 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 923 | IPH_MEM_POWER_SD_EN, 0); |
| 924 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 925 | RC_MEM_POWER_CTRL_EN, 0); |
| 926 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 927 | RC_MEM_POWER_LS_EN, 0); |
| 928 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 929 | RC_MEM_POWER_DS_EN, 0); |
| 930 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 931 | RC_MEM_POWER_SD_EN, 0); |
| 932 | WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl); |
| 933 | |
| 934 | /* only one clock gating mode (LS/DS/SD) can be enabled */ |
| 935 | if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) { |
| 936 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 937 | HDP_MEM_POWER_CTRL, |
| 938 | IPH_MEM_POWER_LS_EN, enable); |
| 939 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 940 | HDP_MEM_POWER_CTRL, |
| 941 | RC_MEM_POWER_LS_EN, enable); |
| 942 | } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) { |
| 943 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 944 | HDP_MEM_POWER_CTRL, |
| 945 | IPH_MEM_POWER_DS_EN, enable); |
| 946 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 947 | HDP_MEM_POWER_CTRL, |
| 948 | RC_MEM_POWER_DS_EN, enable); |
| 949 | } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) { |
| 950 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 951 | HDP_MEM_POWER_CTRL, |
| 952 | IPH_MEM_POWER_SD_EN, enable); |
| 953 | /* RC should not use shut down mode, fallback to ds */ |
| 954 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, |
| 955 | HDP_MEM_POWER_CTRL, |
| 956 | RC_MEM_POWER_DS_EN, enable); |
| 957 | } |
| 958 | |
Kenneth Feng | 91c6adf | 2020-02-28 11:57:04 +0800 | [diff] [blame] | 959 | /* confirmed that IPH_MEM_POWER_CTRL_EN and RC_MEM_POWER_CTRL_EN have to |
| 960 | * be set for SRAM LS/DS/SD */ |
| 961 | if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_DS | |
| 962 | AMD_CG_SUPPORT_HDP_SD)) { |
| 963 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 964 | IPH_MEM_POWER_CTRL_EN, 1); |
| 965 | hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL, |
| 966 | RC_MEM_POWER_CTRL_EN, 1); |
| 967 | } |
| 968 | |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 969 | WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl); |
| 970 | |
| 971 | /* restore IPH & RC clock override after clock/power mode changing */ |
| 972 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1); |
| 973 | } |
| 974 | |
| 975 | static void nv_update_hdp_clock_gating(struct amdgpu_device *adev, |
| 976 | bool enable) |
| 977 | { |
| 978 | uint32_t hdp_clk_cntl; |
| 979 | |
| 980 | if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG)) |
| 981 | return; |
| 982 | |
| 983 | hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 984 | |
| 985 | if (enable) { |
| 986 | hdp_clk_cntl &= |
| 987 | ~(uint32_t) |
| 988 | (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 989 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 990 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 991 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 992 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 993 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK); |
| 994 | } else { |
| 995 | hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 996 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 997 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 998 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 999 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 1000 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK; |
| 1001 | } |
| 1002 | |
| 1003 | WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl); |
| 1004 | } |
| 1005 | |
| 1006 | static int nv_common_set_clockgating_state(void *handle, |
| 1007 | enum amd_clockgating_state state) |
| 1008 | { |
| 1009 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1010 | |
| 1011 | if (amdgpu_sriov_vf(adev)) |
| 1012 | return 0; |
| 1013 | |
| 1014 | switch (adev->asic_type) { |
| 1015 | case CHIP_NAVI10: |
Xiaojie Yuan | 5e71e01 | 2018-12-17 18:23:27 +0800 | [diff] [blame] | 1016 | case CHIP_NAVI14: |
Xiaojie Yuan | 7e17e58 | 2019-05-16 19:51:12 +0800 | [diff] [blame] | 1017 | case CHIP_NAVI12: |
Likun Gao | 117910e | 2019-03-19 11:04:03 +0800 | [diff] [blame] | 1018 | case CHIP_SIENNA_CICHLID: |
Jiansong Chen | 543aa25 | 2020-02-10 17:00:28 +0800 | [diff] [blame] | 1019 | case CHIP_NAVY_FLOUNDER: |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 1020 | adev->nbio.funcs->update_medium_grain_clock_gating(adev, |
Nirmoy Das | a9d4fe2 | 2020-01-20 13:54:30 +0100 | [diff] [blame] | 1021 | state == AMD_CG_STATE_GATE); |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 1022 | adev->nbio.funcs->update_medium_grain_light_sleep(adev, |
Nirmoy Das | a9d4fe2 | 2020-01-20 13:54:30 +0100 | [diff] [blame] | 1023 | state == AMD_CG_STATE_GATE); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 1024 | nv_update_hdp_mem_power_gating(adev, |
Nirmoy Das | a9d4fe2 | 2020-01-20 13:54:30 +0100 | [diff] [blame] | 1025 | state == AMD_CG_STATE_GATE); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 1026 | nv_update_hdp_clock_gating(adev, |
Nirmoy Das | a9d4fe2 | 2020-01-20 13:54:30 +0100 | [diff] [blame] | 1027 | state == AMD_CG_STATE_GATE); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 1028 | break; |
| 1029 | default: |
| 1030 | break; |
| 1031 | } |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int nv_common_set_powergating_state(void *handle, |
| 1036 | enum amd_powergating_state state) |
| 1037 | { |
| 1038 | /* TODO */ |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | static void nv_common_get_clockgating_state(void *handle, u32 *flags) |
| 1043 | { |
| 1044 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 1045 | uint32_t tmp; |
| 1046 | |
| 1047 | if (amdgpu_sriov_vf(adev)) |
| 1048 | *flags = 0; |
| 1049 | |
Hawking Zhang | bebc076 | 2019-08-23 19:39:18 +0800 | [diff] [blame] | 1050 | adev->nbio.funcs->get_clockgating_state(adev, flags); |
Hawking Zhang | c6b6a42 | 2019-03-04 14:07:37 +0800 | [diff] [blame] | 1051 | |
| 1052 | /* AMD_CG_SUPPORT_HDP_MGCG */ |
| 1053 | tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL); |
| 1054 | if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 1055 | HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK | |
| 1056 | HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK | |
| 1057 | HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK | |
| 1058 | HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK | |
| 1059 | HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK))) |
| 1060 | *flags |= AMD_CG_SUPPORT_HDP_MGCG; |
| 1061 | |
| 1062 | /* AMD_CG_SUPPORT_HDP_LS/DS/SD */ |
| 1063 | tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL); |
| 1064 | if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK) |
| 1065 | *flags |= AMD_CG_SUPPORT_HDP_LS; |
| 1066 | else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK) |
| 1067 | *flags |= AMD_CG_SUPPORT_HDP_DS; |
| 1068 | else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK) |
| 1069 | *flags |= AMD_CG_SUPPORT_HDP_SD; |
| 1070 | |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | static const struct amd_ip_funcs nv_common_ip_funcs = { |
| 1075 | .name = "nv_common", |
| 1076 | .early_init = nv_common_early_init, |
| 1077 | .late_init = nv_common_late_init, |
| 1078 | .sw_init = nv_common_sw_init, |
| 1079 | .sw_fini = nv_common_sw_fini, |
| 1080 | .hw_init = nv_common_hw_init, |
| 1081 | .hw_fini = nv_common_hw_fini, |
| 1082 | .suspend = nv_common_suspend, |
| 1083 | .resume = nv_common_resume, |
| 1084 | .is_idle = nv_common_is_idle, |
| 1085 | .wait_for_idle = nv_common_wait_for_idle, |
| 1086 | .soft_reset = nv_common_soft_reset, |
| 1087 | .set_clockgating_state = nv_common_set_clockgating_state, |
| 1088 | .set_powergating_state = nv_common_set_powergating_state, |
| 1089 | .get_clockgating_state = nv_common_get_clockgating_state, |
| 1090 | }; |