blob: 8e7c6a4b0018ec9a53ccd82d5bccdb2c5b6b951f [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"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080044
45#include "soc15.h"
46#include "soc15_common.h"
47#include "gmc_v10_0.h"
48#include "gfxhub_v2_0.h"
49#include "mmhub_v2_0.h"
Hawking Zhangbebc0762019-08-23 19:39:18 +080050#include "nbio_v2_3.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080051#include "nv.h"
52#include "navi10_ih.h"
53#include "gfx_v10_0.h"
54#include "sdma_v5_0.h"
55#include "vcn_v2_0.h"
Leo Liu5be45a22019-11-08 15:01:42 -050056#include "jpeg_v2_0.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080057#include "dce_virtual.h"
58#include "mes_v10_1.h"
Jiange Zhaob05b6902019-09-11 17:29:07 +080059#include "mxgpu_nv.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080060
61static const struct amd_ip_funcs nv_common_ip_funcs;
62
63/*
64 * Indirect registers accessor
65 */
66static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
67{
68 unsigned long flags, address, data;
69 u32 r;
Hawking Zhangbebc0762019-08-23 19:39:18 +080070 address = adev->nbio.funcs->get_pcie_index_offset(adev);
71 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080072
73 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
74 WREG32(address, reg);
75 (void)RREG32(address);
76 r = RREG32(data);
77 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
78 return r;
79}
80
81static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
82{
83 unsigned long flags, address, data;
84
Hawking Zhangbebc0762019-08-23 19:39:18 +080085 address = adev->nbio.funcs->get_pcie_index_offset(adev);
86 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080087
88 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
89 WREG32(address, reg);
90 (void)RREG32(address);
91 WREG32(data, v);
92 (void)RREG32(data);
93 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
94}
95
96static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
97{
98 unsigned long flags, address, data;
99 u32 r;
100
101 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
102 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
103
104 spin_lock_irqsave(&adev->didt_idx_lock, flags);
105 WREG32(address, (reg));
106 r = RREG32(data);
107 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
108 return r;
109}
110
111static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
112{
113 unsigned long flags, address, data;
114
115 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
116 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
117
118 spin_lock_irqsave(&adev->didt_idx_lock, flags);
119 WREG32(address, (reg));
120 WREG32(data, (v));
121 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
122}
123
124static u32 nv_get_config_memsize(struct amdgpu_device *adev)
125{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800126 return adev->nbio.funcs->get_memsize(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800127}
128
129static u32 nv_get_xclk(struct amdgpu_device *adev)
130{
Tao Zhou462a70d2019-05-14 11:37:32 +0800131 return adev->clock.spll.reference_freq;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800132}
133
134
135void nv_grbm_select(struct amdgpu_device *adev,
136 u32 me, u32 pipe, u32 queue, u32 vmid)
137{
138 u32 grbm_gfx_cntl = 0;
139 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
140 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
141 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
142 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
143
144 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
145}
146
147static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
148{
149 /* todo */
150}
151
152static bool nv_read_disabled_bios(struct amdgpu_device *adev)
153{
154 /* todo */
155 return false;
156}
157
158static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
159 u8 *bios, u32 length_bytes)
160{
Alex Deucher29bc37b2019-11-13 14:27:54 -0500161 u32 *dw_ptr;
162 u32 i, length_dw;
163
164 if (bios == NULL)
165 return false;
166 if (length_bytes == 0)
167 return false;
168 /* APU vbios image is part of sbios image */
169 if (adev->flags & AMD_IS_APU)
170 return false;
171
172 dw_ptr = (u32 *)bios;
173 length_dw = ALIGN(length_bytes, 4) / 4;
174
175 /* set rom index to 0 */
176 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
177 /* read out the rom data */
178 for (i = 0; i < length_dw; i++)
179 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
180
181 return true;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800182}
183
184static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
185 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
186 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
187 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
188 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
189 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
190 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
191#if 0 /* TODO: will set it when SDMA header is available */
192 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
193 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
194#endif
195 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
196 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
197 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
198 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
199 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
200 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
201 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
Marek Olšák664fe852019-10-22 17:22:38 -0400202 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800203 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
204 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
205 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
206};
207
208static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
209 u32 sh_num, u32 reg_offset)
210{
211 uint32_t val;
212
213 mutex_lock(&adev->grbm_idx_mutex);
214 if (se_num != 0xffffffff || sh_num != 0xffffffff)
215 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
216
217 val = RREG32(reg_offset);
218
219 if (se_num != 0xffffffff || sh_num != 0xffffffff)
220 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
221 mutex_unlock(&adev->grbm_idx_mutex);
222 return val;
223}
224
225static uint32_t nv_get_register_value(struct amdgpu_device *adev,
226 bool indexed, u32 se_num,
227 u32 sh_num, u32 reg_offset)
228{
229 if (indexed) {
230 return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
231 } else {
232 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
233 return adev->gfx.config.gb_addr_config;
234 return RREG32(reg_offset);
235 }
236}
237
238static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
239 u32 sh_num, u32 reg_offset, u32 *value)
240{
241 uint32_t i;
242 struct soc15_allowed_register_entry *en;
243
244 *value = 0;
245 for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
246 en = &nv_allowed_read_registers[i];
247 if (reg_offset !=
248 (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
249 continue;
250
251 *value = nv_get_register_value(adev,
252 nv_allowed_read_registers[i].grbm_indexed,
253 se_num, sh_num, reg_offset);
254 return 0;
255 }
256 return -EINVAL;
257}
258
259#if 0
260static void nv_gpu_pci_config_reset(struct amdgpu_device *adev)
261{
262 u32 i;
263
264 dev_info(adev->dev, "GPU pci config reset\n");
265
266 /* disable BM */
267 pci_clear_master(adev->pdev);
268 /* reset */
269 amdgpu_pci_config_reset(adev);
270
271 udelay(100);
272
273 /* wait for asic to come out of reset */
274 for (i = 0; i < adev->usec_timeout; i++) {
275 u32 memsize = nbio_v2_3_get_memsize(adev);
276 if (memsize != 0xffffffff)
277 break;
278 udelay(1);
279 }
280
281}
282#endif
283
Kevin Wang3e2bb602019-07-05 12:51:45 +0800284static int nv_asic_mode1_reset(struct amdgpu_device *adev)
285{
286 u32 i;
287 int ret = 0;
288
289 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
290
291 dev_info(adev->dev, "GPU mode1 reset\n");
292
293 /* disable BM */
294 pci_clear_master(adev->pdev);
295
296 pci_save_state(adev->pdev);
297
298 ret = psp_gpu_reset(adev);
299 if (ret)
300 dev_err(adev->dev, "GPU mode1 reset failed\n");
301
302 pci_restore_state(adev->pdev);
303
304 /* wait for asic to come out of reset */
305 for (i = 0; i < adev->usec_timeout; i++) {
Hawking Zhangbebc0762019-08-23 19:39:18 +0800306 u32 memsize = adev->nbio.funcs->get_memsize(adev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800307
308 if (memsize != 0xffffffff)
309 break;
310 udelay(1);
311 }
312
313 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
314
315 return ret;
316}
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500317
Alex Deucherac742612019-11-07 18:12:17 -0500318static bool nv_asic_supports_baco(struct amdgpu_device *adev)
319{
320 struct smu_context *smu = &adev->smu;
321
322 if (smu_baco_is_support(smu))
323 return true;
324 else
325 return false;
326}
327
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500328static enum amd_reset_method
329nv_asic_reset_method(struct amdgpu_device *adev)
330{
331 struct smu_context *smu = &adev->smu;
332
Jiange Zhaob4def372019-10-28 18:04:14 +0800333 if (!amdgpu_sriov_vf(adev) && smu_baco_is_support(smu))
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500334 return AMD_RESET_METHOD_BACO;
335 else
336 return AMD_RESET_METHOD_MODE1;
337}
338
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800339static int nv_asic_reset(struct amdgpu_device *adev)
340{
341
342 /* FIXME: it doesn't work since vega10 */
343#if 0
344 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
345
346 nv_gpu_pci_config_reset(adev);
347
348 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
349#endif
Kevin Wang767acab2019-07-05 15:58:46 -0500350 int ret = 0;
351 struct smu_context *smu = &adev->smu;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800352
Monk Liue3526252019-08-27 16:32:55 +0800353 if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
Alex Deucher2c9a0c62019-10-01 16:45:27 -0500354 if (!adev->in_suspend)
355 amdgpu_inc_vram_lost(adev);
Kevin Wang767acab2019-07-05 15:58:46 -0500356 ret = smu_baco_reset(smu);
Monk Liue3526252019-08-27 16:32:55 +0800357 } else {
Alex Deucher2c9a0c62019-10-01 16:45:27 -0500358 if (!adev->in_suspend)
359 amdgpu_inc_vram_lost(adev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800360 ret = nv_asic_mode1_reset(adev);
Monk Liue3526252019-08-27 16:32:55 +0800361 }
Kevin Wang767acab2019-07-05 15:58:46 -0500362
363 return ret;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800364}
365
366static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
367{
368 /* todo */
369 return 0;
370}
371
372static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
373{
374 /* todo */
375 return 0;
376}
377
378static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
379{
380 if (pci_is_root_bus(adev->pdev->bus))
381 return;
382
383 if (amdgpu_pcie_gen2 == 0)
384 return;
385
386 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
387 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
388 return;
389
390 /* todo */
391}
392
393static void nv_program_aspm(struct amdgpu_device *adev)
394{
395
396 if (amdgpu_aspm == 0)
397 return;
398
399 /* todo */
400}
401
402static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
403 bool enable)
404{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800405 adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
406 adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800407}
408
409static const struct amdgpu_ip_block_version nv_common_ip_block =
410{
411 .type = AMD_IP_BLOCK_TYPE_COMMON,
412 .major = 1,
413 .minor = 0,
414 .rev = 0,
415 .funcs = &nv_common_ip_funcs,
416};
417
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800418static int nv_reg_base_init(struct amdgpu_device *adev)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800419{
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800420 int r;
421
422 if (amdgpu_discovery) {
423 r = amdgpu_discovery_reg_base_init(adev);
424 if (r) {
425 DRM_WARN("failed to init reg base from ip discovery table, "
426 "fallback to legacy init method\n");
427 goto legacy_init;
428 }
429
430 return 0;
431 }
432
433legacy_init:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800434 switch (adev->asic_type) {
435 case CHIP_NAVI10:
436 navi10_reg_base_init(adev);
437 break;
Xiaojie Yuana0f6d9262018-12-17 18:24:03 +0800438 case CHIP_NAVI14:
439 navi14_reg_base_init(adev);
440 break;
Xiaojie Yuan03d0a072019-05-14 15:22:53 +0800441 case CHIP_NAVI12:
442 navi12_reg_base_init(adev);
443 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800444 default:
445 return -EINVAL;
446 }
447
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800448 return 0;
449}
450
451int nv_set_ip_blocks(struct amdgpu_device *adev)
452{
453 int r;
454
455 /* Set IP register base before any HW register access */
456 r = nv_reg_base_init(adev);
457 if (r)
458 return r;
459
Hawking Zhangbebc0762019-08-23 19:39:18 +0800460 adev->nbio.funcs = &nbio_v2_3_funcs;
461 adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800462
Hawking Zhangbebc0762019-08-23 19:39:18 +0800463 adev->nbio.funcs->detect_hw_virt(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800464
Jiange Zhaob05b6902019-09-11 17:29:07 +0800465 if (amdgpu_sriov_vf(adev))
466 adev->virt.ops = &xgpu_nv_virt_ops;
467
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800468 switch (adev->asic_type) {
469 case CHIP_NAVI10:
Alex Deucherd1daf852019-07-02 14:42:25 -0500470 case CHIP_NAVI14:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800471 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
472 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
473 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
474 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
475 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
Jiange Zhaoa4ac7692019-09-12 13:15:35 +0800476 is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800477 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
478 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
479 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500480#if defined(CONFIG_DRM_AMD_DC)
Harry Wentlandb4f199c2019-02-26 16:25:27 -0500481 else if (amdgpu_device_has_dc_support(adev))
482 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500483#endif
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800484 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
485 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
486 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Jiange Zhaoa4ac7692019-09-12 13:15:35 +0800487 is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800488 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
489 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Leo Liu5be45a22019-11-08 15:01:42 -0500490 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800491 if (adev->enable_mes)
492 amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
493 break;
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800494 case CHIP_NAVI12:
495 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
496 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
497 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Xiaojie Yuan6b66ae22019-07-18 02:54:29 +0800498 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800499 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
Jiange Zhaoa4ac7692019-09-12 13:15:35 +0800500 is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev))
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800501 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Xiaojie Yuan79902022019-06-26 19:19:57 +0800502 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
503 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200504#if defined(CONFIG_DRM_AMD_DC)
Leo Li078655d92019-07-16 18:12:13 -0400505 else if (amdgpu_device_has_dc_support(adev))
506 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200507#endif
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800508 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
509 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800510 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Jiange Zhaoa4ac7692019-09-12 13:15:35 +0800511 is_support_sw_smu(adev) && !amdgpu_sriov_vf(adev))
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800512 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Boyuan Zhang1fbed282019-07-18 10:13:23 -0400513 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Leo Liu5be45a22019-11-08 15:01:42 -0500514 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800515 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800516 default:
517 return -EINVAL;
518 }
519
520 return 0;
521}
522
523static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
524{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800525 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800526}
527
528static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
529{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800530 adev->nbio.funcs->hdp_flush(adev, ring);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800531}
532
533static void nv_invalidate_hdp(struct amdgpu_device *adev,
534 struct amdgpu_ring *ring)
535{
536 if (!ring || !ring->funcs->emit_wreg) {
537 WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
538 } else {
539 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
540 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
541 }
542}
543
544static bool nv_need_full_reset(struct amdgpu_device *adev)
545{
546 return true;
547}
548
549static void nv_get_pcie_usage(struct amdgpu_device *adev,
550 uint64_t *count0,
551 uint64_t *count1)
552{
553 /*TODO*/
554}
555
556static bool nv_need_reset_on_init(struct amdgpu_device *adev)
557{
558#if 0
559 u32 sol_reg;
560
561 if (adev->flags & AMD_IS_APU)
562 return false;
563
564 /* Check sOS sign of life register to confirm sys driver and sOS
565 * are already been loaded.
566 */
567 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
568 if (sol_reg)
569 return true;
570#endif
571 /* TODO: re-enable it when mode1 reset is functional */
572 return false;
573}
574
Kevin Wang2af815312019-11-05 18:53:30 +0800575static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
576{
577
578 /* TODO
579 * dummy implement for pcie_replay_count sysfs interface
580 * */
581
582 return 0;
583}
584
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800585static void nv_init_doorbell_index(struct amdgpu_device *adev)
586{
587 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
588 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
589 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
590 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
591 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
592 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
593 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
594 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
595 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
596 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
597 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
598 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
599 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
600 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
601 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
602 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
603 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
604 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
605 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
606 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
607 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
608 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
609
610 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
611 adev->doorbell_index.sdma_doorbell_range = 20;
612}
613
614static const struct amdgpu_asic_funcs nv_asic_funcs =
615{
616 .read_disabled_bios = &nv_read_disabled_bios,
617 .read_bios_from_rom = &nv_read_bios_from_rom,
618 .read_register = &nv_read_register,
619 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500620 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800621 .set_vga_state = &nv_vga_set_state,
622 .get_xclk = &nv_get_xclk,
623 .set_uvd_clocks = &nv_set_uvd_clocks,
624 .set_vce_clocks = &nv_set_vce_clocks,
625 .get_config_memsize = &nv_get_config_memsize,
626 .flush_hdp = &nv_flush_hdp,
627 .invalidate_hdp = &nv_invalidate_hdp,
628 .init_doorbell_index = &nv_init_doorbell_index,
629 .need_full_reset = &nv_need_full_reset,
630 .get_pcie_usage = &nv_get_pcie_usage,
631 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800632 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Alex Deucherac742612019-11-07 18:12:17 -0500633 .supports_baco = &nv_asic_supports_baco,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800634};
635
636static int nv_common_early_init(void *handle)
637{
Yong Zhao923c0872019-09-27 23:30:05 -0400638#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800639 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
640
Yong Zhao923c0872019-09-27 23:30:05 -0400641 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
642 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800643 adev->smc_rreg = NULL;
644 adev->smc_wreg = NULL;
645 adev->pcie_rreg = &nv_pcie_rreg;
646 adev->pcie_wreg = &nv_pcie_wreg;
647
648 /* TODO: will add them during VCN v2 implementation */
649 adev->uvd_ctx_rreg = NULL;
650 adev->uvd_ctx_wreg = NULL;
651
652 adev->didt_rreg = &nv_didt_rreg;
653 adev->didt_wreg = &nv_didt_wreg;
654
655 adev->asic_funcs = &nv_asic_funcs;
656
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800657 adev->rev_id = nv_get_rev_id(adev);
658 adev->external_rev_id = 0xff;
659 switch (adev->asic_type) {
660 case CHIP_NAVI10:
661 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800662 AMD_CG_SUPPORT_GFX_CGCG |
663 AMD_CG_SUPPORT_IH_CG |
664 AMD_CG_SUPPORT_HDP_MGCG |
665 AMD_CG_SUPPORT_HDP_LS |
666 AMD_CG_SUPPORT_SDMA_MGCG |
667 AMD_CG_SUPPORT_SDMA_LS |
668 AMD_CG_SUPPORT_MC_MGCG |
669 AMD_CG_SUPPORT_MC_LS |
670 AMD_CG_SUPPORT_ATHUB_MGCG |
671 AMD_CG_SUPPORT_ATHUB_LS |
672 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500673 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800674 AMD_CG_SUPPORT_BIF_MGCG |
675 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400676 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800677 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500678 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800679 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800680 adev->external_rev_id = adev->rev_id + 0x1;
681 break;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800682 case CHIP_NAVI14:
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800683 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
684 AMD_CG_SUPPORT_GFX_CGCG |
685 AMD_CG_SUPPORT_IH_CG |
686 AMD_CG_SUPPORT_HDP_MGCG |
687 AMD_CG_SUPPORT_HDP_LS |
688 AMD_CG_SUPPORT_SDMA_MGCG |
689 AMD_CG_SUPPORT_SDMA_LS |
690 AMD_CG_SUPPORT_MC_MGCG |
691 AMD_CG_SUPPORT_MC_LS |
692 AMD_CG_SUPPORT_ATHUB_MGCG |
693 AMD_CG_SUPPORT_ATHUB_LS |
694 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500695 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800696 AMD_CG_SUPPORT_BIF_MGCG |
697 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500698 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500699 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500700 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800701 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800702 break;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800703 case CHIP_NAVI12:
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800704 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
705 AMD_CG_SUPPORT_GFX_MGLS |
706 AMD_CG_SUPPORT_GFX_CGCG |
707 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800708 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800709 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800710 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800711 AMD_CG_SUPPORT_HDP_LS |
712 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800713 AMD_CG_SUPPORT_SDMA_LS |
714 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800715 AMD_CG_SUPPORT_MC_LS |
716 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800717 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500718 AMD_CG_SUPPORT_VCN_MGCG |
719 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800720 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800721 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500722 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800723 AMD_PG_SUPPORT_ATHUB;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800724 adev->external_rev_id = adev->rev_id + 0xa;
725 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800726 default:
727 /* FIXME: not supported yet */
728 return -EINVAL;
729 }
730
Jiange Zhaob05b6902019-09-11 17:29:07 +0800731 if (amdgpu_sriov_vf(adev)) {
732 amdgpu_virt_init_setting(adev);
733 xgpu_nv_mailbox_set_irq_funcs(adev);
734 }
735
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800736 return 0;
737}
738
739static int nv_common_late_init(void *handle)
740{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800741 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
742
743 if (amdgpu_sriov_vf(adev))
744 xgpu_nv_mailbox_get_irq(adev);
745
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800746 return 0;
747}
748
749static int nv_common_sw_init(void *handle)
750{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800751 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
752
753 if (amdgpu_sriov_vf(adev))
754 xgpu_nv_mailbox_add_irq_id(adev);
755
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800756 return 0;
757}
758
759static int nv_common_sw_fini(void *handle)
760{
761 return 0;
762}
763
764static int nv_common_hw_init(void *handle)
765{
766 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
767
768 /* enable pcie gen2/3 link */
769 nv_pcie_gen3_enable(adev);
770 /* enable aspm */
771 nv_program_aspm(adev);
772 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +0800773 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -0400774 /* remap HDP registers to a hole in mmio space,
775 * for the purpose of expose those registers
776 * to process space
777 */
778 if (adev->nbio.funcs->remap_hdp_registers)
779 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800780 /* enable the doorbell aperture */
781 nv_enable_doorbell_aperture(adev, true);
782
783 return 0;
784}
785
786static int nv_common_hw_fini(void *handle)
787{
788 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
789
790 /* disable the doorbell aperture */
791 nv_enable_doorbell_aperture(adev, false);
792
793 return 0;
794}
795
796static int nv_common_suspend(void *handle)
797{
798 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
799
800 return nv_common_hw_fini(adev);
801}
802
803static int nv_common_resume(void *handle)
804{
805 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
806
807 return nv_common_hw_init(adev);
808}
809
810static bool nv_common_is_idle(void *handle)
811{
812 return true;
813}
814
815static int nv_common_wait_for_idle(void *handle)
816{
817 return 0;
818}
819
820static int nv_common_soft_reset(void *handle)
821{
822 return 0;
823}
824
825static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev,
826 bool enable)
827{
828 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
829 uint32_t hdp_mem_pwr_cntl;
830
831 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |
832 AMD_CG_SUPPORT_HDP_DS |
833 AMD_CG_SUPPORT_HDP_SD)))
834 return;
835
836 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
837 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
838
839 /* Before doing clock/power mode switch,
840 * forced on IPH & RC clock */
841 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
842 IPH_MEM_CLK_SOFT_OVERRIDE, 1);
843 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
844 RC_MEM_CLK_SOFT_OVERRIDE, 1);
845 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
846
847 /* HDP 5.0 doesn't support dynamic power mode switch,
848 * disable clock and power gating before any changing */
849 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
850 IPH_MEM_POWER_CTRL_EN, 0);
851 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
852 IPH_MEM_POWER_LS_EN, 0);
853 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
854 IPH_MEM_POWER_DS_EN, 0);
855 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
856 IPH_MEM_POWER_SD_EN, 0);
857 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
858 RC_MEM_POWER_CTRL_EN, 0);
859 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
860 RC_MEM_POWER_LS_EN, 0);
861 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
862 RC_MEM_POWER_DS_EN, 0);
863 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
864 RC_MEM_POWER_SD_EN, 0);
865 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
866
867 /* only one clock gating mode (LS/DS/SD) can be enabled */
868 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
869 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
870 HDP_MEM_POWER_CTRL,
871 IPH_MEM_POWER_LS_EN, enable);
872 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
873 HDP_MEM_POWER_CTRL,
874 RC_MEM_POWER_LS_EN, enable);
875 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) {
876 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
877 HDP_MEM_POWER_CTRL,
878 IPH_MEM_POWER_DS_EN, enable);
879 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
880 HDP_MEM_POWER_CTRL,
881 RC_MEM_POWER_DS_EN, enable);
882 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) {
883 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
884 HDP_MEM_POWER_CTRL,
885 IPH_MEM_POWER_SD_EN, enable);
886 /* RC should not use shut down mode, fallback to ds */
887 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
888 HDP_MEM_POWER_CTRL,
889 RC_MEM_POWER_DS_EN, enable);
890 }
891
892 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
893
894 /* restore IPH & RC clock override after clock/power mode changing */
895 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1);
896}
897
898static void nv_update_hdp_clock_gating(struct amdgpu_device *adev,
899 bool enable)
900{
901 uint32_t hdp_clk_cntl;
902
903 if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
904 return;
905
906 hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
907
908 if (enable) {
909 hdp_clk_cntl &=
910 ~(uint32_t)
911 (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
912 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
913 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
914 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
915 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
916 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK);
917 } else {
918 hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
919 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
920 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
921 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
922 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
923 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK;
924 }
925
926 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
927}
928
929static int nv_common_set_clockgating_state(void *handle,
930 enum amd_clockgating_state state)
931{
932 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
933
934 if (amdgpu_sriov_vf(adev))
935 return 0;
936
937 switch (adev->asic_type) {
938 case CHIP_NAVI10:
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800939 case CHIP_NAVI14:
Xiaojie Yuan7e17e582019-05-16 19:51:12 +0800940 case CHIP_NAVI12:
Hawking Zhangbebc0762019-08-23 19:39:18 +0800941 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800942 state == AMD_CG_STATE_GATE ? true : false);
Hawking Zhangbebc0762019-08-23 19:39:18 +0800943 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800944 state == AMD_CG_STATE_GATE ? true : false);
945 nv_update_hdp_mem_power_gating(adev,
946 state == AMD_CG_STATE_GATE ? true : false);
947 nv_update_hdp_clock_gating(adev,
948 state == AMD_CG_STATE_GATE ? true : false);
949 break;
950 default:
951 break;
952 }
953 return 0;
954}
955
956static int nv_common_set_powergating_state(void *handle,
957 enum amd_powergating_state state)
958{
959 /* TODO */
960 return 0;
961}
962
963static void nv_common_get_clockgating_state(void *handle, u32 *flags)
964{
965 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
966 uint32_t tmp;
967
968 if (amdgpu_sriov_vf(adev))
969 *flags = 0;
970
Hawking Zhangbebc0762019-08-23 19:39:18 +0800971 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800972
973 /* AMD_CG_SUPPORT_HDP_MGCG */
974 tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
975 if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
976 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
977 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
978 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
979 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
980 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK)))
981 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
982
983 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
984 tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
985 if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK)
986 *flags |= AMD_CG_SUPPORT_HDP_LS;
987 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK)
988 *flags |= AMD_CG_SUPPORT_HDP_DS;
989 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK)
990 *flags |= AMD_CG_SUPPORT_HDP_SD;
991
992 return;
993}
994
995static const struct amd_ip_funcs nv_common_ip_funcs = {
996 .name = "nv_common",
997 .early_init = nv_common_early_init,
998 .late_init = nv_common_late_init,
999 .sw_init = nv_common_sw_init,
1000 .sw_fini = nv_common_sw_fini,
1001 .hw_init = nv_common_hw_init,
1002 .hw_fini = nv_common_hw_fini,
1003 .suspend = nv_common_suspend,
1004 .resume = nv_common_resume,
1005 .is_idle = nv_common_is_idle,
1006 .wait_for_idle = nv_common_wait_for_idle,
1007 .soft_reset = nv_common_soft_reset,
1008 .set_clockgating_state = nv_common_set_clockgating_state,
1009 .set_powergating_state = nv_common_set_powergating_state,
1010 .get_clockgating_state = nv_common_get_clockgating_state,
1011};