blob: 6c06756a216a3e96d5fb7e8f533a50f35cf74407 [file] [log] [blame]
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001/*
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 Deuchere9eea902019-07-31 10:39:40 -050026#include <linux/pci.h>
27
Hawking Zhangc6b6a422019-03-04 14:07:37 +080028#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 Wang767acab2019-07-05 15:58:46 -050035#include "amdgpu_smu.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080036#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 Deucher29bc37b2019-11-13 14:27:54 -050043#include "smuio/smuio_11_0_0_offset.h"
Alex Deucher3967ae62020-05-28 17:28:17 -040044#include "mp/mp_11_0_offset.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080045
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 Zhangbebc0762019-08-23 19:39:18 +080051#include "nbio_v2_3.h"
Huang Ruia7e91bd2020-08-27 12:02:37 -040052#include "nbio_v7_2.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080053#include "nv.h"
54#include "navi10_ih.h"
55#include "gfx_v10_0.h"
56#include "sdma_v5_0.h"
Likun Gao157e72e2019-06-17 13:38:29 +080057#include "sdma_v5_2.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080058#include "vcn_v2_0.h"
Leo Liu5be45a22019-11-08 15:01:42 -050059#include "jpeg_v2_0.h"
Leo Liub8f10582020-03-24 16:30:24 -040060#include "vcn_v3_0.h"
Leo Liu4d72dd12020-03-24 16:31:23 -040061#include "jpeg_v3_0.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080062#include "dce_virtual.h"
63#include "mes_v10_1.h"
Jiange Zhaob05b6902019-09-11 17:29:07 +080064#include "mxgpu_nv.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080065
66static const struct amd_ip_funcs nv_common_ip_funcs;
67
68/*
69 * Indirect registers accessor
70 */
71static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
72{
Hawking Zhang705a2b52020-09-15 17:57:30 +080073 unsigned long address, data;
Hawking Zhangbebc0762019-08-23 19:39:18 +080074 address = adev->nbio.funcs->get_pcie_index_offset(adev);
75 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080076
Hawking Zhang705a2b52020-09-15 17:57:30 +080077 return amdgpu_device_indirect_rreg(adev, address, data, reg);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080078}
79
80static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
81{
Hawking Zhang705a2b52020-09-15 17:57:30 +080082 unsigned long address, data;
Hawking Zhangc6b6a422019-03-04 14:07:37 +080083
Hawking Zhangbebc0762019-08-23 19:39:18 +080084 address = adev->nbio.funcs->get_pcie_index_offset(adev);
85 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080086
Hawking Zhang705a2b52020-09-15 17:57:30 +080087 amdgpu_device_indirect_wreg(adev, address, data, reg, v);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080088}
89
John Clements4922f1bc2020-07-22 09:40:11 +080090static u64 nv_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
91{
Hawking Zhang705a2b52020-09-15 17:57:30 +080092 unsigned long address, data;
John Clements4922f1bc2020-07-22 09:40:11 +080093 address = adev->nbio.funcs->get_pcie_index_offset(adev);
94 data = adev->nbio.funcs->get_pcie_data_offset(adev);
95
Hawking Zhang705a2b52020-09-15 17:57:30 +080096 return amdgpu_device_indirect_rreg64(adev, address, data, reg);
John Clements4922f1bc2020-07-22 09:40:11 +080097}
98
Huang Rui5de54342020-08-27 12:01:26 -040099static u32 nv_pcie_port_rreg(struct amdgpu_device *adev, u32 reg)
100{
101 unsigned long flags, address, data;
102 u32 r;
103 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
104 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
105
106 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
107 WREG32(address, reg * 4);
108 (void)RREG32(address);
109 r = RREG32(data);
110 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
111 return r;
112}
113
John Clements4922f1bc2020-07-22 09:40:11 +0800114static void nv_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
115{
Hawking Zhang705a2b52020-09-15 17:57:30 +0800116 unsigned long address, data;
John Clements4922f1bc2020-07-22 09:40:11 +0800117
118 address = adev->nbio.funcs->get_pcie_index_offset(adev);
119 data = adev->nbio.funcs->get_pcie_data_offset(adev);
120
Hawking Zhang705a2b52020-09-15 17:57:30 +0800121 amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
John Clements4922f1bc2020-07-22 09:40:11 +0800122}
123
Huang Rui5de54342020-08-27 12:01:26 -0400124static void nv_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
125{
126 unsigned long flags, address, data;
127
128 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
129 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
130
131 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
132 WREG32(address, reg * 4);
133 (void)RREG32(address);
134 WREG32(data, v);
135 (void)RREG32(data);
136 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
137}
138
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800139static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
140{
141 unsigned long flags, address, data;
142 u32 r;
143
144 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
145 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
146
147 spin_lock_irqsave(&adev->didt_idx_lock, flags);
148 WREG32(address, (reg));
149 r = RREG32(data);
150 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
151 return r;
152}
153
154static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
155{
156 unsigned long flags, address, data;
157
158 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
159 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
160
161 spin_lock_irqsave(&adev->didt_idx_lock, flags);
162 WREG32(address, (reg));
163 WREG32(data, (v));
164 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
165}
166
167static u32 nv_get_config_memsize(struct amdgpu_device *adev)
168{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800169 return adev->nbio.funcs->get_memsize(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800170}
171
172static u32 nv_get_xclk(struct amdgpu_device *adev)
173{
Tao Zhou462a70d2019-05-14 11:37:32 +0800174 return adev->clock.spll.reference_freq;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800175}
176
177
178void nv_grbm_select(struct amdgpu_device *adev,
179 u32 me, u32 pipe, u32 queue, u32 vmid)
180{
181 u32 grbm_gfx_cntl = 0;
182 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
183 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
184 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
185 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
186
187 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
188}
189
190static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
191{
192 /* todo */
193}
194
195static bool nv_read_disabled_bios(struct amdgpu_device *adev)
196{
197 /* todo */
198 return false;
199}
200
201static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
202 u8 *bios, u32 length_bytes)
203{
Alex Deucher29bc37b2019-11-13 14:27:54 -0500204 u32 *dw_ptr;
205 u32 i, length_dw;
206
207 if (bios == NULL)
208 return false;
209 if (length_bytes == 0)
210 return false;
211 /* APU vbios image is part of sbios image */
212 if (adev->flags & AMD_IS_APU)
213 return false;
214
215 dw_ptr = (u32 *)bios;
216 length_dw = ALIGN(length_bytes, 4) / 4;
217
218 /* set rom index to 0 */
219 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
220 /* read out the rom data */
221 for (i = 0; i < length_dw; i++)
222 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
223
224 return true;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800225}
226
227static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
228 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
229 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
230 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
231 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
232 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
233 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800234 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
235 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800236 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
237 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
238 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
239 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
240 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
241 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
242 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
Marek Olšák664fe852019-10-22 17:22:38 -0400243 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800244 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
245 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
246 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
247};
248
249static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
250 u32 sh_num, u32 reg_offset)
251{
252 uint32_t val;
253
254 mutex_lock(&adev->grbm_idx_mutex);
255 if (se_num != 0xffffffff || sh_num != 0xffffffff)
256 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
257
258 val = RREG32(reg_offset);
259
260 if (se_num != 0xffffffff || sh_num != 0xffffffff)
261 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
262 mutex_unlock(&adev->grbm_idx_mutex);
263 return val;
264}
265
266static uint32_t nv_get_register_value(struct amdgpu_device *adev,
267 bool indexed, u32 se_num,
268 u32 sh_num, u32 reg_offset)
269{
270 if (indexed) {
271 return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
272 } else {
273 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
274 return adev->gfx.config.gb_addr_config;
275 return RREG32(reg_offset);
276 }
277}
278
279static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
280 u32 sh_num, u32 reg_offset, u32 *value)
281{
282 uint32_t i;
283 struct soc15_allowed_register_entry *en;
284
285 *value = 0;
286 for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
287 en = &nv_allowed_read_registers[i];
Huang Ruifced3c32020-08-28 22:54:32 +0800288 if ((i == 7 && (adev->sdma.num_instances == 1)) || /* some asics don't have SDMA1 */
289 reg_offset !=
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800290 (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
291 continue;
292
293 *value = nv_get_register_value(adev,
294 nv_allowed_read_registers[i].grbm_indexed,
295 se_num, sh_num, reg_offset);
296 return 0;
297 }
298 return -EINVAL;
299}
300
Kevin Wang3e2bb602019-07-05 12:51:45 +0800301static int nv_asic_mode1_reset(struct amdgpu_device *adev)
302{
303 u32 i;
304 int ret = 0;
305
306 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
307
Kevin Wang3e2bb602019-07-05 12:51:45 +0800308 /* disable BM */
309 pci_clear_master(adev->pdev);
310
Andrey Grodzovskyc1dd4aa2020-08-24 12:30:47 -0400311 amdgpu_device_cache_pci_state(adev->pdev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800312
Wenhui Sheng311531f2020-07-13 15:15:11 +0800313 if (amdgpu_dpm_is_mode1_reset_supported(adev)) {
314 dev_info(adev->dev, "GPU smu mode1 reset\n");
315 ret = amdgpu_dpm_mode1_reset(adev);
316 } else {
317 dev_info(adev->dev, "GPU psp mode1 reset\n");
318 ret = psp_gpu_reset(adev);
319 }
320
Kevin Wang3e2bb602019-07-05 12:51:45 +0800321 if (ret)
322 dev_err(adev->dev, "GPU mode1 reset failed\n");
Andrey Grodzovskyc1dd4aa2020-08-24 12:30:47 -0400323 amdgpu_device_load_pci_state(adev->pdev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800324
325 /* wait for asic to come out of reset */
326 for (i = 0; i < adev->usec_timeout; i++) {
Hawking Zhangbebc0762019-08-23 19:39:18 +0800327 u32 memsize = adev->nbio.funcs->get_memsize(adev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800328
329 if (memsize != 0xffffffff)
330 break;
331 udelay(1);
332 }
333
334 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
335
336 return ret;
337}
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500338
Alex Deucherac742612019-11-07 18:12:17 -0500339static bool nv_asic_supports_baco(struct amdgpu_device *adev)
340{
341 struct smu_context *smu = &adev->smu;
342
343 if (smu_baco_is_support(smu))
344 return true;
345 else
346 return false;
347}
348
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500349static enum amd_reset_method
350nv_asic_reset_method(struct amdgpu_device *adev)
351{
352 struct smu_context *smu = &adev->smu;
353
Wenhui Sheng273da6f2020-07-14 16:29:18 +0800354 if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
355 amdgpu_reset_method == AMD_RESET_METHOD_BACO)
356 return amdgpu_reset_method;
357
358 if (amdgpu_reset_method != -1)
359 dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
360 amdgpu_reset_method);
361
Likun Gaoca6fd7a2020-08-06 17:37:28 +0800362 switch (adev->asic_type) {
363 case CHIP_SIENNA_CICHLID:
Jiansong Chen22dd44f2020-08-25 15:39:57 +0800364 case CHIP_NAVY_FLOUNDER:
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500365 return AMD_RESET_METHOD_MODE1;
Likun Gaoca6fd7a2020-08-06 17:37:28 +0800366 default:
367 if (smu_baco_is_support(smu))
368 return AMD_RESET_METHOD_BACO;
369 else
370 return AMD_RESET_METHOD_MODE1;
371 }
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500372}
373
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800374static int nv_asic_reset(struct amdgpu_device *adev)
375{
Kevin Wang767acab2019-07-05 15:58:46 -0500376 int ret = 0;
377 struct smu_context *smu = &adev->smu;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800378
Monk Liue3526252019-08-27 16:32:55 +0800379 if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
Alex Deucher11043b72020-08-11 12:02:21 -0400380 dev_info(adev->dev, "BACO reset\n");
Wenhui Sheng311531f2020-07-13 15:15:11 +0800381
Alex Deucher11520f22019-10-28 15:20:03 -0400382 ret = smu_baco_enter(smu);
383 if (ret)
384 return ret;
385 ret = smu_baco_exit(smu);
386 if (ret)
387 return ret;
Alex Deucher11043b72020-08-11 12:02:21 -0400388 } else {
389 dev_info(adev->dev, "MODE1 reset\n");
Kevin Wang3e2bb602019-07-05 12:51:45 +0800390 ret = nv_asic_mode1_reset(adev);
Alex Deucher11043b72020-08-11 12:02:21 -0400391 }
Kevin Wang767acab2019-07-05 15:58:46 -0500392
393 return ret;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800394}
395
396static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
397{
398 /* todo */
399 return 0;
400}
401
402static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
403{
404 /* todo */
405 return 0;
406}
407
408static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
409{
410 if (pci_is_root_bus(adev->pdev->bus))
411 return;
412
413 if (amdgpu_pcie_gen2 == 0)
414 return;
415
416 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
417 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
418 return;
419
420 /* todo */
421}
422
423static void nv_program_aspm(struct amdgpu_device *adev)
424{
425
426 if (amdgpu_aspm == 0)
427 return;
428
429 /* todo */
430}
431
432static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
433 bool enable)
434{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800435 adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
436 adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800437}
438
439static const struct amdgpu_ip_block_version nv_common_ip_block =
440{
441 .type = AMD_IP_BLOCK_TYPE_COMMON,
442 .major = 1,
443 .minor = 0,
444 .rev = 0,
445 .funcs = &nv_common_ip_funcs,
446};
447
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800448static int nv_reg_base_init(struct amdgpu_device *adev)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800449{
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800450 int r;
451
Alex Deucher8bb3aa12020-08-28 11:42:44 -0400452 /* IP discovery table is not available yet */
453 if (adev->asic_type == CHIP_VANGOGH)
454 goto legacy_init;
455
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800456 if (amdgpu_discovery) {
457 r = amdgpu_discovery_reg_base_init(adev);
458 if (r) {
459 DRM_WARN("failed to init reg base from ip discovery table, "
460 "fallback to legacy init method\n");
461 goto legacy_init;
462 }
463
464 return 0;
465 }
466
467legacy_init:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800468 switch (adev->asic_type) {
469 case CHIP_NAVI10:
470 navi10_reg_base_init(adev);
471 break;
Xiaojie Yuana0f6d9262018-12-17 18:24:03 +0800472 case CHIP_NAVI14:
473 navi14_reg_base_init(adev);
474 break;
Xiaojie Yuan03d0a072019-05-14 15:22:53 +0800475 case CHIP_NAVI12:
476 navi12_reg_base_init(adev);
477 break;
Likun Gaodccdbf32019-11-07 16:28:14 +0800478 case CHIP_SIENNA_CICHLID:
Jiansong Chenc8c959f2020-02-11 14:00:39 +0800479 case CHIP_NAVY_FLOUNDER:
Likun Gaodccdbf32019-11-07 16:28:14 +0800480 sienna_cichlid_reg_base_init(adev);
481 break;
Huang Rui026570e2020-08-27 10:46:19 -0400482 case CHIP_VANGOGH:
483 vangogh_reg_base_init(adev);
484 break;
Tao Zhou038d7572020-10-02 11:34:02 -0400485 case CHIP_DIMGREY_CAVEFISH:
486 dimgrey_cavefish_reg_base_init(adev);
487 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800488 default:
489 return -EINVAL;
490 }
491
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800492 return 0;
493}
494
Wenhui Shengc1299462020-06-23 11:35:05 +0800495void nv_set_virt_ops(struct amdgpu_device *adev)
496{
497 adev->virt.ops = &xgpu_nv_virt_ops;
498}
499
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800500int nv_set_ip_blocks(struct amdgpu_device *adev)
501{
502 int r;
503
Huang Ruia7e91bd2020-08-27 12:02:37 -0400504 if (adev->flags & AMD_IS_APU) {
505 adev->nbio.funcs = &nbio_v7_2_funcs;
506 adev->nbio.hdp_flush_reg = &nbio_v7_2_hdp_flush_reg;
507 } else {
508 adev->nbio.funcs = &nbio_v2_3_funcs;
509 adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
510 }
Monk Liu122078d2020-03-04 23:51:51 +0800511
John Clementsc6529232020-07-17 14:13:50 +0800512 if (adev->asic_type == CHIP_SIENNA_CICHLID)
513 adev->gmc.xgmi.supported = true;
514
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800515 /* Set IP register base before any HW register access */
516 r = nv_reg_base_init(adev);
517 if (r)
518 return r;
519
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800520 switch (adev->asic_type) {
521 case CHIP_NAVI10:
Alex Deucherd1daf852019-07-02 14:42:25 -0500522 case CHIP_NAVI14:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800523 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
524 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
525 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
526 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
527 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
Evan Quan95302732020-01-07 16:57:39 +0800528 !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800529 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
530 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
531 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500532#if defined(CONFIG_DRM_AMD_DC)
Harry Wentlandb4f199c2019-02-26 16:25:27 -0500533 else if (amdgpu_device_has_dc_support(adev))
534 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500535#endif
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800536 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
537 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
538 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Evan Quan95302732020-01-07 16:57:39 +0800539 !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800540 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
541 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Leo Liu5be45a22019-11-08 15:01:42 -0500542 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800543 if (adev->enable_mes)
544 amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
545 break;
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800546 case CHIP_NAVI12:
547 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
548 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
549 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Xiaojie Yuan6b66ae22019-07-18 02:54:29 +0800550 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
Monk Liu79bebab2020-04-22 12:09:16 +0800551 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800552 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Xiaojie Yuan79902022019-06-26 19:19:57 +0800553 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
554 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200555#if defined(CONFIG_DRM_AMD_DC)
Leo Li078655d92019-07-16 18:12:13 -0400556 else if (amdgpu_device_has_dc_support(adev))
557 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200558#endif
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800559 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
560 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800561 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Evan Quan95302732020-01-07 16:57:39 +0800562 !amdgpu_sriov_vf(adev))
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800563 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Boyuan Zhang1fbed282019-07-18 10:13:23 -0400564 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Monk Liufe442492020-03-05 21:10:03 +0800565 if (!amdgpu_sriov_vf(adev))
566 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800567 break;
Likun Gao2e1ba102019-04-18 13:49:07 +0800568 case CHIP_SIENNA_CICHLID:
569 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
Likun Gao0b3df162019-06-16 22:34:59 +0800570 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
Likun Gao757b3af2019-06-16 22:37:56 +0800571 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Likun Gao56304e72020-03-24 16:27:43 -0400572 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
573 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
Likun Gaob07e5c62020-03-24 16:24:44 -0400574 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
shaoyunl38d5bbe2020-03-17 11:41:34 -0400575 is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev))
Likun Gaob07e5c62020-03-24 16:24:44 -0400576 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Likun Gao9a986762019-08-14 17:39:03 +0800577 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
578 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Bhawanpreet Lakha464ab912020-05-21 12:57:27 -0400579#if defined(CONFIG_DRM_AMD_DC)
580 else if (amdgpu_device_has_dc_support(adev))
581 amdgpu_device_ip_block_add(adev, &dm_ip_block);
582#endif
Likun Gao933c8a92020-05-01 10:21:23 -0400583 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
Likun Gao157e72e2019-06-17 13:38:29 +0800584 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
Leo Liub8f10582020-03-24 16:30:24 -0400585 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
Jack Zhangc45fbe12020-06-23 19:36:24 +0800586 if (!amdgpu_sriov_vf(adev))
587 amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
588
Jack Xiaoa346ef82020-03-24 16:28:43 -0400589 if (adev->enable_mes)
590 amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
Likun Gao2e1ba102019-04-18 13:49:07 +0800591 break;
Jiansong Chen8515e0a2020-02-12 21:47:47 +0800592 case CHIP_NAVY_FLOUNDER:
593 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
Jiansong Chenfc8f07d2020-02-12 22:19:37 +0800594 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
Jiansong Chen026c3962020-02-12 22:32:01 +0800595 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Jiansong Chen7420eab22020-07-08 17:07:26 -0400596 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
597 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
598 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
599 is_support_sw_smu(adev))
600 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Jiansong Chen5404f072020-02-24 14:28:34 +0800601 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
602 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Bhawanpreet Lakhaa6c53082020-07-08 17:11:12 -0400603#if defined(CONFIG_DRM_AMD_DC)
604 else if (amdgpu_device_has_dc_support(adev))
605 amdgpu_device_ip_block_add(adev, &dm_ip_block);
606#endif
Jiansong Chen885eb3f2020-02-13 15:43:15 +0800607 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
Jiansong Chendf2d15d2020-02-14 16:19:13 +0800608 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
Boyuan Zhang290b4ad2020-07-08 16:48:26 -0400609 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
610 amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
Jiansong Chenf4497d12020-04-15 11:20:19 +0800611 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
612 is_support_sw_smu(adev))
613 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Jiansong Chen8515e0a2020-02-12 21:47:47 +0800614 break;
Huang Rui88edbad2019-10-12 20:02:39 +0800615 case CHIP_VANGOGH:
616 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
617 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
618 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Huang Ruied3b7352020-09-17 12:02:12 -0400619 if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
620 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
Huang Ruic821e0f2020-05-28 15:46:41 +0800621 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Huang Rui88edbad2019-10-12 20:02:39 +0800622 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
623 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
624 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
625 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
Thong Thaib4e532d2020-08-27 11:35:13 -0400626 amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
627 amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
Huang Rui88edbad2019-10-12 20:02:39 +0800628 break;
Tao Zhou2aa92b12020-10-02 11:35:47 -0400629 case CHIP_DIMGREY_CAVEFISH:
630 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
Tao Zhou3e02ad42020-10-02 11:38:30 -0400631 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
Tao Zhou2aa92b12020-10-02 11:35:47 -0400632 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800633 default:
634 return -EINVAL;
635 }
636
637 return 0;
638}
639
640static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
641{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800642 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800643}
644
645static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
646{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800647 adev->nbio.funcs->hdp_flush(adev, ring);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800648}
649
650static void nv_invalidate_hdp(struct amdgpu_device *adev,
651 struct amdgpu_ring *ring)
652{
653 if (!ring || !ring->funcs->emit_wreg) {
Stanley.Yang78f0aef2020-09-22 16:56:54 +0800654 WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800655 } else {
656 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
657 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
658 }
659}
660
661static bool nv_need_full_reset(struct amdgpu_device *adev)
662{
663 return true;
664}
665
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800666static bool nv_need_reset_on_init(struct amdgpu_device *adev)
667{
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800668 u32 sol_reg;
669
670 if (adev->flags & AMD_IS_APU)
671 return false;
672
673 /* Check sOS sign of life register to confirm sys driver and sOS
674 * are already been loaded.
675 */
676 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
677 if (sol_reg)
678 return true;
Alex Deucher3967ae62020-05-28 17:28:17 -0400679
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800680 return false;
681}
682
Kevin Wang2af815312019-11-05 18:53:30 +0800683static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
684{
685
686 /* TODO
687 * dummy implement for pcie_replay_count sysfs interface
688 * */
689
690 return 0;
691}
692
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800693static void nv_init_doorbell_index(struct amdgpu_device *adev)
694{
695 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
696 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
697 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
698 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
699 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
700 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
701 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
702 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
703 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
704 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
705 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
706 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
707 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
Jack Xiao20519232019-04-26 18:58:41 +0800708 adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800709 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
710 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
Likun Gao157e72e2019-06-17 13:38:29 +0800711 adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
712 adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800713 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
714 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
715 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
716 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
717 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
718 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
719 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
720
721 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
722 adev->doorbell_index.sdma_doorbell_range = 20;
723}
724
Alex Deuchera7173732020-08-19 17:04:47 -0400725static void nv_pre_asic_init(struct amdgpu_device *adev)
726{
727}
728
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800729static const struct amdgpu_asic_funcs nv_asic_funcs =
730{
731 .read_disabled_bios = &nv_read_disabled_bios,
732 .read_bios_from_rom = &nv_read_bios_from_rom,
733 .read_register = &nv_read_register,
734 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500735 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800736 .set_vga_state = &nv_vga_set_state,
737 .get_xclk = &nv_get_xclk,
738 .set_uvd_clocks = &nv_set_uvd_clocks,
739 .set_vce_clocks = &nv_set_vce_clocks,
740 .get_config_memsize = &nv_get_config_memsize,
741 .flush_hdp = &nv_flush_hdp,
742 .invalidate_hdp = &nv_invalidate_hdp,
743 .init_doorbell_index = &nv_init_doorbell_index,
744 .need_full_reset = &nv_need_full_reset,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800745 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800746 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Alex Deucherac742612019-11-07 18:12:17 -0500747 .supports_baco = &nv_asic_supports_baco,
Alex Deuchera7173732020-08-19 17:04:47 -0400748 .pre_asic_init = &nv_pre_asic_init,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800749};
750
751static int nv_common_early_init(void *handle)
752{
Yong Zhao923c0872019-09-27 23:30:05 -0400753#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800754 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
755
Yong Zhao923c0872019-09-27 23:30:05 -0400756 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
757 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800758 adev->smc_rreg = NULL;
759 adev->smc_wreg = NULL;
760 adev->pcie_rreg = &nv_pcie_rreg;
761 adev->pcie_wreg = &nv_pcie_wreg;
John Clements4922f1bc2020-07-22 09:40:11 +0800762 adev->pcie_rreg64 = &nv_pcie_rreg64;
763 adev->pcie_wreg64 = &nv_pcie_wreg64;
Huang Rui5de54342020-08-27 12:01:26 -0400764 adev->pciep_rreg = &nv_pcie_port_rreg;
765 adev->pciep_wreg = &nv_pcie_port_wreg;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800766
767 /* TODO: will add them during VCN v2 implementation */
768 adev->uvd_ctx_rreg = NULL;
769 adev->uvd_ctx_wreg = NULL;
770
771 adev->didt_rreg = &nv_didt_rreg;
772 adev->didt_wreg = &nv_didt_wreg;
773
774 adev->asic_funcs = &nv_asic_funcs;
775
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800776 adev->rev_id = nv_get_rev_id(adev);
777 adev->external_rev_id = 0xff;
778 switch (adev->asic_type) {
779 case CHIP_NAVI10:
780 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800781 AMD_CG_SUPPORT_GFX_CGCG |
782 AMD_CG_SUPPORT_IH_CG |
783 AMD_CG_SUPPORT_HDP_MGCG |
784 AMD_CG_SUPPORT_HDP_LS |
785 AMD_CG_SUPPORT_SDMA_MGCG |
786 AMD_CG_SUPPORT_SDMA_LS |
787 AMD_CG_SUPPORT_MC_MGCG |
788 AMD_CG_SUPPORT_MC_LS |
789 AMD_CG_SUPPORT_ATHUB_MGCG |
790 AMD_CG_SUPPORT_ATHUB_LS |
791 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500792 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800793 AMD_CG_SUPPORT_BIF_MGCG |
794 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400795 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800796 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500797 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800798 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800799 adev->external_rev_id = adev->rev_id + 0x1;
800 break;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800801 case CHIP_NAVI14:
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800802 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
803 AMD_CG_SUPPORT_GFX_CGCG |
804 AMD_CG_SUPPORT_IH_CG |
805 AMD_CG_SUPPORT_HDP_MGCG |
806 AMD_CG_SUPPORT_HDP_LS |
807 AMD_CG_SUPPORT_SDMA_MGCG |
808 AMD_CG_SUPPORT_SDMA_LS |
809 AMD_CG_SUPPORT_MC_MGCG |
810 AMD_CG_SUPPORT_MC_LS |
811 AMD_CG_SUPPORT_ATHUB_MGCG |
812 AMD_CG_SUPPORT_ATHUB_LS |
813 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500814 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800815 AMD_CG_SUPPORT_BIF_MGCG |
816 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500817 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500818 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500819 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800820 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800821 break;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800822 case CHIP_NAVI12:
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800823 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
824 AMD_CG_SUPPORT_GFX_MGLS |
825 AMD_CG_SUPPORT_GFX_CGCG |
826 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800827 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800828 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800829 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800830 AMD_CG_SUPPORT_HDP_LS |
831 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800832 AMD_CG_SUPPORT_SDMA_LS |
833 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800834 AMD_CG_SUPPORT_MC_LS |
835 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800836 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500837 AMD_CG_SUPPORT_VCN_MGCG |
838 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800839 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800840 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500841 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800842 AMD_PG_SUPPORT_ATHUB;
Tiecheng Zhoudf5e9842020-01-08 13:44:29 +0800843 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
844 * as a consequence, the rev_id and external_rev_id are wrong.
845 * workaround it by hardcoding rev_id to 0 (default value).
846 */
847 if (amdgpu_sriov_vf(adev))
848 adev->rev_id = 0;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800849 adev->external_rev_id = adev->rev_id + 0xa;
850 break;
Likun Gao117910e2019-03-19 11:04:03 +0800851 case CHIP_SIENNA_CICHLID:
Likun Gao00194de2020-01-24 03:57:55 +0800852 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
853 AMD_CG_SUPPORT_GFX_CGCG |
854 AMD_CG_SUPPORT_GFX_3D_CGCG |
Likun Gao98f8ea22020-03-18 17:33:47 -0400855 AMD_CG_SUPPORT_MC_MGCG |
Likun Gao00194de2020-01-24 03:57:55 +0800856 AMD_CG_SUPPORT_VCN_MGCG |
Kenneth Fengca364612020-02-28 11:57:04 +0800857 AMD_CG_SUPPORT_JPEG_MGCG |
858 AMD_CG_SUPPORT_HDP_MGCG |
Kenneth Feng3a32c252020-02-28 14:09:31 +0800859 AMD_CG_SUPPORT_HDP_LS |
Kenneth Fengbcc83672020-02-28 14:14:00 +0800860 AMD_CG_SUPPORT_IH_CG |
861 AMD_CG_SUPPORT_MC_LS;
Leo Liub467c4f2019-12-03 09:23:24 -0500862 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhangd00b0fa2020-04-02 13:28:07 -0400863 AMD_PG_SUPPORT_VCN_DPG |
Kenneth Fengb7946162020-03-26 12:01:15 +0800864 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800865 AMD_PG_SUPPORT_ATHUB |
866 AMD_PG_SUPPORT_MMHUB;
Jack Zhangc45fbe12020-06-23 19:36:24 +0800867 if (amdgpu_sriov_vf(adev)) {
868 /* hypervisor control CG and PG enablement */
869 adev->cg_flags = 0;
870 adev->pg_flags = 0;
871 }
Likun Gao117910e2019-03-19 11:04:03 +0800872 adev->external_rev_id = adev->rev_id + 0x28;
873 break;
Jiansong Chen543aa252020-02-10 17:00:28 +0800874 case CHIP_NAVY_FLOUNDER:
Jiansong Chen40582e62020-07-02 15:34:37 +0800875 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
876 AMD_CG_SUPPORT_GFX_CGCG |
877 AMD_CG_SUPPORT_GFX_3D_CGCG |
878 AMD_CG_SUPPORT_VCN_MGCG |
Jiansong Chen92c73752020-07-08 18:53:36 +0800879 AMD_CG_SUPPORT_JPEG_MGCG |
880 AMD_CG_SUPPORT_MC_MGCG |
Jiansong Chen4759f882020-07-08 18:59:11 +0800881 AMD_CG_SUPPORT_MC_LS |
882 AMD_CG_SUPPORT_HDP_MGCG |
Jiansong Chen85e71512020-07-08 19:02:14 +0800883 AMD_CG_SUPPORT_HDP_LS |
884 AMD_CG_SUPPORT_IH_CG;
Boyuan Zhangc6e9dd02020-07-01 17:59:51 -0400885 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhang00740df2020-07-01 18:02:32 -0400886 AMD_PG_SUPPORT_VCN_DPG |
Jiansong Chen47fc8942020-07-08 18:42:04 +0800887 AMD_PG_SUPPORT_JPEG |
888 AMD_PG_SUPPORT_ATHUB |
889 AMD_PG_SUPPORT_MMHUB;
Jiansong Chen543aa252020-02-10 17:00:28 +0800890 adev->external_rev_id = adev->rev_id + 0x32;
891 break;
892
Huang Rui026570e2020-08-27 10:46:19 -0400893 case CHIP_VANGOGH:
Huang Ruiac0dc4c2020-09-22 19:08:31 +0800894 adev->cg_flags = AMD_CG_SUPPORT_GFX_CGCG |
895 AMD_CG_SUPPORT_GFX_CGLS |
896 AMD_CG_SUPPORT_GFX_3D_CGCG |
897 AMD_CG_SUPPORT_GFX_3D_CGLS;
898 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG;
Huang Rui026570e2020-08-27 10:46:19 -0400899 adev->external_rev_id = adev->rev_id + 0x01;
900 break;
Tao Zhou550c58e2020-10-02 11:30:54 -0400901 case CHIP_DIMGREY_CAVEFISH:
902 adev->cg_flags = 0;
903 adev->pg_flags = 0;
904 adev->external_rev_id = adev->rev_id + 0x3c;
905 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800906 default:
907 /* FIXME: not supported yet */
908 return -EINVAL;
909 }
910
Jiange Zhaob05b6902019-09-11 17:29:07 +0800911 if (amdgpu_sriov_vf(adev)) {
912 amdgpu_virt_init_setting(adev);
913 xgpu_nv_mailbox_set_irq_funcs(adev);
914 }
915
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800916 return 0;
917}
918
919static int nv_common_late_init(void *handle)
920{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800921 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
922
923 if (amdgpu_sriov_vf(adev))
924 xgpu_nv_mailbox_get_irq(adev);
925
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800926 return 0;
927}
928
929static int nv_common_sw_init(void *handle)
930{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800931 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
932
933 if (amdgpu_sriov_vf(adev))
934 xgpu_nv_mailbox_add_irq_id(adev);
935
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800936 return 0;
937}
938
939static int nv_common_sw_fini(void *handle)
940{
941 return 0;
942}
943
944static int nv_common_hw_init(void *handle)
945{
946 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
947
948 /* enable pcie gen2/3 link */
949 nv_pcie_gen3_enable(adev);
950 /* enable aspm */
951 nv_program_aspm(adev);
952 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +0800953 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -0400954 /* remap HDP registers to a hole in mmio space,
955 * for the purpose of expose those registers
956 * to process space
957 */
958 if (adev->nbio.funcs->remap_hdp_registers)
959 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800960 /* enable the doorbell aperture */
961 nv_enable_doorbell_aperture(adev, true);
962
963 return 0;
964}
965
966static int nv_common_hw_fini(void *handle)
967{
968 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
969
970 /* disable the doorbell aperture */
971 nv_enable_doorbell_aperture(adev, false);
972
973 return 0;
974}
975
976static int nv_common_suspend(void *handle)
977{
978 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
979
980 return nv_common_hw_fini(adev);
981}
982
983static int nv_common_resume(void *handle)
984{
985 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
986
987 return nv_common_hw_init(adev);
988}
989
990static bool nv_common_is_idle(void *handle)
991{
992 return true;
993}
994
995static int nv_common_wait_for_idle(void *handle)
996{
997 return 0;
998}
999
1000static int nv_common_soft_reset(void *handle)
1001{
1002 return 0;
1003}
1004
1005static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev,
1006 bool enable)
1007{
1008 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
1009 uint32_t hdp_mem_pwr_cntl;
1010
1011 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |
1012 AMD_CG_SUPPORT_HDP_DS |
1013 AMD_CG_SUPPORT_HDP_SD)))
1014 return;
1015
1016 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1017 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1018
1019 /* Before doing clock/power mode switch,
1020 * forced on IPH & RC clock */
1021 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1022 IPH_MEM_CLK_SOFT_OVERRIDE, 1);
1023 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1024 RC_MEM_CLK_SOFT_OVERRIDE, 1);
1025 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1026
1027 /* HDP 5.0 doesn't support dynamic power mode switch,
1028 * disable clock and power gating before any changing */
1029 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1030 IPH_MEM_POWER_CTRL_EN, 0);
1031 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1032 IPH_MEM_POWER_LS_EN, 0);
1033 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1034 IPH_MEM_POWER_DS_EN, 0);
1035 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1036 IPH_MEM_POWER_SD_EN, 0);
1037 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1038 RC_MEM_POWER_CTRL_EN, 0);
1039 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1040 RC_MEM_POWER_LS_EN, 0);
1041 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1042 RC_MEM_POWER_DS_EN, 0);
1043 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1044 RC_MEM_POWER_SD_EN, 0);
1045 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1046
1047 /* only one clock gating mode (LS/DS/SD) can be enabled */
1048 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1049 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1050 HDP_MEM_POWER_CTRL,
1051 IPH_MEM_POWER_LS_EN, enable);
1052 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1053 HDP_MEM_POWER_CTRL,
1054 RC_MEM_POWER_LS_EN, enable);
1055 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) {
1056 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1057 HDP_MEM_POWER_CTRL,
1058 IPH_MEM_POWER_DS_EN, enable);
1059 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1060 HDP_MEM_POWER_CTRL,
1061 RC_MEM_POWER_DS_EN, enable);
1062 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) {
1063 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1064 HDP_MEM_POWER_CTRL,
1065 IPH_MEM_POWER_SD_EN, enable);
1066 /* RC should not use shut down mode, fallback to ds */
1067 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1068 HDP_MEM_POWER_CTRL,
1069 RC_MEM_POWER_DS_EN, enable);
1070 }
1071
Kenneth Feng91c6adf2020-02-28 11:57:04 +08001072 /* confirmed that IPH_MEM_POWER_CTRL_EN and RC_MEM_POWER_CTRL_EN have to
1073 * be set for SRAM LS/DS/SD */
1074 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_DS |
1075 AMD_CG_SUPPORT_HDP_SD)) {
1076 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1077 IPH_MEM_POWER_CTRL_EN, 1);
1078 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1079 RC_MEM_POWER_CTRL_EN, 1);
1080 }
1081
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001082 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1083
1084 /* restore IPH & RC clock override after clock/power mode changing */
1085 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1);
1086}
1087
1088static void nv_update_hdp_clock_gating(struct amdgpu_device *adev,
1089 bool enable)
1090{
1091 uint32_t hdp_clk_cntl;
1092
1093 if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
1094 return;
1095
1096 hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1097
1098 if (enable) {
1099 hdp_clk_cntl &=
1100 ~(uint32_t)
1101 (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1102 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1103 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1104 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1105 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1106 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK);
1107 } else {
1108 hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1109 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1110 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1111 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1112 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1113 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK;
1114 }
1115
1116 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1117}
1118
1119static int nv_common_set_clockgating_state(void *handle,
1120 enum amd_clockgating_state state)
1121{
1122 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1123
1124 if (amdgpu_sriov_vf(adev))
1125 return 0;
1126
1127 switch (adev->asic_type) {
1128 case CHIP_NAVI10:
Xiaojie Yuan5e71e012018-12-17 18:23:27 +08001129 case CHIP_NAVI14:
Xiaojie Yuan7e17e582019-05-16 19:51:12 +08001130 case CHIP_NAVI12:
Likun Gao117910e2019-03-19 11:04:03 +08001131 case CHIP_SIENNA_CICHLID:
Jiansong Chen543aa252020-02-10 17:00:28 +08001132 case CHIP_NAVY_FLOUNDER:
Tao Zhou550c58e2020-10-02 11:30:54 -04001133 case CHIP_DIMGREY_CAVEFISH:
Hawking Zhangbebc0762019-08-23 19:39:18 +08001134 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001135 state == AMD_CG_STATE_GATE);
Hawking Zhangbebc0762019-08-23 19:39:18 +08001136 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001137 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001138 nv_update_hdp_mem_power_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001139 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001140 nv_update_hdp_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001141 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001142 break;
1143 default:
1144 break;
1145 }
1146 return 0;
1147}
1148
1149static int nv_common_set_powergating_state(void *handle,
1150 enum amd_powergating_state state)
1151{
1152 /* TODO */
1153 return 0;
1154}
1155
1156static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1157{
1158 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1159 uint32_t tmp;
1160
1161 if (amdgpu_sriov_vf(adev))
1162 *flags = 0;
1163
Hawking Zhangbebc0762019-08-23 19:39:18 +08001164 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001165
1166 /* AMD_CG_SUPPORT_HDP_MGCG */
1167 tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1168 if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1169 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1170 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1171 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1172 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1173 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK)))
1174 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
1175
1176 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
1177 tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1178 if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK)
1179 *flags |= AMD_CG_SUPPORT_HDP_LS;
1180 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK)
1181 *flags |= AMD_CG_SUPPORT_HDP_DS;
1182 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK)
1183 *flags |= AMD_CG_SUPPORT_HDP_SD;
1184
1185 return;
1186}
1187
1188static const struct amd_ip_funcs nv_common_ip_funcs = {
1189 .name = "nv_common",
1190 .early_init = nv_common_early_init,
1191 .late_init = nv_common_late_init,
1192 .sw_init = nv_common_sw_init,
1193 .sw_fini = nv_common_sw_fini,
1194 .hw_init = nv_common_hw_init,
1195 .hw_fini = nv_common_hw_fini,
1196 .suspend = nv_common_suspend,
1197 .resume = nv_common_resume,
1198 .is_idle = nv_common_is_idle,
1199 .wait_for_idle = nv_common_wait_for_idle,
1200 .soft_reset = nv_common_soft_reset,
1201 .set_clockgating_state = nv_common_set_clockgating_state,
1202 .set_powergating_state = nv_common_set_powergating_state,
1203 .get_clockgating_state = nv_common_get_clockgating_state,
1204};