Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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> |
Masahiro Yamada | 248a1d6 | 2017-04-24 13:50:21 +0900 | [diff] [blame] | 26 | #include <drm/drmP.h> |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 27 | #include "amdgpu.h" |
Alex Deucher | d05da0e | 2017-06-30 17:08:45 -0400 | [diff] [blame] | 28 | #include "amdgpu_atombios.h" |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 29 | #include "amdgpu_ih.h" |
| 30 | #include "amdgpu_uvd.h" |
| 31 | #include "amdgpu_vce.h" |
| 32 | #include "amdgpu_ucode.h" |
| 33 | #include "amdgpu_psp.h" |
| 34 | #include "atom.h" |
| 35 | #include "amd_pcie.h" |
| 36 | |
| 37 | #include "vega10/soc15ip.h" |
| 38 | #include "vega10/UVD/uvd_7_0_offset.h" |
| 39 | #include "vega10/GC/gc_9_0_offset.h" |
| 40 | #include "vega10/GC/gc_9_0_sh_mask.h" |
| 41 | #include "vega10/SDMA0/sdma0_4_0_offset.h" |
| 42 | #include "vega10/SDMA1/sdma1_4_0_offset.h" |
| 43 | #include "vega10/HDP/hdp_4_0_offset.h" |
| 44 | #include "vega10/HDP/hdp_4_0_sh_mask.h" |
| 45 | #include "vega10/MP/mp_9_0_offset.h" |
| 46 | #include "vega10/MP/mp_9_0_sh_mask.h" |
| 47 | #include "vega10/SMUIO/smuio_9_0_offset.h" |
| 48 | #include "vega10/SMUIO/smuio_9_0_sh_mask.h" |
| 49 | |
| 50 | #include "soc15.h" |
| 51 | #include "soc15_common.h" |
| 52 | #include "gfx_v9_0.h" |
| 53 | #include "gmc_v9_0.h" |
| 54 | #include "gfxhub_v1_0.h" |
| 55 | #include "mmhub_v1_0.h" |
| 56 | #include "vega10_ih.h" |
| 57 | #include "sdma_v4_0.h" |
| 58 | #include "uvd_v7_0.h" |
| 59 | #include "vce_v4_0.h" |
Leo Liu | f2d7e70 | 2016-12-28 13:36:00 -0500 | [diff] [blame] | 60 | #include "vcn_v1_0.h" |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 61 | #include "amdgpu_powerplay.h" |
Xiangliang Yu | 796b656 | 2017-02-28 17:22:03 +0800 | [diff] [blame] | 62 | #include "dce_virtual.h" |
Xiangliang Yu | f1a3446 | 2017-03-08 15:06:47 +0800 | [diff] [blame] | 63 | #include "mxgpu_ai.h" |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 64 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 65 | #define mmFabricConfigAccessControl 0x0410 |
| 66 | #define mmFabricConfigAccessControl_BASE_IDX 0 |
| 67 | #define mmFabricConfigAccessControl_DEFAULT 0x00000000 |
| 68 | //FabricConfigAccessControl |
| 69 | #define FabricConfigAccessControl__CfgRegInstAccEn__SHIFT 0x0 |
| 70 | #define FabricConfigAccessControl__CfgRegInstAccRegLock__SHIFT 0x1 |
| 71 | #define FabricConfigAccessControl__CfgRegInstID__SHIFT 0x10 |
| 72 | #define FabricConfigAccessControl__CfgRegInstAccEn_MASK 0x00000001L |
| 73 | #define FabricConfigAccessControl__CfgRegInstAccRegLock_MASK 0x00000002L |
| 74 | #define FabricConfigAccessControl__CfgRegInstID_MASK 0x00FF0000L |
| 75 | |
| 76 | |
| 77 | #define mmDF_PIE_AON0_DfGlobalClkGater 0x00fc |
| 78 | #define mmDF_PIE_AON0_DfGlobalClkGater_BASE_IDX 0 |
| 79 | //DF_PIE_AON0_DfGlobalClkGater |
| 80 | #define DF_PIE_AON0_DfGlobalClkGater__MGCGMode__SHIFT 0x0 |
| 81 | #define DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK 0x0000000FL |
| 82 | |
| 83 | enum { |
| 84 | DF_MGCG_DISABLE = 0, |
| 85 | DF_MGCG_ENABLE_00_CYCLE_DELAY =1, |
| 86 | DF_MGCG_ENABLE_01_CYCLE_DELAY =2, |
| 87 | DF_MGCG_ENABLE_15_CYCLE_DELAY =13, |
| 88 | DF_MGCG_ENABLE_31_CYCLE_DELAY =14, |
| 89 | DF_MGCG_ENABLE_63_CYCLE_DELAY =15 |
| 90 | }; |
| 91 | |
| 92 | #define mmMP0_MISC_CGTT_CTRL0 0x01b9 |
| 93 | #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX 0 |
| 94 | #define mmMP0_MISC_LIGHT_SLEEP_CTRL 0x01ba |
| 95 | #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX 0 |
| 96 | |
| 97 | /* |
| 98 | * Indirect registers accessor |
| 99 | */ |
| 100 | static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg) |
| 101 | { |
| 102 | unsigned long flags, address, data; |
| 103 | u32 r; |
| 104 | struct nbio_pcie_index_data *nbio_pcie_id; |
| 105 | |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 106 | if (adev->flags & AMD_IS_APU) |
| 107 | nbio_pcie_id = &nbio_v7_0_pcie_index_data; |
Alex Deucher | 1fdc639 | 2017-04-03 16:56:08 -0400 | [diff] [blame] | 108 | else |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 109 | nbio_pcie_id = &nbio_v6_1_pcie_index_data; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 110 | |
| 111 | address = nbio_pcie_id->index_offset; |
| 112 | data = nbio_pcie_id->data_offset; |
| 113 | |
| 114 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 115 | WREG32(address, reg); |
| 116 | (void)RREG32(address); |
| 117 | r = RREG32(data); |
| 118 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 119 | return r; |
| 120 | } |
| 121 | |
| 122 | static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 123 | { |
| 124 | unsigned long flags, address, data; |
| 125 | struct nbio_pcie_index_data *nbio_pcie_id; |
| 126 | |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 127 | if (adev->flags & AMD_IS_APU) |
| 128 | nbio_pcie_id = &nbio_v7_0_pcie_index_data; |
Alex Deucher | 1fdc639 | 2017-04-03 16:56:08 -0400 | [diff] [blame] | 129 | else |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 130 | nbio_pcie_id = &nbio_v6_1_pcie_index_data; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 131 | |
| 132 | address = nbio_pcie_id->index_offset; |
| 133 | data = nbio_pcie_id->data_offset; |
| 134 | |
| 135 | spin_lock_irqsave(&adev->pcie_idx_lock, flags); |
| 136 | WREG32(address, reg); |
| 137 | (void)RREG32(address); |
| 138 | WREG32(data, v); |
| 139 | (void)RREG32(data); |
| 140 | spin_unlock_irqrestore(&adev->pcie_idx_lock, flags); |
| 141 | } |
| 142 | |
| 143 | static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg) |
| 144 | { |
| 145 | unsigned long flags, address, data; |
| 146 | u32 r; |
| 147 | |
| 148 | address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX); |
| 149 | data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA); |
| 150 | |
| 151 | spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags); |
| 152 | WREG32(address, ((reg) & 0x1ff)); |
| 153 | r = RREG32(data); |
| 154 | spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags); |
| 155 | return r; |
| 156 | } |
| 157 | |
| 158 | static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 159 | { |
| 160 | unsigned long flags, address, data; |
| 161 | |
| 162 | address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX); |
| 163 | data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA); |
| 164 | |
| 165 | spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags); |
| 166 | WREG32(address, ((reg) & 0x1ff)); |
| 167 | WREG32(data, (v)); |
| 168 | spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags); |
| 169 | } |
| 170 | |
| 171 | static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg) |
| 172 | { |
| 173 | unsigned long flags, address, data; |
| 174 | u32 r; |
| 175 | |
| 176 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 177 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 178 | |
| 179 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 180 | WREG32(address, (reg)); |
| 181 | r = RREG32(data); |
| 182 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 183 | return r; |
| 184 | } |
| 185 | |
| 186 | static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 187 | { |
| 188 | unsigned long flags, address, data; |
| 189 | |
| 190 | address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX); |
| 191 | data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA); |
| 192 | |
| 193 | spin_lock_irqsave(&adev->didt_idx_lock, flags); |
| 194 | WREG32(address, (reg)); |
| 195 | WREG32(data, (v)); |
| 196 | spin_unlock_irqrestore(&adev->didt_idx_lock, flags); |
| 197 | } |
| 198 | |
| 199 | static u32 soc15_get_config_memsize(struct amdgpu_device *adev) |
| 200 | { |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 201 | if (adev->flags & AMD_IS_APU) |
| 202 | return nbio_v7_0_get_memsize(adev); |
| 203 | else |
| 204 | return nbio_v6_1_get_memsize(adev); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static const u32 vega10_golden_init[] = |
| 208 | { |
| 209 | }; |
| 210 | |
Chunming Zhou | e0ab957 | 2016-12-08 10:16:00 +0800 | [diff] [blame] | 211 | static const u32 raven_golden_init[] = |
| 212 | { |
| 213 | }; |
| 214 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 215 | static void soc15_init_golden_registers(struct amdgpu_device *adev) |
| 216 | { |
| 217 | /* Some of the registers might be dependent on GRBM_GFX_INDEX */ |
| 218 | mutex_lock(&adev->grbm_idx_mutex); |
| 219 | |
| 220 | switch (adev->asic_type) { |
| 221 | case CHIP_VEGA10: |
| 222 | amdgpu_program_register_sequence(adev, |
| 223 | vega10_golden_init, |
| 224 | (const u32)ARRAY_SIZE(vega10_golden_init)); |
| 225 | break; |
Chunming Zhou | e0ab957 | 2016-12-08 10:16:00 +0800 | [diff] [blame] | 226 | case CHIP_RAVEN: |
| 227 | amdgpu_program_register_sequence(adev, |
| 228 | raven_golden_init, |
| 229 | (const u32)ARRAY_SIZE(raven_golden_init)); |
| 230 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 231 | default: |
| 232 | break; |
| 233 | } |
| 234 | mutex_unlock(&adev->grbm_idx_mutex); |
| 235 | } |
| 236 | static u32 soc15_get_xclk(struct amdgpu_device *adev) |
| 237 | { |
| 238 | if (adev->asic_type == CHIP_VEGA10) |
| 239 | return adev->clock.spll.reference_freq/4; |
| 240 | else |
| 241 | return adev->clock.spll.reference_freq; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | void soc15_grbm_select(struct amdgpu_device *adev, |
| 246 | u32 me, u32 pipe, u32 queue, u32 vmid) |
| 247 | { |
| 248 | u32 grbm_gfx_cntl = 0; |
| 249 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe); |
| 250 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me); |
| 251 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid); |
| 252 | grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue); |
| 253 | |
| 254 | WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl); |
| 255 | } |
| 256 | |
| 257 | static void soc15_vga_set_state(struct amdgpu_device *adev, bool state) |
| 258 | { |
| 259 | /* todo */ |
| 260 | } |
| 261 | |
| 262 | static bool soc15_read_disabled_bios(struct amdgpu_device *adev) |
| 263 | { |
| 264 | /* todo */ |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | static bool soc15_read_bios_from_rom(struct amdgpu_device *adev, |
| 269 | u8 *bios, u32 length_bytes) |
| 270 | { |
| 271 | u32 *dw_ptr; |
| 272 | u32 i, length_dw; |
| 273 | |
| 274 | if (bios == NULL) |
| 275 | return false; |
| 276 | if (length_bytes == 0) |
| 277 | return false; |
| 278 | /* APU vbios image is part of sbios image */ |
| 279 | if (adev->flags & AMD_IS_APU) |
| 280 | return false; |
| 281 | |
| 282 | dw_ptr = (u32 *)bios; |
| 283 | length_dw = ALIGN(length_bytes, 4) / 4; |
| 284 | |
| 285 | /* set rom index to 0 */ |
| 286 | WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0); |
| 287 | /* read out the rom data */ |
| 288 | for (i = 0; i < length_dw; i++) |
| 289 | dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA)); |
| 290 | |
| 291 | return true; |
| 292 | } |
| 293 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 294 | static struct amdgpu_allowed_register_entry soc15_allowed_read_registers[] = { |
Christian König | 97fcc76 | 2017-04-12 12:49:54 +0200 | [diff] [blame] | 295 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS)}, |
| 296 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS2)}, |
| 297 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE0)}, |
| 298 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE1)}, |
| 299 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE2)}, |
| 300 | { SOC15_REG_OFFSET(GC, 0, mmGRBM_STATUS_SE3)}, |
| 301 | { SOC15_REG_OFFSET(SDMA0, 0, mmSDMA0_STATUS_REG)}, |
| 302 | { SOC15_REG_OFFSET(SDMA1, 0, mmSDMA1_STATUS_REG)}, |
| 303 | { SOC15_REG_OFFSET(GC, 0, mmCP_STAT)}, |
| 304 | { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT1)}, |
| 305 | { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT2)}, |
| 306 | { SOC15_REG_OFFSET(GC, 0, mmCP_STALLED_STAT3)}, |
| 307 | { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_BUSY_STAT)}, |
| 308 | { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STALLED_STAT1)}, |
| 309 | { SOC15_REG_OFFSET(GC, 0, mmCP_CPF_STATUS)}, |
| 310 | { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STALLED_STAT1)}, |
| 311 | { SOC15_REG_OFFSET(GC, 0, mmCP_CPC_STATUS)}, |
| 312 | { SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG)}, |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num, |
| 316 | u32 sh_num, u32 reg_offset) |
| 317 | { |
| 318 | uint32_t val; |
| 319 | |
| 320 | mutex_lock(&adev->grbm_idx_mutex); |
| 321 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 322 | amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff); |
| 323 | |
| 324 | val = RREG32(reg_offset); |
| 325 | |
| 326 | if (se_num != 0xffffffff || sh_num != 0xffffffff) |
| 327 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 328 | mutex_unlock(&adev->grbm_idx_mutex); |
| 329 | return val; |
| 330 | } |
| 331 | |
Alex Deucher | c013cea | 2017-03-24 15:05:07 -0400 | [diff] [blame] | 332 | static uint32_t soc15_get_register_value(struct amdgpu_device *adev, |
| 333 | bool indexed, u32 se_num, |
| 334 | u32 sh_num, u32 reg_offset) |
| 335 | { |
| 336 | if (indexed) { |
| 337 | return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset); |
| 338 | } else { |
| 339 | switch (reg_offset) { |
| 340 | case SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG): |
| 341 | return adev->gfx.config.gb_addr_config; |
| 342 | default: |
| 343 | return RREG32(reg_offset); |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 348 | static int soc15_read_register(struct amdgpu_device *adev, u32 se_num, |
| 349 | u32 sh_num, u32 reg_offset, u32 *value) |
| 350 | { |
Christian König | 3032f35 | 2017-04-12 12:53:18 +0200 | [diff] [blame] | 351 | uint32_t i; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 352 | |
| 353 | *value = 0; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 354 | for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) { |
| 355 | if (reg_offset != soc15_allowed_read_registers[i].reg_offset) |
| 356 | continue; |
| 357 | |
Christian König | 97fcc76 | 2017-04-12 12:49:54 +0200 | [diff] [blame] | 358 | *value = soc15_get_register_value(adev, |
| 359 | soc15_allowed_read_registers[i].grbm_indexed, |
| 360 | se_num, sh_num, reg_offset); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 361 | return 0; |
| 362 | } |
| 363 | return -EINVAL; |
| 364 | } |
| 365 | |
| 366 | static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev) |
| 367 | { |
| 368 | u32 i; |
| 369 | |
| 370 | dev_info(adev->dev, "GPU pci config reset\n"); |
| 371 | |
| 372 | /* disable BM */ |
| 373 | pci_clear_master(adev->pdev); |
| 374 | /* reset */ |
| 375 | amdgpu_pci_config_reset(adev); |
| 376 | |
| 377 | udelay(100); |
| 378 | |
| 379 | /* wait for asic to come out of reset */ |
| 380 | for (i = 0; i < adev->usec_timeout; i++) { |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 381 | u32 memsize = (adev->flags & AMD_IS_APU) ? |
| 382 | nbio_v7_0_get_memsize(adev) : |
| 383 | nbio_v6_1_get_memsize(adev); |
| 384 | if (memsize != 0xffffffff) |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 385 | break; |
| 386 | udelay(1); |
| 387 | } |
| 388 | |
| 389 | } |
| 390 | |
| 391 | static int soc15_asic_reset(struct amdgpu_device *adev) |
| 392 | { |
Alex Deucher | d05da0e | 2017-06-30 17:08:45 -0400 | [diff] [blame] | 393 | amdgpu_atombios_scratch_regs_engine_hung(adev, true); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 394 | |
| 395 | soc15_gpu_pci_config_reset(adev); |
| 396 | |
Alex Deucher | d05da0e | 2017-06-30 17:08:45 -0400 | [diff] [blame] | 397 | amdgpu_atombios_scratch_regs_engine_hung(adev, false); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock, |
| 403 | u32 cntl_reg, u32 status_reg) |
| 404 | { |
| 405 | return 0; |
| 406 | }*/ |
| 407 | |
| 408 | static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk) |
| 409 | { |
| 410 | /*int r; |
| 411 | |
| 412 | r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS); |
| 413 | if (r) |
| 414 | return r; |
| 415 | |
| 416 | r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS); |
| 417 | */ |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk) |
| 422 | { |
| 423 | /* todo */ |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static void soc15_pcie_gen3_enable(struct amdgpu_device *adev) |
| 429 | { |
| 430 | if (pci_is_root_bus(adev->pdev->bus)) |
| 431 | return; |
| 432 | |
| 433 | if (amdgpu_pcie_gen2 == 0) |
| 434 | return; |
| 435 | |
| 436 | if (adev->flags & AMD_IS_APU) |
| 437 | return; |
| 438 | |
| 439 | if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 440 | CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3))) |
| 441 | return; |
| 442 | |
| 443 | /* todo */ |
| 444 | } |
| 445 | |
| 446 | static void soc15_program_aspm(struct amdgpu_device *adev) |
| 447 | { |
| 448 | |
| 449 | if (amdgpu_aspm == 0) |
| 450 | return; |
| 451 | |
| 452 | /* todo */ |
| 453 | } |
| 454 | |
| 455 | static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev, |
| 456 | bool enable) |
| 457 | { |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 458 | if (adev->flags & AMD_IS_APU) { |
| 459 | nbio_v7_0_enable_doorbell_aperture(adev, enable); |
| 460 | } else { |
| 461 | nbio_v6_1_enable_doorbell_aperture(adev, enable); |
| 462 | nbio_v6_1_enable_doorbell_selfring_aperture(adev, enable); |
| 463 | } |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static const struct amdgpu_ip_block_version vega10_common_ip_block = |
| 467 | { |
| 468 | .type = AMD_IP_BLOCK_TYPE_COMMON, |
| 469 | .major = 2, |
| 470 | .minor = 0, |
| 471 | .rev = 0, |
| 472 | .funcs = &soc15_common_ip_funcs, |
| 473 | }; |
| 474 | |
| 475 | int soc15_set_ip_blocks(struct amdgpu_device *adev) |
| 476 | { |
Xiangliang Yu | 1b92242 | 2017-03-08 15:00:48 +0800 | [diff] [blame] | 477 | nbio_v6_1_detect_hw_virt(adev); |
| 478 | |
Xiangliang Yu | f1a3446 | 2017-03-08 15:06:47 +0800 | [diff] [blame] | 479 | if (amdgpu_sriov_vf(adev)) |
| 480 | adev->virt.ops = &xgpu_ai_virt_ops; |
| 481 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 482 | switch (adev->asic_type) { |
| 483 | case CHIP_VEGA10: |
| 484 | amdgpu_ip_block_add(adev, &vega10_common_ip_block); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 485 | amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block); |
| 486 | amdgpu_ip_block_add(adev, &vega10_ih_ip_block); |
Monk Liu | bb5c9ca | 2017-03-30 18:00:20 +0800 | [diff] [blame] | 487 | if (amdgpu_fw_load_type == 2 || amdgpu_fw_load_type == -1) |
| 488 | amdgpu_ip_block_add(adev, &psp_v3_1_ip_block); |
Xiangliang Yu | c6f3e7c | 2017-03-28 19:16:42 +0800 | [diff] [blame] | 489 | if (!amdgpu_sriov_vf(adev)) |
Xiangliang Yu | cfd8373 | 2017-02-28 17:26:40 +0800 | [diff] [blame] | 490 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
Alex Deucher | f844530 | 2017-03-22 10:49:25 -0400 | [diff] [blame] | 491 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
Xiangliang Yu | 796b656 | 2017-02-28 17:22:03 +0800 | [diff] [blame] | 492 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 493 | amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block); |
| 494 | amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block); |
Frank Min | 91faed9 | 2017-04-17 11:19:45 +0800 | [diff] [blame] | 495 | amdgpu_ip_block_add(adev, &uvd_v7_0_ip_block); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 496 | amdgpu_ip_block_add(adev, &vce_v4_0_ip_block); |
| 497 | break; |
Chunming Zhou | 1023b79 | 2016-12-08 10:09:13 +0800 | [diff] [blame] | 498 | case CHIP_RAVEN: |
| 499 | amdgpu_ip_block_add(adev, &vega10_common_ip_block); |
Chunming Zhou | 1023b79 | 2016-12-08 10:09:13 +0800 | [diff] [blame] | 500 | amdgpu_ip_block_add(adev, &gmc_v9_0_ip_block); |
| 501 | amdgpu_ip_block_add(adev, &vega10_ih_ip_block); |
Huang Rui | 9e2837f | 2017-05-11 16:26:16 -0400 | [diff] [blame] | 502 | amdgpu_ip_block_add(adev, &psp_v10_0_ip_block); |
Hawking Zhang | 30db095 | 2017-05-11 16:30:31 -0400 | [diff] [blame] | 503 | amdgpu_ip_block_add(adev, &amdgpu_pp_ip_block); |
Alex Deucher | d67fed16 | 2017-06-02 14:52:18 -0400 | [diff] [blame] | 504 | if (adev->enable_virtual_display || amdgpu_sriov_vf(adev)) |
| 505 | amdgpu_ip_block_add(adev, &dce_virtual_ip_block); |
Chunming Zhou | 1023b79 | 2016-12-08 10:09:13 +0800 | [diff] [blame] | 506 | amdgpu_ip_block_add(adev, &gfx_v9_0_ip_block); |
| 507 | amdgpu_ip_block_add(adev, &sdma_v4_0_ip_block); |
Leo Liu | f2d7e70 | 2016-12-28 13:36:00 -0500 | [diff] [blame] | 508 | amdgpu_ip_block_add(adev, &vcn_v1_0_ip_block); |
Chunming Zhou | 1023b79 | 2016-12-08 10:09:13 +0800 | [diff] [blame] | 509 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 510 | default: |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | static uint32_t soc15_get_rev_id(struct amdgpu_device *adev) |
| 518 | { |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 519 | if (adev->flags & AMD_IS_APU) |
| 520 | return nbio_v7_0_get_rev_id(adev); |
| 521 | else |
| 522 | return nbio_v6_1_get_rev_id(adev); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | |
| 526 | int gmc_v9_0_mc_wait_for_idle(struct amdgpu_device *adev) |
| 527 | { |
| 528 | /* to be implemented in MC IP*/ |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static const struct amdgpu_asic_funcs soc15_asic_funcs = |
| 533 | { |
| 534 | .read_disabled_bios = &soc15_read_disabled_bios, |
| 535 | .read_bios_from_rom = &soc15_read_bios_from_rom, |
| 536 | .read_register = &soc15_read_register, |
| 537 | .reset = &soc15_asic_reset, |
| 538 | .set_vga_state = &soc15_vga_set_state, |
| 539 | .get_xclk = &soc15_get_xclk, |
| 540 | .set_uvd_clocks = &soc15_set_uvd_clocks, |
| 541 | .set_vce_clocks = &soc15_set_vce_clocks, |
| 542 | .get_config_memsize = &soc15_get_config_memsize, |
| 543 | }; |
| 544 | |
| 545 | static int soc15_common_early_init(void *handle) |
| 546 | { |
| 547 | bool psp_enabled = false; |
| 548 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 549 | |
| 550 | adev->smc_rreg = NULL; |
| 551 | adev->smc_wreg = NULL; |
| 552 | adev->pcie_rreg = &soc15_pcie_rreg; |
| 553 | adev->pcie_wreg = &soc15_pcie_wreg; |
| 554 | adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg; |
| 555 | adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg; |
| 556 | adev->didt_rreg = &soc15_didt_rreg; |
| 557 | adev->didt_wreg = &soc15_didt_wreg; |
| 558 | |
| 559 | adev->asic_funcs = &soc15_asic_funcs; |
| 560 | |
| 561 | if (amdgpu_get_ip_block(adev, AMD_IP_BLOCK_TYPE_PSP) && |
| 562 | (amdgpu_ip_block_mask & (1 << AMD_IP_BLOCK_TYPE_PSP))) |
| 563 | psp_enabled = true; |
| 564 | |
| 565 | /* |
| 566 | * nbio need be used for both sdma and gfx9, but only |
| 567 | * initializes once |
| 568 | */ |
| 569 | switch(adev->asic_type) { |
| 570 | case CHIP_VEGA10: |
| 571 | nbio_v6_1_init(adev); |
| 572 | break; |
Chunming Zhou | aecbe64 | 2017-05-04 15:06:25 -0400 | [diff] [blame] | 573 | case CHIP_RAVEN: |
| 574 | nbio_v7_0_init(adev); |
| 575 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 576 | default: |
| 577 | return -EINVAL; |
| 578 | } |
| 579 | |
| 580 | adev->rev_id = soc15_get_rev_id(adev); |
| 581 | adev->external_rev_id = 0xFF; |
| 582 | switch (adev->asic_type) { |
| 583 | case CHIP_VEGA10: |
| 584 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 585 | AMD_CG_SUPPORT_GFX_MGLS | |
| 586 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 587 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 588 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
| 589 | AMD_CG_SUPPORT_GFX_3D_CGLS | |
| 590 | AMD_CG_SUPPORT_GFX_CGCG | |
| 591 | AMD_CG_SUPPORT_GFX_CGLS | |
| 592 | AMD_CG_SUPPORT_BIF_MGCG | |
| 593 | AMD_CG_SUPPORT_BIF_LS | |
| 594 | AMD_CG_SUPPORT_HDP_LS | |
| 595 | AMD_CG_SUPPORT_DRM_MGCG | |
| 596 | AMD_CG_SUPPORT_DRM_LS | |
| 597 | AMD_CG_SUPPORT_ROM_MGCG | |
| 598 | AMD_CG_SUPPORT_DF_MGCG | |
| 599 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 600 | AMD_CG_SUPPORT_SDMA_LS | |
| 601 | AMD_CG_SUPPORT_MC_MGCG | |
| 602 | AMD_CG_SUPPORT_MC_LS; |
| 603 | adev->pg_flags = 0; |
| 604 | adev->external_rev_id = 0x1; |
| 605 | break; |
Hawking Zhang | 957c6fe | 2016-12-27 21:02:48 +0800 | [diff] [blame] | 606 | case CHIP_RAVEN: |
Huang Rui | 5c5928a | 2017-01-18 18:14:08 +0800 | [diff] [blame] | 607 | adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG | |
| 608 | AMD_CG_SUPPORT_GFX_MGLS | |
| 609 | AMD_CG_SUPPORT_GFX_RLC_LS | |
| 610 | AMD_CG_SUPPORT_GFX_CP_LS | |
| 611 | AMD_CG_SUPPORT_GFX_3D_CGCG | |
| 612 | AMD_CG_SUPPORT_GFX_3D_CGLS | |
| 613 | AMD_CG_SUPPORT_GFX_CGCG | |
| 614 | AMD_CG_SUPPORT_GFX_CGLS | |
| 615 | AMD_CG_SUPPORT_BIF_MGCG | |
| 616 | AMD_CG_SUPPORT_BIF_LS | |
| 617 | AMD_CG_SUPPORT_HDP_MGCG | |
| 618 | AMD_CG_SUPPORT_HDP_LS | |
| 619 | AMD_CG_SUPPORT_DRM_MGCG | |
| 620 | AMD_CG_SUPPORT_DRM_LS | |
Huang Rui | c2cdb0e | 2017-05-05 14:27:23 -0400 | [diff] [blame] | 621 | AMD_CG_SUPPORT_ROM_MGCG | |
| 622 | AMD_CG_SUPPORT_MC_MGCG | |
Huang Rui | fe1a3b2 | 2017-05-05 14:28:27 -0400 | [diff] [blame] | 623 | AMD_CG_SUPPORT_MC_LS | |
| 624 | AMD_CG_SUPPORT_SDMA_MGCG | |
| 625 | AMD_CG_SUPPORT_SDMA_LS; |
Hawking Zhang | 32622ad | 2017-06-19 14:40:19 +0800 | [diff] [blame] | 626 | adev->pg_flags = AMD_PG_SUPPORT_SDMA | |
| 627 | AMD_PG_SUPPORT_MMHUB; |
Hawking Zhang | 957c6fe | 2016-12-27 21:02:48 +0800 | [diff] [blame] | 628 | adev->external_rev_id = 0x1; |
| 629 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 630 | default: |
| 631 | /* FIXME: not supported yet */ |
| 632 | return -EINVAL; |
| 633 | } |
| 634 | |
Xiangliang Yu | ab27663 | 2017-04-21 14:06:09 +0800 | [diff] [blame] | 635 | if (amdgpu_sriov_vf(adev)) { |
| 636 | amdgpu_virt_init_setting(adev); |
| 637 | xgpu_ai_mailbox_set_irq_funcs(adev); |
| 638 | } |
| 639 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 640 | adev->firmware.load_type = amdgpu_ucode_get_load_type(adev, amdgpu_fw_load_type); |
| 641 | |
| 642 | amdgpu_get_pcie_info(adev); |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
Monk Liu | 81758c5 | 2017-04-05 13:04:50 +0800 | [diff] [blame] | 647 | static int soc15_common_late_init(void *handle) |
| 648 | { |
| 649 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 650 | |
| 651 | if (amdgpu_sriov_vf(adev)) |
| 652 | xgpu_ai_mailbox_get_irq(adev); |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 657 | static int soc15_common_sw_init(void *handle) |
| 658 | { |
Monk Liu | 81758c5 | 2017-04-05 13:04:50 +0800 | [diff] [blame] | 659 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 660 | |
| 661 | if (amdgpu_sriov_vf(adev)) |
| 662 | xgpu_ai_mailbox_add_irq_id(adev); |
| 663 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int soc15_common_sw_fini(void *handle) |
| 668 | { |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | static int soc15_common_hw_init(void *handle) |
| 673 | { |
| 674 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 675 | |
| 676 | /* move the golden regs per IP block */ |
| 677 | soc15_init_golden_registers(adev); |
| 678 | /* enable pcie gen2/3 link */ |
| 679 | soc15_pcie_gen3_enable(adev); |
| 680 | /* enable aspm */ |
| 681 | soc15_program_aspm(adev); |
| 682 | /* enable the doorbell aperture */ |
| 683 | soc15_enable_doorbell_aperture(adev, true); |
| 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int soc15_common_hw_fini(void *handle) |
| 689 | { |
| 690 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 691 | |
| 692 | /* disable the doorbell aperture */ |
| 693 | soc15_enable_doorbell_aperture(adev, false); |
Monk Liu | 81758c5 | 2017-04-05 13:04:50 +0800 | [diff] [blame] | 694 | if (amdgpu_sriov_vf(adev)) |
| 695 | xgpu_ai_mailbox_put_irq(adev); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | static int soc15_common_suspend(void *handle) |
| 701 | { |
| 702 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 703 | |
| 704 | return soc15_common_hw_fini(adev); |
| 705 | } |
| 706 | |
| 707 | static int soc15_common_resume(void *handle) |
| 708 | { |
| 709 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 710 | |
| 711 | return soc15_common_hw_init(adev); |
| 712 | } |
| 713 | |
| 714 | static bool soc15_common_is_idle(void *handle) |
| 715 | { |
| 716 | return true; |
| 717 | } |
| 718 | |
| 719 | static int soc15_common_wait_for_idle(void *handle) |
| 720 | { |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static int soc15_common_soft_reset(void *handle) |
| 725 | { |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable) |
| 730 | { |
| 731 | uint32_t def, data; |
| 732 | |
| 733 | def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS)); |
| 734 | |
| 735 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS)) |
| 736 | data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK; |
| 737 | else |
| 738 | data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK; |
| 739 | |
| 740 | if (def != data) |
| 741 | WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data); |
| 742 | } |
| 743 | |
| 744 | static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable) |
| 745 | { |
| 746 | uint32_t def, data; |
| 747 | |
| 748 | def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0)); |
| 749 | |
| 750 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG)) |
| 751 | data &= ~(0x01000000 | |
| 752 | 0x02000000 | |
| 753 | 0x04000000 | |
| 754 | 0x08000000 | |
| 755 | 0x10000000 | |
| 756 | 0x20000000 | |
| 757 | 0x40000000 | |
| 758 | 0x80000000); |
| 759 | else |
| 760 | data |= (0x01000000 | |
| 761 | 0x02000000 | |
| 762 | 0x04000000 | |
| 763 | 0x08000000 | |
| 764 | 0x10000000 | |
| 765 | 0x20000000 | |
| 766 | 0x40000000 | |
| 767 | 0x80000000); |
| 768 | |
| 769 | if (def != data) |
| 770 | WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data); |
| 771 | } |
| 772 | |
| 773 | static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable) |
| 774 | { |
| 775 | uint32_t def, data; |
| 776 | |
| 777 | def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL)); |
| 778 | |
| 779 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS)) |
| 780 | data |= 1; |
| 781 | else |
| 782 | data &= ~1; |
| 783 | |
| 784 | if (def != data) |
| 785 | WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data); |
| 786 | } |
| 787 | |
| 788 | static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev, |
| 789 | bool enable) |
| 790 | { |
| 791 | uint32_t def, data; |
| 792 | |
| 793 | def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0)); |
| 794 | |
| 795 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG)) |
| 796 | data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK | |
| 797 | CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK); |
| 798 | else |
| 799 | data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK | |
| 800 | CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK; |
| 801 | |
| 802 | if (def != data) |
| 803 | WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data); |
| 804 | } |
| 805 | |
| 806 | static void soc15_update_df_medium_grain_clock_gating(struct amdgpu_device *adev, |
| 807 | bool enable) |
| 808 | { |
| 809 | uint32_t data; |
| 810 | |
| 811 | /* Put DF on broadcast mode */ |
| 812 | data = RREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl)); |
| 813 | data &= ~FabricConfigAccessControl__CfgRegInstAccEn_MASK; |
| 814 | WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), data); |
| 815 | |
| 816 | if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DF_MGCG)) { |
| 817 | data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater)); |
| 818 | data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK; |
| 819 | data |= DF_MGCG_ENABLE_15_CYCLE_DELAY; |
| 820 | WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data); |
| 821 | } else { |
| 822 | data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater)); |
| 823 | data &= ~DF_PIE_AON0_DfGlobalClkGater__MGCGMode_MASK; |
| 824 | data |= DF_MGCG_DISABLE; |
| 825 | WREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater), data); |
| 826 | } |
| 827 | |
| 828 | WREG32(SOC15_REG_OFFSET(DF, 0, mmFabricConfigAccessControl), |
| 829 | mmFabricConfigAccessControl_DEFAULT); |
| 830 | } |
| 831 | |
| 832 | static int soc15_common_set_clockgating_state(void *handle, |
| 833 | enum amd_clockgating_state state) |
| 834 | { |
| 835 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 836 | |
Monk Liu | 6e9dc86 | 2017-03-22 18:02:40 +0800 | [diff] [blame] | 837 | if (amdgpu_sriov_vf(adev)) |
| 838 | return 0; |
| 839 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 840 | switch (adev->asic_type) { |
| 841 | case CHIP_VEGA10: |
| 842 | nbio_v6_1_update_medium_grain_clock_gating(adev, |
| 843 | state == AMD_CG_STATE_GATE ? true : false); |
| 844 | nbio_v6_1_update_medium_grain_light_sleep(adev, |
| 845 | state == AMD_CG_STATE_GATE ? true : false); |
| 846 | soc15_update_hdp_light_sleep(adev, |
| 847 | state == AMD_CG_STATE_GATE ? true : false); |
| 848 | soc15_update_drm_clock_gating(adev, |
| 849 | state == AMD_CG_STATE_GATE ? true : false); |
| 850 | soc15_update_drm_light_sleep(adev, |
| 851 | state == AMD_CG_STATE_GATE ? true : false); |
| 852 | soc15_update_rom_medium_grain_clock_gating(adev, |
| 853 | state == AMD_CG_STATE_GATE ? true : false); |
| 854 | soc15_update_df_medium_grain_clock_gating(adev, |
| 855 | state == AMD_CG_STATE_GATE ? true : false); |
| 856 | break; |
Huang Rui | 9e5a9eb | 2017-01-18 18:12:59 +0800 | [diff] [blame] | 857 | case CHIP_RAVEN: |
Huang Rui | 7fda6ec | 2017-02-27 14:01:55 +0800 | [diff] [blame] | 858 | nbio_v7_0_update_medium_grain_clock_gating(adev, |
Huang Rui | 9e5a9eb | 2017-01-18 18:12:59 +0800 | [diff] [blame] | 859 | state == AMD_CG_STATE_GATE ? true : false); |
| 860 | nbio_v6_1_update_medium_grain_light_sleep(adev, |
| 861 | state == AMD_CG_STATE_GATE ? true : false); |
| 862 | soc15_update_hdp_light_sleep(adev, |
| 863 | state == AMD_CG_STATE_GATE ? true : false); |
| 864 | soc15_update_drm_clock_gating(adev, |
| 865 | state == AMD_CG_STATE_GATE ? true : false); |
| 866 | soc15_update_drm_light_sleep(adev, |
| 867 | state == AMD_CG_STATE_GATE ? true : false); |
| 868 | soc15_update_rom_medium_grain_clock_gating(adev, |
| 869 | state == AMD_CG_STATE_GATE ? true : false); |
| 870 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 871 | default: |
| 872 | break; |
| 873 | } |
| 874 | return 0; |
| 875 | } |
| 876 | |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 877 | static void soc15_common_get_clockgating_state(void *handle, u32 *flags) |
| 878 | { |
| 879 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 880 | int data; |
| 881 | |
| 882 | if (amdgpu_sriov_vf(adev)) |
| 883 | *flags = 0; |
| 884 | |
| 885 | nbio_v6_1_get_clockgating_state(adev, flags); |
| 886 | |
| 887 | /* AMD_CG_SUPPORT_HDP_LS */ |
| 888 | data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS)); |
| 889 | if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK) |
| 890 | *flags |= AMD_CG_SUPPORT_HDP_LS; |
| 891 | |
| 892 | /* AMD_CG_SUPPORT_DRM_MGCG */ |
| 893 | data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0)); |
| 894 | if (!(data & 0x01000000)) |
| 895 | *flags |= AMD_CG_SUPPORT_DRM_MGCG; |
| 896 | |
| 897 | /* AMD_CG_SUPPORT_DRM_LS */ |
| 898 | data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL)); |
| 899 | if (data & 0x1) |
| 900 | *flags |= AMD_CG_SUPPORT_DRM_LS; |
| 901 | |
| 902 | /* AMD_CG_SUPPORT_ROM_MGCG */ |
| 903 | data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0)); |
| 904 | if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK)) |
| 905 | *flags |= AMD_CG_SUPPORT_ROM_MGCG; |
| 906 | |
| 907 | /* AMD_CG_SUPPORT_DF_MGCG */ |
| 908 | data = RREG32(SOC15_REG_OFFSET(DF, 0, mmDF_PIE_AON0_DfGlobalClkGater)); |
| 909 | if (data & DF_MGCG_ENABLE_15_CYCLE_DELAY) |
| 910 | *flags |= AMD_CG_SUPPORT_DF_MGCG; |
| 911 | } |
| 912 | |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 913 | static int soc15_common_set_powergating_state(void *handle, |
| 914 | enum amd_powergating_state state) |
| 915 | { |
| 916 | /* todo */ |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | const struct amd_ip_funcs soc15_common_ip_funcs = { |
| 921 | .name = "soc15_common", |
| 922 | .early_init = soc15_common_early_init, |
Monk Liu | 81758c5 | 2017-04-05 13:04:50 +0800 | [diff] [blame] | 923 | .late_init = soc15_common_late_init, |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 924 | .sw_init = soc15_common_sw_init, |
| 925 | .sw_fini = soc15_common_sw_fini, |
| 926 | .hw_init = soc15_common_hw_init, |
| 927 | .hw_fini = soc15_common_hw_fini, |
| 928 | .suspend = soc15_common_suspend, |
| 929 | .resume = soc15_common_resume, |
| 930 | .is_idle = soc15_common_is_idle, |
| 931 | .wait_for_idle = soc15_common_wait_for_idle, |
| 932 | .soft_reset = soc15_common_soft_reset, |
| 933 | .set_clockgating_state = soc15_common_set_clockgating_state, |
| 934 | .set_powergating_state = soc15_common_set_powergating_state, |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 935 | .get_clockgating_state= soc15_common_get_clockgating_state, |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 936 | }; |