blob: 229ec1d88bb640fc7b6e84fe36d7371fded57e2c [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 Zhou76a2d9e2020-03-11 12:09:57 +0800633 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
634 amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
Tao Zhoufeb63292020-10-02 11:40:44 -0400635 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
Tao Zhou01069222020-10-02 11:42:31 -0400636 amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
Tao Zhou2aa92b12020-10-02 11:35:47 -0400637 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800638 default:
639 return -EINVAL;
640 }
641
642 return 0;
643}
644
645static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
646{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800647 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800648}
649
650static void nv_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
651{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800652 adev->nbio.funcs->hdp_flush(adev, ring);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800653}
654
655static void nv_invalidate_hdp(struct amdgpu_device *adev,
656 struct amdgpu_ring *ring)
657{
658 if (!ring || !ring->funcs->emit_wreg) {
Stanley.Yang78f0aef2020-09-22 16:56:54 +0800659 WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800660 } else {
661 amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
662 HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
663 }
664}
665
666static bool nv_need_full_reset(struct amdgpu_device *adev)
667{
668 return true;
669}
670
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800671static bool nv_need_reset_on_init(struct amdgpu_device *adev)
672{
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800673 u32 sol_reg;
674
675 if (adev->flags & AMD_IS_APU)
676 return false;
677
678 /* Check sOS sign of life register to confirm sys driver and sOS
679 * are already been loaded.
680 */
681 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
682 if (sol_reg)
683 return true;
Alex Deucher3967ae62020-05-28 17:28:17 -0400684
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800685 return false;
686}
687
Kevin Wang2af815312019-11-05 18:53:30 +0800688static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
689{
690
691 /* TODO
692 * dummy implement for pcie_replay_count sysfs interface
693 * */
694
695 return 0;
696}
697
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800698static void nv_init_doorbell_index(struct amdgpu_device *adev)
699{
700 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
701 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
702 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
703 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
704 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
705 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
706 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
707 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
708 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
709 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
710 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
711 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
712 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
Jack Xiao20519232019-04-26 18:58:41 +0800713 adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800714 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
715 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
Likun Gao157e72e2019-06-17 13:38:29 +0800716 adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
717 adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800718 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
719 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
720 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
721 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
722 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
723 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
724 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
725
726 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
727 adev->doorbell_index.sdma_doorbell_range = 20;
728}
729
Alex Deuchera7173732020-08-19 17:04:47 -0400730static void nv_pre_asic_init(struct amdgpu_device *adev)
731{
732}
733
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800734static const struct amdgpu_asic_funcs nv_asic_funcs =
735{
736 .read_disabled_bios = &nv_read_disabled_bios,
737 .read_bios_from_rom = &nv_read_bios_from_rom,
738 .read_register = &nv_read_register,
739 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500740 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800741 .set_vga_state = &nv_vga_set_state,
742 .get_xclk = &nv_get_xclk,
743 .set_uvd_clocks = &nv_set_uvd_clocks,
744 .set_vce_clocks = &nv_set_vce_clocks,
745 .get_config_memsize = &nv_get_config_memsize,
746 .flush_hdp = &nv_flush_hdp,
747 .invalidate_hdp = &nv_invalidate_hdp,
748 .init_doorbell_index = &nv_init_doorbell_index,
749 .need_full_reset = &nv_need_full_reset,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800750 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800751 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Alex Deucherac742612019-11-07 18:12:17 -0500752 .supports_baco = &nv_asic_supports_baco,
Alex Deuchera7173732020-08-19 17:04:47 -0400753 .pre_asic_init = &nv_pre_asic_init,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800754};
755
756static int nv_common_early_init(void *handle)
757{
Yong Zhao923c0872019-09-27 23:30:05 -0400758#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800759 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
760
Yong Zhao923c0872019-09-27 23:30:05 -0400761 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
762 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800763 adev->smc_rreg = NULL;
764 adev->smc_wreg = NULL;
765 adev->pcie_rreg = &nv_pcie_rreg;
766 adev->pcie_wreg = &nv_pcie_wreg;
John Clements4922f1bc2020-07-22 09:40:11 +0800767 adev->pcie_rreg64 = &nv_pcie_rreg64;
768 adev->pcie_wreg64 = &nv_pcie_wreg64;
Huang Rui5de54342020-08-27 12:01:26 -0400769 adev->pciep_rreg = &nv_pcie_port_rreg;
770 adev->pciep_wreg = &nv_pcie_port_wreg;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800771
772 /* TODO: will add them during VCN v2 implementation */
773 adev->uvd_ctx_rreg = NULL;
774 adev->uvd_ctx_wreg = NULL;
775
776 adev->didt_rreg = &nv_didt_rreg;
777 adev->didt_wreg = &nv_didt_wreg;
778
779 adev->asic_funcs = &nv_asic_funcs;
780
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800781 adev->rev_id = nv_get_rev_id(adev);
782 adev->external_rev_id = 0xff;
783 switch (adev->asic_type) {
784 case CHIP_NAVI10:
785 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800786 AMD_CG_SUPPORT_GFX_CGCG |
787 AMD_CG_SUPPORT_IH_CG |
788 AMD_CG_SUPPORT_HDP_MGCG |
789 AMD_CG_SUPPORT_HDP_LS |
790 AMD_CG_SUPPORT_SDMA_MGCG |
791 AMD_CG_SUPPORT_SDMA_LS |
792 AMD_CG_SUPPORT_MC_MGCG |
793 AMD_CG_SUPPORT_MC_LS |
794 AMD_CG_SUPPORT_ATHUB_MGCG |
795 AMD_CG_SUPPORT_ATHUB_LS |
796 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500797 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800798 AMD_CG_SUPPORT_BIF_MGCG |
799 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400800 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800801 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500802 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800803 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800804 adev->external_rev_id = adev->rev_id + 0x1;
805 break;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800806 case CHIP_NAVI14:
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800807 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
808 AMD_CG_SUPPORT_GFX_CGCG |
809 AMD_CG_SUPPORT_IH_CG |
810 AMD_CG_SUPPORT_HDP_MGCG |
811 AMD_CG_SUPPORT_HDP_LS |
812 AMD_CG_SUPPORT_SDMA_MGCG |
813 AMD_CG_SUPPORT_SDMA_LS |
814 AMD_CG_SUPPORT_MC_MGCG |
815 AMD_CG_SUPPORT_MC_LS |
816 AMD_CG_SUPPORT_ATHUB_MGCG |
817 AMD_CG_SUPPORT_ATHUB_LS |
818 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500819 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800820 AMD_CG_SUPPORT_BIF_MGCG |
821 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500822 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500823 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500824 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800825 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800826 break;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800827 case CHIP_NAVI12:
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800828 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
829 AMD_CG_SUPPORT_GFX_MGLS |
830 AMD_CG_SUPPORT_GFX_CGCG |
831 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800832 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800833 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800834 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800835 AMD_CG_SUPPORT_HDP_LS |
836 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800837 AMD_CG_SUPPORT_SDMA_LS |
838 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800839 AMD_CG_SUPPORT_MC_LS |
840 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800841 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500842 AMD_CG_SUPPORT_VCN_MGCG |
843 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800844 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800845 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500846 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800847 AMD_PG_SUPPORT_ATHUB;
Tiecheng Zhoudf5e9842020-01-08 13:44:29 +0800848 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
849 * as a consequence, the rev_id and external_rev_id are wrong.
850 * workaround it by hardcoding rev_id to 0 (default value).
851 */
852 if (amdgpu_sriov_vf(adev))
853 adev->rev_id = 0;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800854 adev->external_rev_id = adev->rev_id + 0xa;
855 break;
Likun Gao117910e2019-03-19 11:04:03 +0800856 case CHIP_SIENNA_CICHLID:
Likun Gao00194de2020-01-24 03:57:55 +0800857 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
858 AMD_CG_SUPPORT_GFX_CGCG |
859 AMD_CG_SUPPORT_GFX_3D_CGCG |
Likun Gao98f8ea22020-03-18 17:33:47 -0400860 AMD_CG_SUPPORT_MC_MGCG |
Likun Gao00194de2020-01-24 03:57:55 +0800861 AMD_CG_SUPPORT_VCN_MGCG |
Kenneth Fengca364612020-02-28 11:57:04 +0800862 AMD_CG_SUPPORT_JPEG_MGCG |
863 AMD_CG_SUPPORT_HDP_MGCG |
Kenneth Feng3a32c252020-02-28 14:09:31 +0800864 AMD_CG_SUPPORT_HDP_LS |
Kenneth Fengbcc83672020-02-28 14:14:00 +0800865 AMD_CG_SUPPORT_IH_CG |
866 AMD_CG_SUPPORT_MC_LS;
Leo Liub467c4f2019-12-03 09:23:24 -0500867 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhangd00b0fa2020-04-02 13:28:07 -0400868 AMD_PG_SUPPORT_VCN_DPG |
Kenneth Fengb7946162020-03-26 12:01:15 +0800869 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800870 AMD_PG_SUPPORT_ATHUB |
871 AMD_PG_SUPPORT_MMHUB;
Jack Zhangc45fbe12020-06-23 19:36:24 +0800872 if (amdgpu_sriov_vf(adev)) {
873 /* hypervisor control CG and PG enablement */
874 adev->cg_flags = 0;
875 adev->pg_flags = 0;
876 }
Likun Gao117910e2019-03-19 11:04:03 +0800877 adev->external_rev_id = adev->rev_id + 0x28;
878 break;
Jiansong Chen543aa252020-02-10 17:00:28 +0800879 case CHIP_NAVY_FLOUNDER:
Jiansong Chen40582e62020-07-02 15:34:37 +0800880 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
881 AMD_CG_SUPPORT_GFX_CGCG |
882 AMD_CG_SUPPORT_GFX_3D_CGCG |
883 AMD_CG_SUPPORT_VCN_MGCG |
Jiansong Chen92c73752020-07-08 18:53:36 +0800884 AMD_CG_SUPPORT_JPEG_MGCG |
885 AMD_CG_SUPPORT_MC_MGCG |
Jiansong Chen4759f882020-07-08 18:59:11 +0800886 AMD_CG_SUPPORT_MC_LS |
887 AMD_CG_SUPPORT_HDP_MGCG |
Jiansong Chen85e71512020-07-08 19:02:14 +0800888 AMD_CG_SUPPORT_HDP_LS |
889 AMD_CG_SUPPORT_IH_CG;
Boyuan Zhangc6e9dd02020-07-01 17:59:51 -0400890 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhang00740df2020-07-01 18:02:32 -0400891 AMD_PG_SUPPORT_VCN_DPG |
Jiansong Chen47fc8942020-07-08 18:42:04 +0800892 AMD_PG_SUPPORT_JPEG |
893 AMD_PG_SUPPORT_ATHUB |
894 AMD_PG_SUPPORT_MMHUB;
Jiansong Chen543aa252020-02-10 17:00:28 +0800895 adev->external_rev_id = adev->rev_id + 0x32;
896 break;
897
Huang Rui026570e2020-08-27 10:46:19 -0400898 case CHIP_VANGOGH:
Huang Ruiac0dc4c2020-09-22 19:08:31 +0800899 adev->cg_flags = AMD_CG_SUPPORT_GFX_CGCG |
900 AMD_CG_SUPPORT_GFX_CGLS |
901 AMD_CG_SUPPORT_GFX_3D_CGCG |
902 AMD_CG_SUPPORT_GFX_3D_CGLS;
903 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG;
Huang Rui026570e2020-08-27 10:46:19 -0400904 adev->external_rev_id = adev->rev_id + 0x01;
905 break;
Tao Zhou550c58e2020-10-02 11:30:54 -0400906 case CHIP_DIMGREY_CAVEFISH:
Tao Zhou583e5a52020-08-10 17:15:23 +0800907 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
908 AMD_CG_SUPPORT_GFX_CGCG |
909 AMD_CG_SUPPORT_GFX_3D_CGCG |
910 AMD_CG_SUPPORT_VCN_MGCG |
Tao Zhou135333a2020-08-10 17:34:30 +0800911 AMD_CG_SUPPORT_JPEG_MGCG |
912 AMD_CG_SUPPORT_MC_MGCG |
913 AMD_CG_SUPPORT_MC_LS;
James Zhud5bc1572020-08-05 17:54:21 -0400914 adev->pg_flags = AMD_PG_SUPPORT_VCN |
James Zhucc6161a2020-08-05 17:59:09 -0400915 AMD_PG_SUPPORT_VCN_DPG |
Tao Zhou73da8e82020-08-10 17:38:47 +0800916 AMD_PG_SUPPORT_JPEG |
917 AMD_PG_SUPPORT_ATHUB |
918 AMD_PG_SUPPORT_MMHUB;
Tao Zhou550c58e2020-10-02 11:30:54 -0400919 adev->external_rev_id = adev->rev_id + 0x3c;
920 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800921 default:
922 /* FIXME: not supported yet */
923 return -EINVAL;
924 }
925
Jiange Zhaob05b6902019-09-11 17:29:07 +0800926 if (amdgpu_sriov_vf(adev)) {
927 amdgpu_virt_init_setting(adev);
928 xgpu_nv_mailbox_set_irq_funcs(adev);
929 }
930
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800931 return 0;
932}
933
934static int nv_common_late_init(void *handle)
935{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800936 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
937
938 if (amdgpu_sriov_vf(adev))
939 xgpu_nv_mailbox_get_irq(adev);
940
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800941 return 0;
942}
943
944static int nv_common_sw_init(void *handle)
945{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800946 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
947
948 if (amdgpu_sriov_vf(adev))
949 xgpu_nv_mailbox_add_irq_id(adev);
950
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800951 return 0;
952}
953
954static int nv_common_sw_fini(void *handle)
955{
956 return 0;
957}
958
959static int nv_common_hw_init(void *handle)
960{
961 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
962
963 /* enable pcie gen2/3 link */
964 nv_pcie_gen3_enable(adev);
965 /* enable aspm */
966 nv_program_aspm(adev);
967 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +0800968 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -0400969 /* remap HDP registers to a hole in mmio space,
970 * for the purpose of expose those registers
971 * to process space
972 */
973 if (adev->nbio.funcs->remap_hdp_registers)
974 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800975 /* enable the doorbell aperture */
976 nv_enable_doorbell_aperture(adev, true);
977
978 return 0;
979}
980
981static int nv_common_hw_fini(void *handle)
982{
983 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
984
985 /* disable the doorbell aperture */
986 nv_enable_doorbell_aperture(adev, false);
987
988 return 0;
989}
990
991static int nv_common_suspend(void *handle)
992{
993 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
994
995 return nv_common_hw_fini(adev);
996}
997
998static int nv_common_resume(void *handle)
999{
1000 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1001
1002 return nv_common_hw_init(adev);
1003}
1004
1005static bool nv_common_is_idle(void *handle)
1006{
1007 return true;
1008}
1009
1010static int nv_common_wait_for_idle(void *handle)
1011{
1012 return 0;
1013}
1014
1015static int nv_common_soft_reset(void *handle)
1016{
1017 return 0;
1018}
1019
1020static void nv_update_hdp_mem_power_gating(struct amdgpu_device *adev,
1021 bool enable)
1022{
1023 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
1024 uint32_t hdp_mem_pwr_cntl;
1025
1026 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |
1027 AMD_CG_SUPPORT_HDP_DS |
1028 AMD_CG_SUPPORT_HDP_SD)))
1029 return;
1030
1031 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1032 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1033
1034 /* Before doing clock/power mode switch,
1035 * forced on IPH & RC clock */
1036 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1037 IPH_MEM_CLK_SOFT_OVERRIDE, 1);
1038 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,
1039 RC_MEM_CLK_SOFT_OVERRIDE, 1);
1040 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1041
1042 /* HDP 5.0 doesn't support dynamic power mode switch,
1043 * disable clock and power gating before any changing */
1044 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1045 IPH_MEM_POWER_CTRL_EN, 0);
1046 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1047 IPH_MEM_POWER_LS_EN, 0);
1048 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1049 IPH_MEM_POWER_DS_EN, 0);
1050 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1051 IPH_MEM_POWER_SD_EN, 0);
1052 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1053 RC_MEM_POWER_CTRL_EN, 0);
1054 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1055 RC_MEM_POWER_LS_EN, 0);
1056 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1057 RC_MEM_POWER_DS_EN, 0);
1058 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1059 RC_MEM_POWER_SD_EN, 0);
1060 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1061
1062 /* only one clock gating mode (LS/DS/SD) can be enabled */
1063 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS) {
1064 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1065 HDP_MEM_POWER_CTRL,
1066 IPH_MEM_POWER_LS_EN, enable);
1067 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1068 HDP_MEM_POWER_CTRL,
1069 RC_MEM_POWER_LS_EN, enable);
1070 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS) {
1071 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1072 HDP_MEM_POWER_CTRL,
1073 IPH_MEM_POWER_DS_EN, enable);
1074 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1075 HDP_MEM_POWER_CTRL,
1076 RC_MEM_POWER_DS_EN, enable);
1077 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD) {
1078 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1079 HDP_MEM_POWER_CTRL,
1080 IPH_MEM_POWER_SD_EN, enable);
1081 /* RC should not use shut down mode, fallback to ds */
1082 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,
1083 HDP_MEM_POWER_CTRL,
1084 RC_MEM_POWER_DS_EN, enable);
1085 }
1086
Kenneth Feng91c6adf2020-02-28 11:57:04 +08001087 /* confirmed that IPH_MEM_POWER_CTRL_EN and RC_MEM_POWER_CTRL_EN have to
1088 * be set for SRAM LS/DS/SD */
1089 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS | AMD_CG_SUPPORT_HDP_DS |
1090 AMD_CG_SUPPORT_HDP_SD)) {
1091 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1092 IPH_MEM_POWER_CTRL_EN, 1);
1093 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,
1094 RC_MEM_POWER_CTRL_EN, 1);
1095 }
1096
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001097 WREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl);
1098
1099 /* restore IPH & RC clock override after clock/power mode changing */
1100 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl1);
1101}
1102
1103static void nv_update_hdp_clock_gating(struct amdgpu_device *adev,
1104 bool enable)
1105{
1106 uint32_t hdp_clk_cntl;
1107
1108 if (!(adev->cg_flags & AMD_CG_SUPPORT_HDP_MGCG))
1109 return;
1110
1111 hdp_clk_cntl = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1112
1113 if (enable) {
1114 hdp_clk_cntl &=
1115 ~(uint32_t)
1116 (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1117 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1118 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1119 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1120 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1121 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK);
1122 } else {
1123 hdp_clk_cntl |= HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1124 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1125 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1126 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1127 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1128 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK;
1129 }
1130
1131 WREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL, hdp_clk_cntl);
1132}
1133
1134static int nv_common_set_clockgating_state(void *handle,
1135 enum amd_clockgating_state state)
1136{
1137 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1138
1139 if (amdgpu_sriov_vf(adev))
1140 return 0;
1141
1142 switch (adev->asic_type) {
1143 case CHIP_NAVI10:
Xiaojie Yuan5e71e012018-12-17 18:23:27 +08001144 case CHIP_NAVI14:
Xiaojie Yuan7e17e582019-05-16 19:51:12 +08001145 case CHIP_NAVI12:
Likun Gao117910e2019-03-19 11:04:03 +08001146 case CHIP_SIENNA_CICHLID:
Jiansong Chen543aa252020-02-10 17:00:28 +08001147 case CHIP_NAVY_FLOUNDER:
Tao Zhou550c58e2020-10-02 11:30:54 -04001148 case CHIP_DIMGREY_CAVEFISH:
Hawking Zhangbebc0762019-08-23 19:39:18 +08001149 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001150 state == AMD_CG_STATE_GATE);
Hawking Zhangbebc0762019-08-23 19:39:18 +08001151 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001152 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001153 nv_update_hdp_mem_power_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001154 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001155 nv_update_hdp_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001156 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001157 break;
1158 default:
1159 break;
1160 }
1161 return 0;
1162}
1163
1164static int nv_common_set_powergating_state(void *handle,
1165 enum amd_powergating_state state)
1166{
1167 /* TODO */
1168 return 0;
1169}
1170
1171static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1172{
1173 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1174 uint32_t tmp;
1175
1176 if (amdgpu_sriov_vf(adev))
1177 *flags = 0;
1178
Hawking Zhangbebc0762019-08-23 19:39:18 +08001179 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001180
1181 /* AMD_CG_SUPPORT_HDP_MGCG */
1182 tmp = RREG32_SOC15(HDP, 0, mmHDP_CLK_CNTL);
1183 if (!(tmp & (HDP_CLK_CNTL__IPH_MEM_CLK_SOFT_OVERRIDE_MASK |
1184 HDP_CLK_CNTL__RC_MEM_CLK_SOFT_OVERRIDE_MASK |
1185 HDP_CLK_CNTL__DBUS_CLK_SOFT_OVERRIDE_MASK |
1186 HDP_CLK_CNTL__DYN_CLK_SOFT_OVERRIDE_MASK |
1187 HDP_CLK_CNTL__XDP_REG_CLK_SOFT_OVERRIDE_MASK |
1188 HDP_CLK_CNTL__HDP_REG_CLK_SOFT_OVERRIDE_MASK)))
1189 *flags |= AMD_CG_SUPPORT_HDP_MGCG;
1190
1191 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
1192 tmp = RREG32_SOC15(HDP, 0, mmHDP_MEM_POWER_CTRL);
1193 if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK)
1194 *flags |= AMD_CG_SUPPORT_HDP_LS;
1195 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_DS_EN_MASK)
1196 *flags |= AMD_CG_SUPPORT_HDP_DS;
1197 else if (tmp & HDP_MEM_POWER_CTRL__IPH_MEM_POWER_SD_EN_MASK)
1198 *flags |= AMD_CG_SUPPORT_HDP_SD;
1199
1200 return;
1201}
1202
1203static const struct amd_ip_funcs nv_common_ip_funcs = {
1204 .name = "nv_common",
1205 .early_init = nv_common_early_init,
1206 .late_init = nv_common_late_init,
1207 .sw_init = nv_common_sw_init,
1208 .sw_fini = nv_common_sw_fini,
1209 .hw_init = nv_common_hw_init,
1210 .hw_fini = nv_common_hw_fini,
1211 .suspend = nv_common_suspend,
1212 .resume = nv_common_resume,
1213 .is_idle = nv_common_is_idle,
1214 .wait_for_idle = nv_common_wait_for_idle,
1215 .soft_reset = nv_common_soft_reset,
1216 .set_clockgating_state = nv_common_set_clockgating_state,
1217 .set_powergating_state = nv_common_set_powergating_state,
1218 .get_clockgating_state = nv_common_get_clockgating_state,
1219};