blob: 7b261dc447864616afd22e7bd2b503ca21230c9b [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 Zhou771cc672020-10-02 11:39:28 -0400632 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
Tao Zhou2aa92b12020-10-02 11:35:47 -0400633 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800634 default:
635 return -EINVAL;
636 }
637
638 return 0;
639}
640
641static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
642{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800643 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800644}
645
646static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
647{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800648 adev->nbio.funcs->hdp_flush(adev, ring);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800649}
650
651static void nv_invalidate_hdp(struct amdgpu_device *adev,
652 struct amdgpu_ring *ring)
653{
654 if (!ring || !ring->funcs->emit_wreg) {
Stanley.Yang78f0aef2020-09-22 16:56:54 +0800655 WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800656 } else {
657 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
658 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
659 }
660}
661
662static bool nv_need_full_reset(struct amdgpu_device *adev)
663{
664 return true;
665}
666
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800667static bool nv_need_reset_on_init(struct amdgpu_device *adev)
668{
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800669 u32 sol_reg;
670
671 if (adev->flags & AMD_IS_APU)
672 return false;
673
674 /* Check sOS sign of life register to confirm sys driver and sOS
675 * are already been loaded.
676 */
677 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
678 if (sol_reg)
679 return true;
Alex Deucher3967ae62020-05-28 17:28:17 -0400680
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800681 return false;
682}
683
Kevin Wang2af815312019-11-05 18:53:30 +0800684static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
685{
686
687 /* TODO
688 * dummy implement for pcie_replay_count sysfs interface
689 * */
690
691 return 0;
692}
693
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800694static void nv_init_doorbell_index(struct amdgpu_device *adev)
695{
696 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
697 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
698 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
699 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
700 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
701 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
702 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
703 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
704 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
705 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
706 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
707 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
708 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
Jack Xiao20519232019-04-26 18:58:41 +0800709 adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800710 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
711 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
Likun Gao157e72e2019-06-17 13:38:29 +0800712 adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
713 adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800714 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
715 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
716 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
717 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
718 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
719 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
720 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
721
722 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
723 adev->doorbell_index.sdma_doorbell_range = 20;
724}
725
Alex Deuchera7173732020-08-19 17:04:47 -0400726static void nv_pre_asic_init(struct amdgpu_device *adev)
727{
728}
729
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800730static const struct amdgpu_asic_funcs nv_asic_funcs =
731{
732 .read_disabled_bios = &nv_read_disabled_bios,
733 .read_bios_from_rom = &nv_read_bios_from_rom,
734 .read_register = &nv_read_register,
735 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500736 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800737 .set_vga_state = &nv_vga_set_state,
738 .get_xclk = &nv_get_xclk,
739 .set_uvd_clocks = &nv_set_uvd_clocks,
740 .set_vce_clocks = &nv_set_vce_clocks,
741 .get_config_memsize = &nv_get_config_memsize,
742 .flush_hdp = &nv_flush_hdp,
743 .invalidate_hdp = &nv_invalidate_hdp,
744 .init_doorbell_index = &nv_init_doorbell_index,
745 .need_full_reset = &nv_need_full_reset,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800746 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800747 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Alex Deucherac742612019-11-07 18:12:17 -0500748 .supports_baco = &nv_asic_supports_baco,
Alex Deuchera7173732020-08-19 17:04:47 -0400749 .pre_asic_init = &nv_pre_asic_init,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800750};
751
752static int nv_common_early_init(void *handle)
753{
Yong Zhao923c0872019-09-27 23:30:05 -0400754#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800755 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
756
Yong Zhao923c0872019-09-27 23:30:05 -0400757 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
758 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800759 adev->smc_rreg = NULL;
760 adev->smc_wreg = NULL;
761 adev->pcie_rreg = &nv_pcie_rreg;
762 adev->pcie_wreg = &nv_pcie_wreg;
John Clements4922f1bc2020-07-22 09:40:11 +0800763 adev->pcie_rreg64 = &nv_pcie_rreg64;
764 adev->pcie_wreg64 = &nv_pcie_wreg64;
Huang Rui5de54342020-08-27 12:01:26 -0400765 adev->pciep_rreg = &nv_pcie_port_rreg;
766 adev->pciep_wreg = &nv_pcie_port_wreg;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800767
768 /* TODO: will add them during VCN v2 implementation */
769 adev->uvd_ctx_rreg = NULL;
770 adev->uvd_ctx_wreg = NULL;
771
772 adev->didt_rreg = &nv_didt_rreg;
773 adev->didt_wreg = &nv_didt_wreg;
774
775 adev->asic_funcs = &nv_asic_funcs;
776
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800777 adev->rev_id = nv_get_rev_id(adev);
778 adev->external_rev_id = 0xff;
779 switch (adev->asic_type) {
780 case CHIP_NAVI10:
781 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800782 AMD_CG_SUPPORT_GFX_CGCG |
783 AMD_CG_SUPPORT_IH_CG |
784 AMD_CG_SUPPORT_HDP_MGCG |
785 AMD_CG_SUPPORT_HDP_LS |
786 AMD_CG_SUPPORT_SDMA_MGCG |
787 AMD_CG_SUPPORT_SDMA_LS |
788 AMD_CG_SUPPORT_MC_MGCG |
789 AMD_CG_SUPPORT_MC_LS |
790 AMD_CG_SUPPORT_ATHUB_MGCG |
791 AMD_CG_SUPPORT_ATHUB_LS |
792 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500793 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800794 AMD_CG_SUPPORT_BIF_MGCG |
795 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400796 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800797 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500798 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800799 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800800 adev->external_rev_id = adev->rev_id + 0x1;
801 break;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800802 case CHIP_NAVI14:
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800803 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
804 AMD_CG_SUPPORT_GFX_CGCG |
805 AMD_CG_SUPPORT_IH_CG |
806 AMD_CG_SUPPORT_HDP_MGCG |
807 AMD_CG_SUPPORT_HDP_LS |
808 AMD_CG_SUPPORT_SDMA_MGCG |
809 AMD_CG_SUPPORT_SDMA_LS |
810 AMD_CG_SUPPORT_MC_MGCG |
811 AMD_CG_SUPPORT_MC_LS |
812 AMD_CG_SUPPORT_ATHUB_MGCG |
813 AMD_CG_SUPPORT_ATHUB_LS |
814 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500815 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800816 AMD_CG_SUPPORT_BIF_MGCG |
817 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500818 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500819 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500820 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800821 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800822 break;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800823 case CHIP_NAVI12:
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800824 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
825 AMD_CG_SUPPORT_GFX_MGLS |
826 AMD_CG_SUPPORT_GFX_CGCG |
827 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800828 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800829 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800830 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800831 AMD_CG_SUPPORT_HDP_LS |
832 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800833 AMD_CG_SUPPORT_SDMA_LS |
834 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800835 AMD_CG_SUPPORT_MC_LS |
836 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800837 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500838 AMD_CG_SUPPORT_VCN_MGCG |
839 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800840 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800841 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500842 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800843 AMD_PG_SUPPORT_ATHUB;
Tiecheng Zhoudf5e9842020-01-08 13:44:29 +0800844 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
845 * as a consequence, the rev_id and external_rev_id are wrong.
846 * workaround it by hardcoding rev_id to 0 (default value).
847 */
848 if (amdgpu_sriov_vf(adev))
849 adev->rev_id = 0;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800850 adev->external_rev_id = adev->rev_id + 0xa;
851 break;
Likun Gao117910e2019-03-19 11:04:03 +0800852 case CHIP_SIENNA_CICHLID:
Likun Gao00194de2020-01-24 03:57:55 +0800853 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
854 AMD_CG_SUPPORT_GFX_CGCG |
855 AMD_CG_SUPPORT_GFX_3D_CGCG |
Likun Gao98f8ea22020-03-18 17:33:47 -0400856 AMD_CG_SUPPORT_MC_MGCG |
Likun Gao00194de2020-01-24 03:57:55 +0800857 AMD_CG_SUPPORT_VCN_MGCG |
Kenneth Fengca364612020-02-28 11:57:04 +0800858 AMD_CG_SUPPORT_JPEG_MGCG |
859 AMD_CG_SUPPORT_HDP_MGCG |
Kenneth Feng3a32c252020-02-28 14:09:31 +0800860 AMD_CG_SUPPORT_HDP_LS |
Kenneth Fengbcc83672020-02-28 14:14:00 +0800861 AMD_CG_SUPPORT_IH_CG |
862 AMD_CG_SUPPORT_MC_LS;
Leo Liub467c4f2019-12-03 09:23:24 -0500863 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhangd00b0fa2020-04-02 13:28:07 -0400864 AMD_PG_SUPPORT_VCN_DPG |
Kenneth Fengb7946162020-03-26 12:01:15 +0800865 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800866 AMD_PG_SUPPORT_ATHUB |
867 AMD_PG_SUPPORT_MMHUB;
Jack Zhangc45fbe12020-06-23 19:36:24 +0800868 if (amdgpu_sriov_vf(adev)) {
869 /* hypervisor control CG and PG enablement */
870 adev->cg_flags = 0;
871 adev->pg_flags = 0;
872 }
Likun Gao117910e2019-03-19 11:04:03 +0800873 adev->external_rev_id = adev->rev_id + 0x28;
874 break;
Jiansong Chen543aa252020-02-10 17:00:28 +0800875 case CHIP_NAVY_FLOUNDER:
Jiansong Chen40582e62020-07-02 15:34:37 +0800876 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
877 AMD_CG_SUPPORT_GFX_CGCG |
878 AMD_CG_SUPPORT_GFX_3D_CGCG |
879 AMD_CG_SUPPORT_VCN_MGCG |
Jiansong Chen92c73752020-07-08 18:53:36 +0800880 AMD_CG_SUPPORT_JPEG_MGCG |
881 AMD_CG_SUPPORT_MC_MGCG |
Jiansong Chen4759f882020-07-08 18:59:11 +0800882 AMD_CG_SUPPORT_MC_LS |
883 AMD_CG_SUPPORT_HDP_MGCG |
Jiansong Chen85e71512020-07-08 19:02:14 +0800884 AMD_CG_SUPPORT_HDP_LS |
885 AMD_CG_SUPPORT_IH_CG;
Boyuan Zhangc6e9dd02020-07-01 17:59:51 -0400886 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhang00740df2020-07-01 18:02:32 -0400887 AMD_PG_SUPPORT_VCN_DPG |
Jiansong Chen47fc8942020-07-08 18:42:04 +0800888 AMD_PG_SUPPORT_JPEG |
889 AMD_PG_SUPPORT_ATHUB |
890 AMD_PG_SUPPORT_MMHUB;
Jiansong Chen543aa252020-02-10 17:00:28 +0800891 adev->external_rev_id = adev->rev_id + 0x32;
892 break;
893
Huang Rui026570e2020-08-27 10:46:19 -0400894 case CHIP_VANGOGH:
Huang Ruiac0dc4c2020-09-22 19:08:31 +0800895 adev->cg_flags = AMD_CG_SUPPORT_GFX_CGCG |
896 AMD_CG_SUPPORT_GFX_CGLS |
897 AMD_CG_SUPPORT_GFX_3D_CGCG |
898 AMD_CG_SUPPORT_GFX_3D_CGLS;
899 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG;
Huang Rui026570e2020-08-27 10:46:19 -0400900 adev->external_rev_id = adev->rev_id + 0x01;
901 break;
Tao Zhou550c58e2020-10-02 11:30:54 -0400902 case CHIP_DIMGREY_CAVEFISH:
903 adev->cg_flags = 0;
904 adev->pg_flags = 0;
905 adev->external_rev_id = adev->rev_id + 0x3c;
906 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800907 default:
908 /* FIXME: not supported yet */
909 return -EINVAL;
910 }
911
Jiange Zhaob05b6902019-09-11 17:29:07 +0800912 if (amdgpu_sriov_vf(adev)) {
913 amdgpu_virt_init_setting(adev);
914 xgpu_nv_mailbox_set_irq_funcs(adev);
915 }
916
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800917 return 0;
918}
919
920static int nv_common_late_init(void *handle)
921{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800922 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
923
924 if (amdgpu_sriov_vf(adev))
925 xgpu_nv_mailbox_get_irq(adev);
926
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800927 return 0;
928}
929
930static int nv_common_sw_init(void *handle)
931{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800932 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
933
934 if (amdgpu_sriov_vf(adev))
935 xgpu_nv_mailbox_add_irq_id(adev);
936
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800937 return 0;
938}
939
940static int nv_common_sw_fini(void *handle)
941{
942 return 0;
943}
944
945static int nv_common_hw_init(void *handle)
946{
947 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
948
949 /* enable pcie gen2/3 link */
950 nv_pcie_gen3_enable(adev);
951 /* enable aspm */
952 nv_program_aspm(adev);
953 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +0800954 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -0400955 /* remap HDP registers to a hole in mmio space,
956 * for the purpose of expose those registers
957 * to process space
958 */
959 if (adev->nbio.funcs->remap_hdp_registers)
960 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800961 /* enable the doorbell aperture */
962 nv_enable_doorbell_aperture(adev, true);
963
964 return 0;
965}
966
967static int nv_common_hw_fini(void *handle)
968{
969 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
970
971 /* disable the doorbell aperture */
972 nv_enable_doorbell_aperture(adev, false);
973
974 return 0;
975}
976
977static int nv_common_suspend(void *handle)
978{
979 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
980
981 return nv_common_hw_fini(adev);
982}
983
984static int nv_common_resume(void *handle)
985{
986 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
987
988 return nv_common_hw_init(adev);
989}
990
991static bool nv_common_is_idle(void *handle)
992{
993 return true;
994}
995
996static int nv_common_wait_for_idle(void *handle)
997{
998 return 0;
999}
1000
1001static int nv_common_soft_reset(void *handle)
1002{
1003 return 0;
1004}
1005
1006static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev,
1007 bool enable)
1008{
1009 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
1010 uint32_t hdp_mem_pwr_cntl;
1011
1012 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |
1013 AMD_CG_SUPPORT_HDP_DS |
1014 AMD_CG_SUPPORT_HDP_SD)))
1015 return;
1016
1017 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1018 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1019
1020 /* Before doing clock/power mode switch,
1021 * forced on IPH & RC clock */
1022 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1023 IPH_MEM_CLK_SOFT_OVERRIDE, 1);
1024 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1025 RC_MEM_CLK_SOFT_OVERRIDE, 1);
1026 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1027
1028 /* HDP 5.0 doesn't support dynamic power mode switch,
1029 * disable clock and power gating before any changing */
1030 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1031 IPH_MEM_POWER_CTRL_EN, 0);
1032 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1033 IPH_MEM_POWER_LS_EN, 0);
1034 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1035 IPH_MEM_POWER_DS_EN, 0);
1036 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1037 IPH_MEM_POWER_SD_EN, 0);
1038 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1039 RC_MEM_POWER_CTRL_EN, 0);
1040 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1041 RC_MEM_POWER_LS_EN, 0);
1042 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1043 RC_MEM_POWER_DS_EN, 0);
1044 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1045 RC_MEM_POWER_SD_EN, 0);
1046 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1047
1048 /* only one clock gating mode (LS/DS/SD) can be enabled */
1049 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1050 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1051 HDP_MEM_POWER_CTRL,
1052 IPH_MEM_POWER_LS_EN, enable);
1053 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1054 HDP_MEM_POWER_CTRL,
1055 RC_MEM_POWER_LS_EN, enable);
1056 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) {
1057 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1058 HDP_MEM_POWER_CTRL,
1059 IPH_MEM_POWER_DS_EN, enable);
1060 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1061 HDP_MEM_POWER_CTRL,
1062 RC_MEM_POWER_DS_EN, enable);
1063 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) {
1064 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1065 HDP_MEM_POWER_CTRL,
1066 IPH_MEM_POWER_SD_EN, enable);
1067 /* RC should not use shut down mode, fallback to ds */
1068 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1069 HDP_MEM_POWER_CTRL,
1070 RC_MEM_POWER_DS_EN, enable);
1071 }
1072
Kenneth Feng91c6adf2020-02-28 11:57:04 +08001073 /* confirmed that IPH_MEM_POWER_CTRL_EN and RC_MEM_POWER_CTRL_EN have to
1074 * be set for SRAM LS/DS/SD */
1075 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_DS |
1076 AMD_CG_SUPPORT_HDP_SD)) {
1077 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1078 IPH_MEM_POWER_CTRL_EN, 1);
1079 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1080 RC_MEM_POWER_CTRL_EN, 1);
1081 }
1082
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001083 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1084
1085 /* restore IPH & RC clock override after clock/power mode changing */
1086 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1);
1087}
1088
1089static void nv_update_hdp_clock_gating(struct amdgpu_device *adev,
1090 bool enable)
1091{
1092 uint32_t hdp_clk_cntl;
1093
1094 if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
1095 return;
1096
1097 hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1098
1099 if (enable) {
1100 hdp_clk_cntl &=
1101 ~(uint32_t)
1102 (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1103 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1104 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1105 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1106 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1107 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK);
1108 } else {
1109 hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1110 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1111 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1112 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1113 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1114 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK;
1115 }
1116
1117 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1118}
1119
1120static int nv_common_set_clockgating_state(void *handle,
1121 enum amd_clockgating_state state)
1122{
1123 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1124
1125 if (amdgpu_sriov_vf(adev))
1126 return 0;
1127
1128 switch (adev->asic_type) {
1129 case CHIP_NAVI10:
Xiaojie Yuan5e71e012018-12-17 18:23:27 +08001130 case CHIP_NAVI14:
Xiaojie Yuan7e17e582019-05-16 19:51:12 +08001131 case CHIP_NAVI12:
Likun Gao117910e2019-03-19 11:04:03 +08001132 case CHIP_SIENNA_CICHLID:
Jiansong Chen543aa252020-02-10 17:00:28 +08001133 case CHIP_NAVY_FLOUNDER:
Tao Zhou550c58e2020-10-02 11:30:54 -04001134 case CHIP_DIMGREY_CAVEFISH:
Hawking Zhangbebc0762019-08-23 19:39:18 +08001135 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001136 state == AMD_CG_STATE_GATE);
Hawking Zhangbebc0762019-08-23 19:39:18 +08001137 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001138 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001139 nv_update_hdp_mem_power_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001140 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001141 nv_update_hdp_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001142 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001143 break;
1144 default:
1145 break;
1146 }
1147 return 0;
1148}
1149
1150static int nv_common_set_powergating_state(void *handle,
1151 enum amd_powergating_state state)
1152{
1153 /* TODO */
1154 return 0;
1155}
1156
1157static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1158{
1159 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1160 uint32_t tmp;
1161
1162 if (amdgpu_sriov_vf(adev))
1163 *flags = 0;
1164
Hawking Zhangbebc0762019-08-23 19:39:18 +08001165 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001166
1167 /* AMD_CG_SUPPORT_HDP_MGCG */
1168 tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1169 if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1170 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1171 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1172 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1173 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1174 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK)))
1175 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
1176
1177 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
1178 tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1179 if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK)
1180 *flags |= AMD_CG_SUPPORT_HDP_LS;
1181 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK)
1182 *flags |= AMD_CG_SUPPORT_HDP_DS;
1183 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK)
1184 *flags |= AMD_CG_SUPPORT_HDP_SD;
1185
1186 return;
1187}
1188
1189static const struct amd_ip_funcs nv_common_ip_funcs = {
1190 .name = "nv_common",
1191 .early_init = nv_common_early_init,
1192 .late_init = nv_common_late_init,
1193 .sw_init = nv_common_sw_init,
1194 .sw_fini = nv_common_sw_fini,
1195 .hw_init = nv_common_hw_init,
1196 .hw_fini = nv_common_hw_fini,
1197 .suspend = nv_common_suspend,
1198 .resume = nv_common_resume,
1199 .is_idle = nv_common_is_idle,
1200 .wait_for_idle = nv_common_wait_for_idle,
1201 .soft_reset = nv_common_soft_reset,
1202 .set_clockgating_state = nv_common_set_clockgating_state,
1203 .set_powergating_state = nv_common_set_powergating_state,
1204 .get_clockgating_state = nv_common_get_clockgating_state,
1205};