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