blob: e2d97bcdf32894cf7f4b58ce383cb6ab6d33d84f [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"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080052#include "nv.h"
53#include "navi10_ih.h"
54#include "gfx_v10_0.h"
55#include "sdma_v5_0.h"
Likun Gao157e72e2019-06-17 13:38:29 +080056#include "sdma_v5_2.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080057#include "vcn_v2_0.h"
Leo Liu5be45a22019-11-08 15:01:42 -050058#include "jpeg_v2_0.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080059#include "dce_virtual.h"
60#include "mes_v10_1.h"
Jiange Zhaob05b6902019-09-11 17:29:07 +080061#include "mxgpu_nv.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080062
63static const struct amd_ip_funcs nv_common_ip_funcs;
64
65/*
66 * Indirect registers accessor
67 */
68static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
69{
70 unsigned long flags, address, data;
71 u32 r;
Hawking Zhangbebc0762019-08-23 19:39:18 +080072 address = adev->nbio.funcs->get_pcie_index_offset(adev);
73 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080074
75 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
76 WREG32(address, reg);
77 (void)RREG32(address);
78 r = RREG32(data);
79 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
80 return r;
81}
82
83static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
84{
85 unsigned long flags, address, data;
86
Hawking Zhangbebc0762019-08-23 19:39:18 +080087 address = adev->nbio.funcs->get_pcie_index_offset(adev);
88 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +080089
90 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
91 WREG32(address, reg);
92 (void)RREG32(address);
93 WREG32(data, v);
94 (void)RREG32(data);
95 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
96}
97
98static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
99{
100 unsigned long flags, address, data;
101 u32 r;
102
103 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
104 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
105
106 spin_lock_irqsave(&adev->didt_idx_lock, flags);
107 WREG32(address, (reg));
108 r = RREG32(data);
109 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
110 return r;
111}
112
113static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
114{
115 unsigned long flags, address, data;
116
117 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
118 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
119
120 spin_lock_irqsave(&adev->didt_idx_lock, flags);
121 WREG32(address, (reg));
122 WREG32(data, (v));
123 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
124}
125
126static u32 nv_get_config_memsize(struct amdgpu_device *adev)
127{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800128 return adev->nbio.funcs->get_memsize(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800129}
130
131static u32 nv_get_xclk(struct amdgpu_device *adev)
132{
Tao Zhou462a70d2019-05-14 11:37:32 +0800133 return adev->clock.spll.reference_freq;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800134}
135
136
137void nv_grbm_select(struct amdgpu_device *adev,
138 u32 me, u32 pipe, u32 queue, u32 vmid)
139{
140 u32 grbm_gfx_cntl = 0;
141 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
142 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
143 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
144 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
145
146 WREG32(SOC15_REG_OFFSET(GC, 0, mmGRBM_GFX_CNTL), grbm_gfx_cntl);
147}
148
149static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
150{
151 /* todo */
152}
153
154static bool nv_read_disabled_bios(struct amdgpu_device *adev)
155{
156 /* todo */
157 return false;
158}
159
160static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
161 u8 *bios, u32 length_bytes)
162{
Alex Deucher29bc37b2019-11-13 14:27:54 -0500163 u32 *dw_ptr;
164 u32 i, length_dw;
165
166 if (bios == NULL)
167 return false;
168 if (length_bytes == 0)
169 return false;
170 /* APU vbios image is part of sbios image */
171 if (adev->flags & AMD_IS_APU)
172 return false;
173
174 dw_ptr = (u32 *)bios;
175 length_dw = ALIGN(length_bytes, 4) / 4;
176
177 /* set rom index to 0 */
178 WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
179 /* read out the rom data */
180 for (i = 0; i < length_dw; i++)
181 dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
182
183 return true;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800184}
185
186static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
187 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
188 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
189 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
190 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
191 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
192 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800193 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
194 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800195 { 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
Kevin Wang3e2bb602019-07-05 12:51:45 +0800259static int nv_asic_mode1_reset(struct amdgpu_device *adev)
260{
261 u32 i;
262 int ret = 0;
263
264 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
265
266 dev_info(adev->dev, "GPU mode1 reset\n");
267
268 /* disable BM */
269 pci_clear_master(adev->pdev);
270
271 pci_save_state(adev->pdev);
272
273 ret = psp_gpu_reset(adev);
274 if (ret)
275 dev_err(adev->dev, "GPU mode1 reset failed\n");
276
277 pci_restore_state(adev->pdev);
278
279 /* wait for asic to come out of reset */
280 for (i = 0; i < adev->usec_timeout; i++) {
Hawking Zhangbebc0762019-08-23 19:39:18 +0800281 u32 memsize = adev->nbio.funcs->get_memsize(adev);
Kevin Wang3e2bb602019-07-05 12:51:45 +0800282
283 if (memsize != 0xffffffff)
284 break;
285 udelay(1);
286 }
287
288 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
289
290 return ret;
291}
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500292
Alex Deucherac742612019-11-07 18:12:17 -0500293static bool nv_asic_supports_baco(struct amdgpu_device *adev)
294{
295 struct smu_context *smu = &adev->smu;
296
297 if (smu_baco_is_support(smu))
298 return true;
299 else
300 return false;
301}
302
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500303static enum amd_reset_method
304nv_asic_reset_method(struct amdgpu_device *adev)
305{
306 struct smu_context *smu = &adev->smu;
307
Jiange Zhaob4def372019-10-28 18:04:14 +0800308 if (!amdgpu_sriov_vf(adev) && smu_baco_is_support(smu))
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500309 return AMD_RESET_METHOD_BACO;
310 else
311 return AMD_RESET_METHOD_MODE1;
312}
313
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800314static int nv_asic_reset(struct amdgpu_device *adev)
315{
Kevin Wang767acab2019-07-05 15:58:46 -0500316 int ret = 0;
317 struct smu_context *smu = &adev->smu;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800318
Monk Liue3526252019-08-27 16:32:55 +0800319 if (nv_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
Alex Deucher11520f22019-10-28 15:20:03 -0400320 ret = smu_baco_enter(smu);
321 if (ret)
322 return ret;
323 ret = smu_baco_exit(smu);
324 if (ret)
325 return ret;
Monk Liue3526252019-08-27 16:32:55 +0800326 } else {
Kevin Wang3e2bb602019-07-05 12:51:45 +0800327 ret = nv_asic_mode1_reset(adev);
Monk Liue3526252019-08-27 16:32:55 +0800328 }
Kevin Wang767acab2019-07-05 15:58:46 -0500329
330 return ret;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800331}
332
333static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
334{
335 /* todo */
336 return 0;
337}
338
339static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
340{
341 /* todo */
342 return 0;
343}
344
345static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
346{
347 if (pci_is_root_bus(adev->pdev->bus))
348 return;
349
350 if (amdgpu_pcie_gen2 == 0)
351 return;
352
353 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
354 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
355 return;
356
357 /* todo */
358}
359
360static void nv_program_aspm(struct amdgpu_device *adev)
361{
362
363 if (amdgpu_aspm == 0)
364 return;
365
366 /* todo */
367}
368
369static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
370 bool enable)
371{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800372 adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
373 adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800374}
375
376static const struct amdgpu_ip_block_version nv_common_ip_block =
377{
378 .type = AMD_IP_BLOCK_TYPE_COMMON,
379 .major = 1,
380 .minor = 0,
381 .rev = 0,
382 .funcs = &nv_common_ip_funcs,
383};
384
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800385static int nv_reg_base_init(struct amdgpu_device *adev)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800386{
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800387 int r;
388
389 if (amdgpu_discovery) {
390 r = amdgpu_discovery_reg_base_init(adev);
391 if (r) {
392 DRM_WARN("failed to init reg base from ip discovery table, "
393 "fallback to legacy init method\n");
394 goto legacy_init;
395 }
396
397 return 0;
398 }
399
400legacy_init:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800401 switch (adev->asic_type) {
402 case CHIP_NAVI10:
403 navi10_reg_base_init(adev);
404 break;
Xiaojie Yuana0f6d9262018-12-17 18:24:03 +0800405 case CHIP_NAVI14:
406 navi14_reg_base_init(adev);
407 break;
Xiaojie Yuan03d0a072019-05-14 15:22:53 +0800408 case CHIP_NAVI12:
409 navi12_reg_base_init(adev);
410 break;
Likun Gaodccdbf32019-11-07 16:28:14 +0800411 case CHIP_SIENNA_CICHLID:
412 sienna_cichlid_reg_base_init(adev);
413 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800414 default:
415 return -EINVAL;
416 }
417
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800418 return 0;
419}
420
421int nv_set_ip_blocks(struct amdgpu_device *adev)
422{
423 int r;
424
Monk Liu122078d2020-03-04 23:51:51 +0800425 adev->nbio.funcs = &nbio_v2_3_funcs;
426 adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
427
428 if (amdgpu_sriov_vf(adev)) {
429 adev->virt.ops = &xgpu_nv_virt_ops;
430 /* try send GPU_INIT_DATA request to host */
431 amdgpu_virt_request_init_data(adev);
432 }
433
Xiaojie Yuanb5c73852019-08-05 16:19:45 +0800434 /* Set IP register base before any HW register access */
435 r = nv_reg_base_init(adev);
436 if (r)
437 return r;
438
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800439 switch (adev->asic_type) {
440 case CHIP_NAVI10:
Alex Deucherd1daf852019-07-02 14:42:25 -0500441 case CHIP_NAVI14:
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800442 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
443 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
444 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
445 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
446 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
Evan Quan95302732020-01-07 16:57:39 +0800447 !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800448 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
449 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
450 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500451#if defined(CONFIG_DRM_AMD_DC)
Harry Wentlandb4f199c2019-02-26 16:25:27 -0500452 else if (amdgpu_device_has_dc_support(adev))
453 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Alex Deucherf8a79762019-07-05 15:39:39 -0500454#endif
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800455 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
456 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
457 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Evan Quan95302732020-01-07 16:57:39 +0800458 !amdgpu_sriov_vf(adev))
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800459 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
460 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Leo Liu5be45a22019-11-08 15:01:42 -0500461 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800462 if (adev->enable_mes)
463 amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
464 break;
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800465 case CHIP_NAVI12:
466 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
467 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
468 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Xiaojie Yuan6b66ae22019-07-18 02:54:29 +0800469 amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
Monk Liu79bebab2020-04-22 12:09:16 +0800470 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800471 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Xiaojie Yuan79902022019-06-26 19:19:57 +0800472 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
473 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200474#if defined(CONFIG_DRM_AMD_DC)
Leo Li078655d92019-07-16 18:12:13 -0400475 else if (amdgpu_device_has_dc_support(adev))
476 amdgpu_device_ip_block_add(adev, &dm_ip_block);
Petr Cvek20c14ee2019-08-30 16:31:58 +0200477#endif
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800478 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
479 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800480 if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
Evan Quan95302732020-01-07 16:57:39 +0800481 !amdgpu_sriov_vf(adev))
Xiaojie Yuan7f47efe2019-07-16 03:26:49 +0800482 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Boyuan Zhang1fbed282019-07-18 10:13:23 -0400483 amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
Monk Liufe442492020-03-05 21:10:03 +0800484 if (!amdgpu_sriov_vf(adev))
485 amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
Xiaojie Yuan44e9e7c2019-05-16 19:58:19 +0800486 break;
Likun Gao2e1ba102019-04-18 13:49:07 +0800487 case CHIP_SIENNA_CICHLID:
488 amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
Likun Gao0b3df162019-06-16 22:34:59 +0800489 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
Likun Gao757b3af2019-06-16 22:37:56 +0800490 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Likun Gaob07e5c62020-03-24 16:24:44 -0400491 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
492 is_support_sw_smu(adev))
493 amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
Likun Gao9a986762019-08-14 17:39:03 +0800494 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
495 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Likun Gao933c8a92020-05-01 10:21:23 -0400496 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
Likun Gao157e72e2019-06-17 13:38:29 +0800497 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
Likun Gao2e1ba102019-04-18 13:49:07 +0800498 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800499 default:
500 return -EINVAL;
501 }
502
503 return 0;
504}
505
506static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
507{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800508 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800509}
510
511static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
512{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800513 adev->nbio.funcs->hdp_flush(adev, ring);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800514}
515
516static void nv_invalidate_hdp(struct amdgpu_device *adev,
517 struct amdgpu_ring *ring)
518{
519 if (!ring || !ring->funcs->emit_wreg) {
520 WREG32_SOC15_NO_KIQ(NBIO, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
521 } else {
522 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
523 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
524 }
525}
526
527static bool nv_need_full_reset(struct amdgpu_device *adev)
528{
529 return true;
530}
531
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800532static bool nv_need_reset_on_init(struct amdgpu_device *adev)
533{
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800534 u32 sol_reg;
535
536 if (adev->flags & AMD_IS_APU)
537 return false;
538
539 /* Check sOS sign of life register to confirm sys driver and sOS
540 * are already been loaded.
541 */
542 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
543 if (sol_reg)
544 return true;
Alex Deucher3967ae62020-05-28 17:28:17 -0400545
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800546 return false;
547}
548
Kevin Wang2af815312019-11-05 18:53:30 +0800549static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
550{
551
552 /* TODO
553 * dummy implement for pcie_replay_count sysfs interface
554 * */
555
556 return 0;
557}
558
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800559static void nv_init_doorbell_index(struct amdgpu_device *adev)
560{
561 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
562 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
563 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
564 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
565 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
566 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
567 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
568 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
569 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
570 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
571 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
572 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
573 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
574 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
575 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
Likun Gao157e72e2019-06-17 13:38:29 +0800576 adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
577 adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800578 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
579 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
580 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
581 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
582 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
583 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
584 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
585
586 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
587 adev->doorbell_index.sdma_doorbell_range = 20;
588}
589
590static const struct amdgpu_asic_funcs nv_asic_funcs =
591{
592 .read_disabled_bios = &nv_read_disabled_bios,
593 .read_bios_from_rom = &nv_read_bios_from_rom,
594 .read_register = &nv_read_register,
595 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500596 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800597 .set_vga_state = &nv_vga_set_state,
598 .get_xclk = &nv_get_xclk,
599 .set_uvd_clocks = &nv_set_uvd_clocks,
600 .set_vce_clocks = &nv_set_vce_clocks,
601 .get_config_memsize = &nv_get_config_memsize,
602 .flush_hdp = &nv_flush_hdp,
603 .invalidate_hdp = &nv_invalidate_hdp,
604 .init_doorbell_index = &nv_init_doorbell_index,
605 .need_full_reset = &nv_need_full_reset,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800606 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800607 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Alex Deucherac742612019-11-07 18:12:17 -0500608 .supports_baco = &nv_asic_supports_baco,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800609};
610
611static int nv_common_early_init(void *handle)
612{
Yong Zhao923c0872019-09-27 23:30:05 -0400613#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800614 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
615
Yong Zhao923c0872019-09-27 23:30:05 -0400616 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
617 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800618 adev->smc_rreg = NULL;
619 adev->smc_wreg = NULL;
620 adev->pcie_rreg = &nv_pcie_rreg;
621 adev->pcie_wreg = &nv_pcie_wreg;
622
623 /* TODO: will add them during VCN v2 implementation */
624 adev->uvd_ctx_rreg = NULL;
625 adev->uvd_ctx_wreg = NULL;
626
627 adev->didt_rreg = &nv_didt_rreg;
628 adev->didt_wreg = &nv_didt_wreg;
629
630 adev->asic_funcs = &nv_asic_funcs;
631
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800632 adev->rev_id = nv_get_rev_id(adev);
633 adev->external_rev_id = 0xff;
634 switch (adev->asic_type) {
635 case CHIP_NAVI10:
636 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800637 AMD_CG_SUPPORT_GFX_CGCG |
638 AMD_CG_SUPPORT_IH_CG |
639 AMD_CG_SUPPORT_HDP_MGCG |
640 AMD_CG_SUPPORT_HDP_LS |
641 AMD_CG_SUPPORT_SDMA_MGCG |
642 AMD_CG_SUPPORT_SDMA_LS |
643 AMD_CG_SUPPORT_MC_MGCG |
644 AMD_CG_SUPPORT_MC_LS |
645 AMD_CG_SUPPORT_ATHUB_MGCG |
646 AMD_CG_SUPPORT_ATHUB_LS |
647 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500648 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800649 AMD_CG_SUPPORT_BIF_MGCG |
650 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400651 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800652 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500653 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800654 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800655 adev->external_rev_id = adev->rev_id + 0x1;
656 break;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800657 case CHIP_NAVI14:
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800658 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
659 AMD_CG_SUPPORT_GFX_CGCG |
660 AMD_CG_SUPPORT_IH_CG |
661 AMD_CG_SUPPORT_HDP_MGCG |
662 AMD_CG_SUPPORT_HDP_LS |
663 AMD_CG_SUPPORT_SDMA_MGCG |
664 AMD_CG_SUPPORT_SDMA_LS |
665 AMD_CG_SUPPORT_MC_MGCG |
666 AMD_CG_SUPPORT_MC_LS |
667 AMD_CG_SUPPORT_ATHUB_MGCG |
668 AMD_CG_SUPPORT_ATHUB_LS |
669 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500670 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800671 AMD_CG_SUPPORT_BIF_MGCG |
672 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500673 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500674 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500675 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800676 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800677 break;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800678 case CHIP_NAVI12:
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800679 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
680 AMD_CG_SUPPORT_GFX_MGLS |
681 AMD_CG_SUPPORT_GFX_CGCG |
682 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800683 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800684 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800685 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800686 AMD_CG_SUPPORT_HDP_LS |
687 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800688 AMD_CG_SUPPORT_SDMA_LS |
689 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800690 AMD_CG_SUPPORT_MC_LS |
691 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800692 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500693 AMD_CG_SUPPORT_VCN_MGCG |
694 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800695 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800696 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500697 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800698 AMD_PG_SUPPORT_ATHUB;
Tiecheng Zhoudf5e9842020-01-08 13:44:29 +0800699 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
700 * as a consequence, the rev_id and external_rev_id are wrong.
701 * workaround it by hardcoding rev_id to 0 (default value).
702 */
703 if (amdgpu_sriov_vf(adev))
704 adev->rev_id = 0;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800705 adev->external_rev_id = adev->rev_id + 0xa;
706 break;
Likun Gao117910e2019-03-19 11:04:03 +0800707 case CHIP_SIENNA_CICHLID:
708 adev->cg_flags = 0;
709 adev->pg_flags = 0;
710 adev->external_rev_id = adev->rev_id + 0x28;
711 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800712 default:
713 /* FIXME: not supported yet */
714 return -EINVAL;
715 }
716
Jiange Zhaob05b6902019-09-11 17:29:07 +0800717 if (amdgpu_sriov_vf(adev)) {
718 amdgpu_virt_init_setting(adev);
719 xgpu_nv_mailbox_set_irq_funcs(adev);
720 }
721
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800722 return 0;
723}
724
725static int nv_common_late_init(void *handle)
726{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800727 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
728
729 if (amdgpu_sriov_vf(adev))
730 xgpu_nv_mailbox_get_irq(adev);
731
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800732 return 0;
733}
734
735static int nv_common_sw_init(void *handle)
736{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800737 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
738
739 if (amdgpu_sriov_vf(adev))
740 xgpu_nv_mailbox_add_irq_id(adev);
741
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800742 return 0;
743}
744
745static int nv_common_sw_fini(void *handle)
746{
747 return 0;
748}
749
750static int nv_common_hw_init(void *handle)
751{
752 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
753
754 /* enable pcie gen2/3 link */
755 nv_pcie_gen3_enable(adev);
756 /* enable aspm */
757 nv_program_aspm(adev);
758 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +0800759 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -0400760 /* remap HDP registers to a hole in mmio space,
761 * for the purpose of expose those registers
762 * to process space
763 */
764 if (adev->nbio.funcs->remap_hdp_registers)
765 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800766 /* enable the doorbell aperture */
767 nv_enable_doorbell_aperture(adev, true);
768
769 return 0;
770}
771
772static int nv_common_hw_fini(void *handle)
773{
774 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
775
776 /* disable the doorbell aperture */
777 nv_enable_doorbell_aperture(adev, false);
778
779 return 0;
780}
781
782static int nv_common_suspend(void *handle)
783{
784 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
785
786 return nv_common_hw_fini(adev);
787}
788
789static int nv_common_resume(void *handle)
790{
791 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
792
793 return nv_common_hw_init(adev);
794}
795
796static bool nv_common_is_idle(void *handle)
797{
798 return true;
799}
800
801static int nv_common_wait_for_idle(void *handle)
802{
803 return 0;
804}
805
806static int nv_common_soft_reset(void *handle)
807{
808 return 0;
809}
810
811static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev,
812 bool enable)
813{
814 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
815 uint32_t hdp_mem_pwr_cntl;
816
817 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |
818 AMD_CG_SUPPORT_HDP_DS |
819 AMD_CG_SUPPORT_HDP_SD)))
820 return;
821
822 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
823 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
824
825 /* Before doing clock/power mode switch,
826 * forced on IPH & RC clock */
827 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
828 IPH_MEM_CLK_SOFT_OVERRIDE, 1);
829 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
830 RC_MEM_CLK_SOFT_OVERRIDE, 1);
831 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
832
833 /* HDP 5.0 doesn't support dynamic power mode switch,
834 * disable clock and power gating before any changing */
835 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
836 IPH_MEM_POWER_CTRL_EN, 0);
837 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
838 IPH_MEM_POWER_LS_EN, 0);
839 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
840 IPH_MEM_POWER_DS_EN, 0);
841 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
842 IPH_MEM_POWER_SD_EN, 0);
843 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
844 RC_MEM_POWER_CTRL_EN, 0);
845 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
846 RC_MEM_POWER_LS_EN, 0);
847 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
848 RC_MEM_POWER_DS_EN, 0);
849 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
850 RC_MEM_POWER_SD_EN, 0);
851 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
852
853 /* only one clock gating mode (LS/DS/SD) can be enabled */
854 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
855 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
856 HDP_MEM_POWER_CTRL,
857 IPH_MEM_POWER_LS_EN, enable);
858 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
859 HDP_MEM_POWER_CTRL,
860 RC_MEM_POWER_LS_EN, enable);
861 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) {
862 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
863 HDP_MEM_POWER_CTRL,
864 IPH_MEM_POWER_DS_EN, enable);
865 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
866 HDP_MEM_POWER_CTRL,
867 RC_MEM_POWER_DS_EN, enable);
868 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) {
869 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
870 HDP_MEM_POWER_CTRL,
871 IPH_MEM_POWER_SD_EN, enable);
872 /* RC should not use shut down mode, fallback to ds */
873 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
874 HDP_MEM_POWER_CTRL,
875 RC_MEM_POWER_DS_EN, enable);
876 }
877
878 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
879
880 /* restore IPH & RC clock override after clock/power mode changing */
881 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1);
882}
883
884static void nv_update_hdp_clock_gating(struct amdgpu_device *adev,
885 bool enable)
886{
887 uint32_t hdp_clk_cntl;
888
889 if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
890 return;
891
892 hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
893
894 if (enable) {
895 hdp_clk_cntl &=
896 ~(uint32_t)
897 (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
898 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
899 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
900 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
901 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
902 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK);
903 } else {
904 hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
905 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
906 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
907 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
908 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
909 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK;
910 }
911
912 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
913}
914
915static int nv_common_set_clockgating_state(void *handle,
916 enum amd_clockgating_state state)
917{
918 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
919
920 if (amdgpu_sriov_vf(adev))
921 return 0;
922
923 switch (adev->asic_type) {
924 case CHIP_NAVI10:
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800925 case CHIP_NAVI14:
Xiaojie Yuan7e17e582019-05-16 19:51:12 +0800926 case CHIP_NAVI12:
Likun Gao117910e2019-03-19 11:04:03 +0800927 case CHIP_SIENNA_CICHLID:
Hawking Zhangbebc0762019-08-23 19:39:18 +0800928 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +0100929 state == AMD_CG_STATE_GATE);
Hawking Zhangbebc0762019-08-23 19:39:18 +0800930 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +0100931 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800932 nv_update_hdp_mem_power_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +0100933 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800934 nv_update_hdp_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +0100935 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800936 break;
937 default:
938 break;
939 }
940 return 0;
941}
942
943static int nv_common_set_powergating_state(void *handle,
944 enum amd_powergating_state state)
945{
946 /* TODO */
947 return 0;
948}
949
950static void nv_common_get_clockgating_state(void *handle, u32 *flags)
951{
952 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
953 uint32_t tmp;
954
955 if (amdgpu_sriov_vf(adev))
956 *flags = 0;
957
Hawking Zhangbebc0762019-08-23 19:39:18 +0800958 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800959
960 /* AMD_CG_SUPPORT_HDP_MGCG */
961 tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
962 if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
963 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
964 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
965 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
966 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
967 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK)))
968 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
969
970 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
971 tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
972 if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK)
973 *flags |= AMD_CG_SUPPORT_HDP_LS;
974 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK)
975 *flags |= AMD_CG_SUPPORT_HDP_DS;
976 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK)
977 *flags |= AMD_CG_SUPPORT_HDP_SD;
978
979 return;
980}
981
982static const struct amd_ip_funcs nv_common_ip_funcs = {
983 .name = "nv_common",
984 .early_init = nv_common_early_init,
985 .late_init = nv_common_late_init,
986 .sw_init = nv_common_sw_init,
987 .sw_fini = nv_common_sw_fini,
988 .hw_init = nv_common_hw_init,
989 .hw_fini = nv_common_hw_fini,
990 .suspend = nv_common_suspend,
991 .resume = nv_common_resume,
992 .is_idle = nv_common_is_idle,
993 .wait_for_idle = nv_common_wait_for_idle,
994 .soft_reset = nv_common_soft_reset,
995 .set_clockgating_state = nv_common_set_clockgating_state,
996 .set_powergating_state = nv_common_set_powergating_state,
997 .get_clockgating_state = nv_common_get_clockgating_state,
998};