blob: 2ec1ffb36b1fc54db2b840b2498a6963d1a36a69 [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
Alex Deucher6f786952021-02-02 11:11:45 -050028#include <drm/amdgpu_drm.h>
29
Hawking Zhangc6b6a422019-03-04 14:07:37 +080030#include "amdgpu.h"
31#include "amdgpu_atombios.h"
32#include "amdgpu_ih.h"
33#include "amdgpu_uvd.h"
34#include "amdgpu_vce.h"
35#include "amdgpu_ucode.h"
36#include "amdgpu_psp.h"
37#include "atom.h"
38#include "amd_pcie.h"
39
40#include "gc/gc_10_1_0_offset.h"
41#include "gc/gc_10_1_0_sh_mask.h"
Alex Deucher3967ae62020-05-28 17:28:17 -040042#include "mp/mp_11_0_offset.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080043
44#include "soc15.h"
45#include "soc15_common.h"
46#include "gmc_v10_0.h"
47#include "gfxhub_v2_0.h"
48#include "mmhub_v2_0.h"
Hawking Zhangbebc0762019-08-23 19:39:18 +080049#include "nbio_v2_3.h"
Huang Ruia7e91bd2020-08-27 12:02:37 -040050#include "nbio_v7_2.h"
Likun Gaobf087282020-12-28 17:02:21 +080051#include "hdp_v5_0.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080052#include "nv.h"
53#include "navi10_ih.h"
54#include "gfx_v10_0.h"
55#include "sdma_v5_0.h"
Likun Gao157e72e2019-06-17 13:38:29 +080056#include "sdma_v5_2.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080057#include "vcn_v2_0.h"
Leo Liu5be45a22019-11-08 15:01:42 -050058#include "jpeg_v2_0.h"
Leo Liub8f10582020-03-24 16:30:24 -040059#include "vcn_v3_0.h"
Leo Liu4d72dd12020-03-24 16:31:23 -040060#include "jpeg_v3_0.h"
Ryan Taylor733ee712021-06-18 13:16:37 -070061#include "amdgpu_vkms.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080062#include "mes_v10_1.h"
Jiange Zhaob05b6902019-09-11 17:29:07 +080063#include "mxgpu_nv.h"
Likun Gao0bf7f2d2021-02-03 18:23:49 +080064#include "smuio_v11_0.h"
65#include "smuio_v11_0_6.h"
Hawking Zhangc6b6a422019-03-04 14:07:37 +080066
67static const struct amd_ip_funcs nv_common_ip_funcs;
68
Alex Deucher3b246e82021-01-07 18:48:12 -050069/* Navi */
70static const struct amdgpu_video_codec_info nv_video_codecs_encode_array[] =
71{
Veerabadhran Gopalakrishnan90750962021-07-13 23:21:43 +053072 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
73 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
Alex Deucher3b246e82021-01-07 18:48:12 -050074};
75
76static const struct amdgpu_video_codecs nv_video_codecs_encode =
77{
78 .codec_count = ARRAY_SIZE(nv_video_codecs_encode_array),
79 .codec_array = nv_video_codecs_encode_array,
80};
81
82/* Navi1x */
83static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] =
84{
Veerabadhran Gopalakrishnan90750962021-07-13 23:21:43 +053085 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
86 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
87 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
88 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
89 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
90 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
91 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
Alex Deucher3b246e82021-01-07 18:48:12 -050092};
93
94static const struct amdgpu_video_codecs nv_video_codecs_decode =
95{
96 .codec_count = ARRAY_SIZE(nv_video_codecs_decode_array),
97 .codec_array = nv_video_codecs_decode_array,
98};
99
100/* Sienna Cichlid */
101static const struct amdgpu_video_codec_info sc_video_codecs_decode_array[] =
102{
Veerabadhran Gopalakrishnan90750962021-07-13 23:21:43 +0530103 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
104 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
105 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
106 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
107 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
108 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
109 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
110 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
Alex Deucher3b246e82021-01-07 18:48:12 -0500111};
112
113static const struct amdgpu_video_codecs sc_video_codecs_decode =
114{
115 .codec_count = ARRAY_SIZE(sc_video_codecs_decode_array),
116 .codec_array = sc_video_codecs_decode_array,
117};
118
Bokun Zhanged9d2052021-05-13 01:17:54 -0400119/* SRIOV Sienna Cichlid, not const since data is controlled by host */
120static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array[] =
121{
Veerabadhran Gopalakrishnan90750962021-07-13 23:21:43 +0530122 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
123 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
Bokun Zhanged9d2052021-05-13 01:17:54 -0400124};
125
126static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array[] =
127{
Veerabadhran Gopalakrishnan90750962021-07-13 23:21:43 +0530128 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
129 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
130 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
131 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
132 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
133 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
134 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
135 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
Bokun Zhanged9d2052021-05-13 01:17:54 -0400136};
137
138static struct amdgpu_video_codecs sriov_sc_video_codecs_encode =
139{
140 .codec_count = ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
141 .codec_array = sriov_sc_video_codecs_encode_array,
142};
143
144static struct amdgpu_video_codecs sriov_sc_video_codecs_decode =
145{
146 .codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array),
147 .codec_array = sriov_sc_video_codecs_decode_array,
148};
149
Veerabadhran Gopalakrishnanb3a24462021-06-19 00:10:46 +0530150/* Beige Goby*/
151static const struct amdgpu_video_codec_info bg_video_codecs_decode_array[] = {
152 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
153 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
154 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
155};
156
157static const struct amdgpu_video_codecs bg_video_codecs_decode = {
158 .codec_count = ARRAY_SIZE(bg_video_codecs_decode_array),
159 .codec_array = bg_video_codecs_decode_array,
160};
161
162static const struct amdgpu_video_codecs bg_video_codecs_encode = {
163 .codec_count = 0,
164 .codec_array = NULL,
165};
166
Veerabadhran Gopalakrishnan55439812021-07-09 13:00:11 +0530167/* Yellow Carp*/
168static const struct amdgpu_video_codec_info yc_video_codecs_decode_array[] = {
169 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
170 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
171 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
172 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
173};
174
175static const struct amdgpu_video_codecs yc_video_codecs_decode = {
Veerabadhran Gopalakrishnanf72ac402021-07-19 19:06:23 +0530176 .codec_count = ARRAY_SIZE(yc_video_codecs_decode_array),
177 .codec_array = yc_video_codecs_decode_array,
Veerabadhran Gopalakrishnan55439812021-07-09 13:00:11 +0530178};
179
Alex Deucher3b246e82021-01-07 18:48:12 -0500180static int nv_query_video_codecs(struct amdgpu_device *adev, bool encode,
181 const struct amdgpu_video_codecs **codecs)
182{
Alex Deucher1d789532021-10-04 15:19:10 -0400183 switch (adev->ip_versions[UVD_HWIP][0]) {
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400184 case IP_VERSION(3, 0, 0):
Guchun Chen4d395f92021-11-10 13:13:55 +0800185 case IP_VERSION(3, 0, 64):
Jane Jianda3b36a2021-11-23 19:19:40 +0800186 case IP_VERSION(3, 0, 192):
Bokun Zhanged9d2052021-05-13 01:17:54 -0400187 if (amdgpu_sriov_vf(adev)) {
188 if (encode)
189 *codecs = &sriov_sc_video_codecs_encode;
190 else
191 *codecs = &sriov_sc_video_codecs_decode;
192 } else {
193 if (encode)
194 *codecs = &nv_video_codecs_encode;
195 else
196 *codecs = &sc_video_codecs_decode;
197 }
198 return 0;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400199 case IP_VERSION(3, 0, 16):
200 case IP_VERSION(3, 0, 2):
Alex Deucher3b246e82021-01-07 18:48:12 -0500201 if (encode)
202 *codecs = &nv_video_codecs_encode;
203 else
204 *codecs = &sc_video_codecs_decode;
205 return 0;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400206 case IP_VERSION(3, 1, 1):
Veerabadhran Gopalakrishnan55439812021-07-09 13:00:11 +0530207 if (encode)
208 *codecs = &nv_video_codecs_encode;
209 else
210 *codecs = &yc_video_codecs_decode;
211 return 0;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400212 case IP_VERSION(3, 0, 33):
Veerabadhran Gopalakrishnanb3a24462021-06-19 00:10:46 +0530213 if (encode)
214 *codecs = &bg_video_codecs_encode;
215 else
216 *codecs = &bg_video_codecs_decode;
217 return 0;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400218 case IP_VERSION(2, 0, 0):
219 case IP_VERSION(2, 0, 2):
Alex Deucher3b246e82021-01-07 18:48:12 -0500220 if (encode)
221 *codecs = &nv_video_codecs_encode;
222 else
223 *codecs = &nv_video_codecs_decode;
224 return 0;
225 default:
226 return -EINVAL;
227 }
228}
229
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800230/*
231 * Indirect registers accessor
232 */
233static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
234{
Hawking Zhang705a2b52020-09-15 17:57:30 +0800235 unsigned long address, data;
Hawking Zhangbebc0762019-08-23 19:39:18 +0800236 address = adev->nbio.funcs->get_pcie_index_offset(adev);
237 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800238
Hawking Zhang705a2b52020-09-15 17:57:30 +0800239 return amdgpu_device_indirect_rreg(adev, address, data, reg);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800240}
241
242static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
243{
Hawking Zhang705a2b52020-09-15 17:57:30 +0800244 unsigned long address, data;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800245
Hawking Zhangbebc0762019-08-23 19:39:18 +0800246 address = adev->nbio.funcs->get_pcie_index_offset(adev);
247 data = adev->nbio.funcs->get_pcie_data_offset(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800248
Hawking Zhang705a2b52020-09-15 17:57:30 +0800249 amdgpu_device_indirect_wreg(adev, address, data, reg, v);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800250}
251
John Clements4922f1bc2020-07-22 09:40:11 +0800252static u64 nv_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
253{
Hawking Zhang705a2b52020-09-15 17:57:30 +0800254 unsigned long address, data;
John Clements4922f1bc2020-07-22 09:40:11 +0800255 address = adev->nbio.funcs->get_pcie_index_offset(adev);
256 data = adev->nbio.funcs->get_pcie_data_offset(adev);
257
Hawking Zhang705a2b52020-09-15 17:57:30 +0800258 return amdgpu_device_indirect_rreg64(adev, address, data, reg);
John Clements4922f1bc2020-07-22 09:40:11 +0800259}
260
Huang Rui5de54342020-08-27 12:01:26 -0400261static u32 nv_pcie_port_rreg(struct amdgpu_device *adev, u32 reg)
262{
263 unsigned long flags, address, data;
264 u32 r;
265 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
266 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
267
268 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
269 WREG32(address, reg * 4);
270 (void)RREG32(address);
271 r = RREG32(data);
272 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
273 return r;
274}
275
John Clements4922f1bc2020-07-22 09:40:11 +0800276static void nv_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
277{
Hawking Zhang705a2b52020-09-15 17:57:30 +0800278 unsigned long address, data;
John Clements4922f1bc2020-07-22 09:40:11 +0800279
280 address = adev->nbio.funcs->get_pcie_index_offset(adev);
281 data = adev->nbio.funcs->get_pcie_data_offset(adev);
282
Hawking Zhang705a2b52020-09-15 17:57:30 +0800283 amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
John Clements4922f1bc2020-07-22 09:40:11 +0800284}
285
Huang Rui5de54342020-08-27 12:01:26 -0400286static void nv_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
287{
288 unsigned long flags, address, data;
289
290 address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
291 data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
292
293 spin_lock_irqsave(&adev->pcie_idx_lock, flags);
294 WREG32(address, reg * 4);
295 (void)RREG32(address);
296 WREG32(data, v);
297 (void)RREG32(data);
298 spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
299}
300
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800301static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
302{
303 unsigned long flags, address, data;
304 u32 r;
305
306 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
307 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
308
309 spin_lock_irqsave(&adev->didt_idx_lock, flags);
310 WREG32(address, (reg));
311 r = RREG32(data);
312 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
313 return r;
314}
315
316static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
317{
318 unsigned long flags, address, data;
319
320 address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
321 data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
322
323 spin_lock_irqsave(&adev->didt_idx_lock, flags);
324 WREG32(address, (reg));
325 WREG32(data, (v));
326 spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
327}
328
329static u32 nv_get_config_memsize(struct amdgpu_device *adev)
330{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800331 return adev->nbio.funcs->get_memsize(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800332}
333
334static u32 nv_get_xclk(struct amdgpu_device *adev)
335{
Tao Zhou462a70d2019-05-14 11:37:32 +0800336 return adev->clock.spll.reference_freq;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800337}
338
339
340void nv_grbm_select(struct amdgpu_device *adev,
341 u32 me, u32 pipe, u32 queue, u32 vmid)
342{
343 u32 grbm_gfx_cntl = 0;
344 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
345 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
346 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
347 grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
348
Peng Ju Zhouf2958a82021-04-23 13:13:41 +0800349 WREG32_SOC15(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800350}
351
352static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
353{
354 /* todo */
355}
356
357static bool nv_read_disabled_bios(struct amdgpu_device *adev)
358{
359 /* todo */
360 return false;
361}
362
363static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
364 u8 *bios, u32 length_bytes)
365{
Alex Deucher29bc37b2019-11-13 14:27:54 -0500366 u32 *dw_ptr;
367 u32 i, length_dw;
Likun Gao0bf7f2d2021-02-03 18:23:49 +0800368 u32 rom_index_offset, rom_data_offset;
Alex Deucher29bc37b2019-11-13 14:27:54 -0500369
370 if (bios == NULL)
371 return false;
372 if (length_bytes == 0)
373 return false;
374 /* APU vbios image is part of sbios image */
375 if (adev->flags & AMD_IS_APU)
376 return false;
377
378 dw_ptr = (u32 *)bios;
379 length_dw = ALIGN(length_bytes, 4) / 4;
380
Likun Gao0bf7f2d2021-02-03 18:23:49 +0800381 rom_index_offset =
382 adev->smuio.funcs->get_rom_index_offset(adev);
383 rom_data_offset =
384 adev->smuio.funcs->get_rom_data_offset(adev);
385
Alex Deucher29bc37b2019-11-13 14:27:54 -0500386 /* set rom index to 0 */
Likun Gao0bf7f2d2021-02-03 18:23:49 +0800387 WREG32(rom_index_offset, 0);
Alex Deucher29bc37b2019-11-13 14:27:54 -0500388 /* read out the rom data */
389 for (i = 0; i < length_dw; i++)
Likun Gao0bf7f2d2021-02-03 18:23:49 +0800390 dw_ptr[i] = RREG32(rom_data_offset);
Alex Deucher29bc37b2019-11-13 14:27:54 -0500391
392 return true;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800393}
394
395static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
396 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
397 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
398 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
399 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
400 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
401 { SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800402 { SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
403 { SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800404 { SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
405 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
406 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
407 { SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
408 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
409 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
410 { SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
Marek Olšák664fe852019-10-22 17:22:38 -0400411 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800412 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
413 { SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
414 { SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
415};
416
417static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
418 u32 sh_num, u32 reg_offset)
419{
420 uint32_t val;
421
422 mutex_lock(&adev->grbm_idx_mutex);
423 if (se_num != 0xffffffff || sh_num != 0xffffffff)
424 amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
425
426 val = RREG32(reg_offset);
427
428 if (se_num != 0xffffffff || sh_num != 0xffffffff)
429 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
430 mutex_unlock(&adev->grbm_idx_mutex);
431 return val;
432}
433
434static uint32_t nv_get_register_value(struct amdgpu_device *adev,
435 bool indexed, u32 se_num,
436 u32 sh_num, u32 reg_offset)
437{
438 if (indexed) {
439 return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
440 } else {
441 if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
442 return adev->gfx.config.gb_addr_config;
443 return RREG32(reg_offset);
444 }
445}
446
447static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
448 u32 sh_num, u32 reg_offset, u32 *value)
449{
450 uint32_t i;
451 struct soc15_allowed_register_entry *en;
452
453 *value = 0;
454 for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
455 en = &nv_allowed_read_registers[i];
Huang Ruifced3c32020-08-28 22:54:32 +0800456 if ((i == 7 && (adev->sdma.num_instances == 1)) || /* some asics don't have SDMA1 */
457 reg_offset !=
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800458 (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
459 continue;
460
461 *value = nv_get_register_value(adev,
462 nv_allowed_read_registers[i].grbm_indexed,
463 se_num, sh_num, reg_offset);
464 return 0;
465 }
466 return -EINVAL;
467}
468
Alex Deucherb913ec62020-11-25 11:21:31 -0500469static int nv_asic_mode2_reset(struct amdgpu_device *adev)
470{
471 u32 i;
472 int ret = 0;
473
474 amdgpu_atombios_scratch_regs_engine_hung(adev, true);
475
476 /* disable BM */
477 pci_clear_master(adev->pdev);
478
479 amdgpu_device_cache_pci_state(adev->pdev);
480
481 ret = amdgpu_dpm_mode2_reset(adev);
482 if (ret)
483 dev_err(adev->dev, "GPU mode2 reset failed\n");
484
485 amdgpu_device_load_pci_state(adev->pdev);
486
487 /* wait for asic to come out of reset */
488 for (i = 0; i < adev->usec_timeout; i++) {
489 u32 memsize = adev->nbio.funcs->get_memsize(adev);
490
491 if (memsize != 0xffffffff)
492 break;
493 udelay(1);
494 }
495
496 amdgpu_atombios_scratch_regs_engine_hung(adev, false);
497
498 return ret;
499}
500
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500501static enum amd_reset_method
502nv_asic_reset_method(struct amdgpu_device *adev)
503{
Wenhui Sheng273da6f2020-07-14 16:29:18 +0800504 if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
Alex Deucher16086352020-11-25 11:21:30 -0500505 amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
Alex Deucherf1728652021-02-04 11:24:00 -0500506 amdgpu_reset_method == AMD_RESET_METHOD_BACO ||
507 amdgpu_reset_method == AMD_RESET_METHOD_PCI)
Wenhui Sheng273da6f2020-07-14 16:29:18 +0800508 return amdgpu_reset_method;
509
510 if (amdgpu_reset_method != -1)
511 dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
512 amdgpu_reset_method);
513
Alex Deucher1d789532021-10-04 15:19:10 -0400514 switch (adev->ip_versions[MP1_HWIP][0]) {
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400515 case IP_VERSION(11, 5, 0):
516 case IP_VERSION(13, 0, 1):
517 case IP_VERSION(13, 0, 3):
Alex Deucher16086352020-11-25 11:21:30 -0500518 return AMD_RESET_METHOD_MODE2;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400519 case IP_VERSION(11, 0, 7):
520 case IP_VERSION(11, 0, 11):
521 case IP_VERSION(11, 0, 12):
522 case IP_VERSION(11, 0, 13):
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500523 return AMD_RESET_METHOD_MODE1;
Likun Gaoca6fd7a2020-08-06 17:37:28 +0800524 default:
Evan Quan181e7722021-03-19 16:22:17 +0800525 if (amdgpu_dpm_is_baco_supported(adev))
Likun Gaoca6fd7a2020-08-06 17:37:28 +0800526 return AMD_RESET_METHOD_BACO;
527 else
528 return AMD_RESET_METHOD_MODE1;
529 }
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500530}
531
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800532static int nv_asic_reset(struct amdgpu_device *adev)
533{
Kevin Wang767acab2019-07-05 15:58:46 -0500534 int ret = 0;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800535
Alex Deucher16086352020-11-25 11:21:30 -0500536 switch (nv_asic_reset_method(adev)) {
Alex Deucherf1728652021-02-04 11:24:00 -0500537 case AMD_RESET_METHOD_PCI:
538 dev_info(adev->dev, "PCI reset\n");
539 ret = amdgpu_device_pci_reset(adev);
540 break;
Alex Deucher16086352020-11-25 11:21:30 -0500541 case AMD_RESET_METHOD_BACO:
Alex Deucher11043b72020-08-11 12:02:21 -0400542 dev_info(adev->dev, "BACO reset\n");
Evan Quan181e7722021-03-19 16:22:17 +0800543 ret = amdgpu_dpm_baco_reset(adev);
Alex Deucher16086352020-11-25 11:21:30 -0500544 break;
545 case AMD_RESET_METHOD_MODE2:
546 dev_info(adev->dev, "MODE2 reset\n");
Alex Deucherb913ec62020-11-25 11:21:31 -0500547 ret = nv_asic_mode2_reset(adev);
Alex Deucher16086352020-11-25 11:21:30 -0500548 break;
549 default:
Alex Deucher11043b72020-08-11 12:02:21 -0400550 dev_info(adev->dev, "MODE1 reset\n");
Feifei Xu5c03e582020-11-19 18:12:26 +0800551 ret = amdgpu_device_mode1_reset(adev);
Alex Deucher16086352020-11-25 11:21:30 -0500552 break;
Alex Deucher11043b72020-08-11 12:02:21 -0400553 }
Kevin Wang767acab2019-07-05 15:58:46 -0500554
555 return ret;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800556}
557
558static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
559{
560 /* todo */
561 return 0;
562}
563
564static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
565{
566 /* todo */
567 return 0;
568}
569
570static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
571{
572 if (pci_is_root_bus(adev->pdev->bus))
573 return;
574
575 if (amdgpu_pcie_gen2 == 0)
576 return;
577
578 if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
579 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
580 return;
581
582 /* todo */
583}
584
585static void nv_program_aspm(struct amdgpu_device *adev)
586{
Kenneth Feng0064b0c2021-05-11 11:00:41 +0800587 if (!amdgpu_aspm)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800588 return;
589
Kenneth Feng3273f8b2021-04-14 18:31:05 +0800590 if (!(adev->flags & AMD_IS_APU) &&
Likun Gaoe1edaea2021-02-01 14:44:09 +0800591 (adev->nbio.funcs->program_aspm))
592 adev->nbio.funcs->program_aspm(adev);
593
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800594}
595
596static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
597 bool enable)
598{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800599 adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
600 adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800601}
602
Alex Deuchera1f62df2021-07-26 15:11:44 -0400603const struct amdgpu_ip_block_version nv_common_ip_block =
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800604{
605 .type = AMD_IP_BLOCK_TYPE_COMMON,
606 .major = 1,
607 .minor = 0,
608 .rev = 0,
609 .funcs = &nv_common_ip_funcs,
610};
611
Wenhui Shengc1299462020-06-23 11:35:05 +0800612void nv_set_virt_ops(struct amdgpu_device *adev)
613{
614 adev->virt.ops = &xgpu_nv_virt_ops;
615}
616
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800617static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
618{
Hawking Zhangbebc0762019-08-23 19:39:18 +0800619 return adev->nbio.funcs->get_rev_id(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800620}
621
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800622static bool nv_need_full_reset(struct amdgpu_device *adev)
623{
624 return true;
625}
626
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800627static bool nv_need_reset_on_init(struct amdgpu_device *adev)
628{
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800629 u32 sol_reg;
630
631 if (adev->flags & AMD_IS_APU)
632 return false;
633
634 /* Check sOS sign of life register to confirm sys driver and sOS
635 * are already been loaded.
636 */
637 sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
638 if (sol_reg)
639 return true;
Alex Deucher3967ae62020-05-28 17:28:17 -0400640
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800641 return false;
642}
643
Kevin Wang2af815312019-11-05 18:53:30 +0800644static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
645{
646
647 /* TODO
648 * dummy implement for pcie_replay_count sysfs interface
649 * */
650
651 return 0;
652}
653
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800654static void nv_init_doorbell_index(struct amdgpu_device *adev)
655{
656 adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
657 adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
658 adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
659 adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
660 adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
661 adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
662 adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
663 adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
664 adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
665 adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
666 adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
667 adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
668 adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
Jack Xiao20519232019-04-26 18:58:41 +0800669 adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800670 adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
671 adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
Likun Gao157e72e2019-06-17 13:38:29 +0800672 adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
673 adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800674 adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
675 adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
676 adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
677 adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
678 adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
679 adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
680 adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
681
682 adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
683 adev->doorbell_index.sdma_doorbell_range = 20;
684}
685
Alex Deuchera7173732020-08-19 17:04:47 -0400686static void nv_pre_asic_init(struct amdgpu_device *adev)
687{
688}
689
Evan Quan27747292020-08-18 17:58:06 +0800690static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
691 bool enter)
692{
693 if (enter)
694 amdgpu_gfx_rlc_enter_safe_mode(adev);
695 else
696 amdgpu_gfx_rlc_exit_safe_mode(adev);
697
698 if (adev->gfx.funcs->update_perfmon_mgcg)
699 adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
700
Kenneth Feng3273f8b2021-04-14 18:31:05 +0800701 if (!(adev->flags & AMD_IS_APU) &&
Likun Gaoe1edaea2021-02-01 14:44:09 +0800702 (adev->nbio.funcs->enable_aspm))
Evan Quan27747292020-08-18 17:58:06 +0800703 adev->nbio.funcs->enable_aspm(adev, !enter);
Evan Quan27747292020-08-18 17:58:06 +0800704
705 return 0;
706}
707
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800708static const struct amdgpu_asic_funcs nv_asic_funcs =
709{
710 .read_disabled_bios = &nv_read_disabled_bios,
711 .read_bios_from_rom = &nv_read_bios_from_rom,
712 .read_register = &nv_read_register,
713 .reset = &nv_asic_reset,
Alex Deucher2ddc6c32019-07-23 23:48:21 -0500714 .reset_method = &nv_asic_reset_method,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800715 .set_vga_state = &nv_vga_set_state,
716 .get_xclk = &nv_get_xclk,
717 .set_uvd_clocks = &nv_set_uvd_clocks,
718 .set_vce_clocks = &nv_set_vce_clocks,
719 .get_config_memsize = &nv_get_config_memsize,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800720 .init_doorbell_index = &nv_init_doorbell_index,
721 .need_full_reset = &nv_need_full_reset,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800722 .need_reset_on_init = &nv_need_reset_on_init,
Kevin Wang2af815312019-11-05 18:53:30 +0800723 .get_pcie_replay_count = &nv_get_pcie_replay_count,
Evan Quan181e7722021-03-19 16:22:17 +0800724 .supports_baco = &amdgpu_dpm_is_baco_supported,
Alex Deuchera7173732020-08-19 17:04:47 -0400725 .pre_asic_init = &nv_pre_asic_init,
Evan Quan27747292020-08-18 17:58:06 +0800726 .update_umd_stable_pstate = &nv_update_umd_stable_pstate,
Alex Deucher3b246e82021-01-07 18:48:12 -0500727 .query_video_codecs = &nv_query_video_codecs,
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800728};
729
730static int nv_common_early_init(void *handle)
731{
Yong Zhao923c0872019-09-27 23:30:05 -0400732#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800733 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
734
Felix Kuehlingd3a21f72021-11-04 16:15:43 -0400735 if (!amdgpu_sriov_vf(adev)) {
736 adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
737 adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
738 }
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800739 adev->smc_rreg = NULL;
740 adev->smc_wreg = NULL;
741 adev->pcie_rreg = &nv_pcie_rreg;
742 adev->pcie_wreg = &nv_pcie_wreg;
John Clements4922f1bc2020-07-22 09:40:11 +0800743 adev->pcie_rreg64 = &nv_pcie_rreg64;
744 adev->pcie_wreg64 = &nv_pcie_wreg64;
Huang Rui5de54342020-08-27 12:01:26 -0400745 adev->pciep_rreg = &nv_pcie_port_rreg;
746 adev->pciep_wreg = &nv_pcie_port_wreg;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800747
748 /* TODO: will add them during VCN v2 implementation */
749 adev->uvd_ctx_rreg = NULL;
750 adev->uvd_ctx_wreg = NULL;
751
752 adev->didt_rreg = &nv_didt_rreg;
753 adev->didt_wreg = &nv_didt_wreg;
754
755 adev->asic_funcs = &nv_asic_funcs;
756
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800757 adev->rev_id = nv_get_rev_id(adev);
758 adev->external_rev_id = 0xff;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400759 /* TODO: split the GC and PG flags based on the relevant IP version for which
760 * they are relevant.
761 */
Alex Deucher1d789532021-10-04 15:19:10 -0400762 switch (adev->ip_versions[GC_HWIP][0]) {
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400763 case IP_VERSION(10, 1, 10):
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800764 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800765 AMD_CG_SUPPORT_GFX_CGCG |
766 AMD_CG_SUPPORT_IH_CG |
767 AMD_CG_SUPPORT_HDP_MGCG |
768 AMD_CG_SUPPORT_HDP_LS |
769 AMD_CG_SUPPORT_SDMA_MGCG |
770 AMD_CG_SUPPORT_SDMA_LS |
771 AMD_CG_SUPPORT_MC_MGCG |
772 AMD_CG_SUPPORT_MC_LS |
773 AMD_CG_SUPPORT_ATHUB_MGCG |
774 AMD_CG_SUPPORT_ATHUB_LS |
775 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500776 AMD_CG_SUPPORT_JPEG_MGCG |
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800777 AMD_CG_SUPPORT_BIF_MGCG |
778 AMD_CG_SUPPORT_BIF_LS;
Leo Liu157710e2019-05-15 13:58:20 -0400779 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Huang Ruic12d4102019-06-14 16:12:51 +0800780 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500781 AMD_PG_SUPPORT_JPEG |
Huang Ruia201b6a2019-06-14 16:19:36 +0800782 AMD_PG_SUPPORT_ATHUB;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800783 adev->external_rev_id = adev->rev_id + 0x1;
784 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400785 case IP_VERSION(10, 1, 1):
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800786 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
787 AMD_CG_SUPPORT_GFX_CGCG |
788 AMD_CG_SUPPORT_IH_CG |
789 AMD_CG_SUPPORT_HDP_MGCG |
790 AMD_CG_SUPPORT_HDP_LS |
791 AMD_CG_SUPPORT_SDMA_MGCG |
792 AMD_CG_SUPPORT_SDMA_LS |
793 AMD_CG_SUPPORT_MC_MGCG |
794 AMD_CG_SUPPORT_MC_LS |
795 AMD_CG_SUPPORT_ATHUB_MGCG |
796 AMD_CG_SUPPORT_ATHUB_LS |
797 AMD_CG_SUPPORT_VCN_MGCG |
Leo Liu099d66e2019-11-11 15:09:25 -0500798 AMD_CG_SUPPORT_JPEG_MGCG |
Xiaojie Yuand0c39f82019-03-20 16:12:54 +0800799 AMD_CG_SUPPORT_BIF_MGCG |
800 AMD_CG_SUPPORT_BIF_LS;
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500801 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Leo Liu099d66e2019-11-11 15:09:25 -0500802 AMD_PG_SUPPORT_JPEG |
Xiaojie Yuan0377b082019-07-02 12:52:52 -0500803 AMD_PG_SUPPORT_VCN_DPG;
tiancyin35ef88f2019-08-05 17:32:45 +0800804 adev->external_rev_id = adev->rev_id + 20;
Xiaojie Yuan5e71e012018-12-17 18:23:27 +0800805 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400806 case IP_VERSION(10, 1, 2):
Xiaojie Yuandca009e2019-07-30 11:28:20 +0800807 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
808 AMD_CG_SUPPORT_GFX_MGLS |
809 AMD_CG_SUPPORT_GFX_CGCG |
810 AMD_CG_SUPPORT_GFX_CP_LS |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800811 AMD_CG_SUPPORT_GFX_RLC_LS |
Xiaojie Yuanfbe0bc52019-08-01 15:01:23 +0800812 AMD_CG_SUPPORT_IH_CG |
Xiaojie Yuan5211c372019-08-01 15:00:28 +0800813 AMD_CG_SUPPORT_HDP_MGCG |
Xiaojie Yuan358ab972019-07-30 12:18:55 +0800814 AMD_CG_SUPPORT_HDP_LS |
815 AMD_CG_SUPPORT_SDMA_MGCG |
Xiaojie Yuan8b797b32019-08-01 15:39:59 +0800816 AMD_CG_SUPPORT_SDMA_LS |
817 AMD_CG_SUPPORT_MC_MGCG |
Xiaojie Yuanca516782019-08-01 15:19:10 +0800818 AMD_CG_SUPPORT_MC_LS |
819 AMD_CG_SUPPORT_ATHUB_MGCG |
Xiaojie Yuan65872e52019-08-01 15:22:59 +0800820 AMD_CG_SUPPORT_ATHUB_LS |
Leo Liu099d66e2019-11-11 15:09:25 -0500821 AMD_CG_SUPPORT_VCN_MGCG |
822 AMD_CG_SUPPORT_JPEG_MGCG;
Xiaojie Yuanc1653ea2019-08-27 11:05:23 +0800823 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Xiaojie Yuan5ef3b8a2019-08-27 11:06:13 +0800824 AMD_PG_SUPPORT_VCN_DPG |
Leo Liu099d66e2019-11-11 15:09:25 -0500825 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800826 AMD_PG_SUPPORT_ATHUB;
Tiecheng Zhoudf5e9842020-01-08 13:44:29 +0800827 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
828 * as a consequence, the rev_id and external_rev_id are wrong.
829 * workaround it by hardcoding rev_id to 0 (default value).
830 */
831 if (amdgpu_sriov_vf(adev))
832 adev->rev_id = 0;
Xiaojie Yuan74b5e502019-05-16 19:47:33 +0800833 adev->external_rev_id = adev->rev_id + 0xa;
834 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400835 case IP_VERSION(10, 3, 0):
Likun Gao00194de2020-01-24 03:57:55 +0800836 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
837 AMD_CG_SUPPORT_GFX_CGCG |
Kenneth Feng1d712be2021-04-22 17:31:04 +0800838 AMD_CG_SUPPORT_GFX_CGLS |
Likun Gao00194de2020-01-24 03:57:55 +0800839 AMD_CG_SUPPORT_GFX_3D_CGCG |
Likun Gao98f8ea22020-03-18 17:33:47 -0400840 AMD_CG_SUPPORT_MC_MGCG |
Likun Gao00194de2020-01-24 03:57:55 +0800841 AMD_CG_SUPPORT_VCN_MGCG |
Kenneth Fengca364612020-02-28 11:57:04 +0800842 AMD_CG_SUPPORT_JPEG_MGCG |
843 AMD_CG_SUPPORT_HDP_MGCG |
Kenneth Feng3a32c252020-02-28 14:09:31 +0800844 AMD_CG_SUPPORT_HDP_LS |
Kenneth Fengbcc83672020-02-28 14:14:00 +0800845 AMD_CG_SUPPORT_IH_CG |
846 AMD_CG_SUPPORT_MC_LS;
Leo Liub467c4f2019-12-03 09:23:24 -0500847 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhangd00b0fa2020-04-02 13:28:07 -0400848 AMD_PG_SUPPORT_VCN_DPG |
Kenneth Fengb7946162020-03-26 12:01:15 +0800849 AMD_PG_SUPPORT_JPEG |
Likun Gao1b0443b2020-07-06 10:54:26 +0800850 AMD_PG_SUPPORT_ATHUB |
851 AMD_PG_SUPPORT_MMHUB;
Jack Zhangc45fbe12020-06-23 19:36:24 +0800852 if (amdgpu_sriov_vf(adev)) {
853 /* hypervisor control CG and PG enablement */
854 adev->cg_flags = 0;
855 adev->pg_flags = 0;
856 }
Likun Gao117910e2019-03-19 11:04:03 +0800857 adev->external_rev_id = adev->rev_id + 0x28;
858 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400859 case IP_VERSION(10, 3, 2):
Jiansong Chen40582e62020-07-02 15:34:37 +0800860 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
861 AMD_CG_SUPPORT_GFX_CGCG |
Kenneth Feng1d712be2021-04-22 17:31:04 +0800862 AMD_CG_SUPPORT_GFX_CGLS |
Jiansong Chen40582e62020-07-02 15:34:37 +0800863 AMD_CG_SUPPORT_GFX_3D_CGCG |
864 AMD_CG_SUPPORT_VCN_MGCG |
Jiansong Chen92c73752020-07-08 18:53:36 +0800865 AMD_CG_SUPPORT_JPEG_MGCG |
866 AMD_CG_SUPPORT_MC_MGCG |
Jiansong Chen4759f882020-07-08 18:59:11 +0800867 AMD_CG_SUPPORT_MC_LS |
868 AMD_CG_SUPPORT_HDP_MGCG |
Jiansong Chen85e71512020-07-08 19:02:14 +0800869 AMD_CG_SUPPORT_HDP_LS |
870 AMD_CG_SUPPORT_IH_CG;
Boyuan Zhangc6e9dd02020-07-01 17:59:51 -0400871 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Boyuan Zhang00740df2020-07-01 18:02:32 -0400872 AMD_PG_SUPPORT_VCN_DPG |
Jiansong Chen47fc8942020-07-08 18:42:04 +0800873 AMD_PG_SUPPORT_JPEG |
874 AMD_PG_SUPPORT_ATHUB |
875 AMD_PG_SUPPORT_MMHUB;
Jiansong Chen543aa252020-02-10 17:00:28 +0800876 adev->external_rev_id = adev->rev_id + 0x32;
877 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400878 case IP_VERSION(10, 3, 1):
Jinzhou.Su51a7e932020-10-27 21:37:49 +0800879 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
880 AMD_CG_SUPPORT_GFX_MGLS |
881 AMD_CG_SUPPORT_GFX_CP_LS |
882 AMD_CG_SUPPORT_GFX_RLC_LS |
883 AMD_CG_SUPPORT_GFX_CGCG |
Huang Ruiac0dc4c2020-09-22 19:08:31 +0800884 AMD_CG_SUPPORT_GFX_CGLS |
885 AMD_CG_SUPPORT_GFX_3D_CGCG |
Boyuan Zhang07f9c222020-10-16 18:19:15 -0400886 AMD_CG_SUPPORT_GFX_3D_CGLS |
Jinzhou.Su0ebce662020-10-30 14:52:46 +0800887 AMD_CG_SUPPORT_MC_MGCG |
888 AMD_CG_SUPPORT_MC_LS |
Jinzhou.Sua3964ec2020-11-03 14:01:59 +0800889 AMD_CG_SUPPORT_GFX_FGCG |
Boyuan Zhang07f9c222020-10-16 18:19:15 -0400890 AMD_CG_SUPPORT_VCN_MGCG |
Jinzhou Suef9bcfd2021-04-21 10:59:13 +0800891 AMD_CG_SUPPORT_SDMA_MGCG |
Jinzhou Suec0f72c2021-04-23 16:29:14 +0800892 AMD_CG_SUPPORT_SDMA_LS |
Boyuan Zhang07f9c222020-10-16 18:19:15 -0400893 AMD_CG_SUPPORT_JPEG_MGCG;
894 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
895 AMD_PG_SUPPORT_VCN |
896 AMD_PG_SUPPORT_VCN_DPG |
897 AMD_PG_SUPPORT_JPEG;
Huang Ruic345c892020-10-26 20:43:41 +0800898 if (adev->apu_flags & AMD_APU_IS_VANGOGH)
899 adev->external_rev_id = adev->rev_id + 0x01;
Huang Rui026570e2020-08-27 10:46:19 -0400900 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400901 case IP_VERSION(10, 3, 4):
Tao Zhou583e5a52020-08-10 17:15:23 +0800902 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
903 AMD_CG_SUPPORT_GFX_CGCG |
Kenneth Feng1d712be2021-04-22 17:31:04 +0800904 AMD_CG_SUPPORT_GFX_CGLS |
Tao Zhou583e5a52020-08-10 17:15:23 +0800905 AMD_CG_SUPPORT_GFX_3D_CGCG |
906 AMD_CG_SUPPORT_VCN_MGCG |
Tao Zhou135333a2020-08-10 17:34:30 +0800907 AMD_CG_SUPPORT_JPEG_MGCG |
908 AMD_CG_SUPPORT_MC_MGCG |
Tao Zhou2c70c332020-08-10 17:46:17 +0800909 AMD_CG_SUPPORT_MC_LS |
910 AMD_CG_SUPPORT_HDP_MGCG |
Tao Zhou8e3bfb92020-08-10 17:48:34 +0800911 AMD_CG_SUPPORT_HDP_LS |
912 AMD_CG_SUPPORT_IH_CG;
James Zhud5bc1572020-08-05 17:54:21 -0400913 adev->pg_flags = AMD_PG_SUPPORT_VCN |
James Zhucc6161a2020-08-05 17:59:09 -0400914 AMD_PG_SUPPORT_VCN_DPG |
Tao Zhou73da8e82020-08-10 17:38:47 +0800915 AMD_PG_SUPPORT_JPEG |
916 AMD_PG_SUPPORT_ATHUB |
917 AMD_PG_SUPPORT_MMHUB;
Tao Zhou550c58e2020-10-02 11:30:54 -0400918 adev->external_rev_id = adev->rev_id + 0x3c;
919 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400920 case IP_VERSION(10, 3, 5):
Tao Zhoubc6bd462021-03-19 14:05:34 +0800921 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
922 AMD_CG_SUPPORT_GFX_CGCG |
Tao Zhoud69d2782021-04-22 17:57:14 +0800923 AMD_CG_SUPPORT_GFX_CGLS |
Tao Zhou5d36b862021-03-19 14:37:57 +0800924 AMD_CG_SUPPORT_GFX_3D_CGCG |
925 AMD_CG_SUPPORT_MC_MGCG |
Tao Zhou170c1932021-03-19 14:44:55 +0800926 AMD_CG_SUPPORT_MC_LS |
927 AMD_CG_SUPPORT_HDP_MGCG |
Tao Zhoua764bef2021-03-19 14:48:28 +0800928 AMD_CG_SUPPORT_HDP_LS |
Veerabadhran Gopalakrishnane47e4c02021-04-01 19:08:39 +0530929 AMD_CG_SUPPORT_IH_CG |
930 AMD_CG_SUPPORT_VCN_MGCG;
Veerabadhran Gopalakrishnanf703d4b2021-03-11 01:09:11 +0530931 adev->pg_flags = AMD_PG_SUPPORT_VCN |
Tao Zhou147de212021-03-19 14:29:28 +0800932 AMD_PG_SUPPORT_VCN_DPG |
933 AMD_PG_SUPPORT_ATHUB |
934 AMD_PG_SUPPORT_MMHUB;
Chengming Gui85730352020-10-13 16:09:55 +0800935 adev->external_rev_id = adev->rev_id + 0x46;
936 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400937 case IP_VERSION(10, 3, 3):
Aaron Liu9c6c48e2021-01-05 17:17:11 +0800938 adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
939 AMD_CG_SUPPORT_GFX_MGLS |
940 AMD_CG_SUPPORT_GFX_CGCG |
941 AMD_CG_SUPPORT_GFX_CGLS |
942 AMD_CG_SUPPORT_GFX_3D_CGCG |
943 AMD_CG_SUPPORT_GFX_3D_CGLS |
944 AMD_CG_SUPPORT_GFX_RLC_LS |
945 AMD_CG_SUPPORT_GFX_CP_LS |
Aaron Liu83ae09b2021-01-05 17:29:03 +0800946 AMD_CG_SUPPORT_GFX_FGCG |
947 AMD_CG_SUPPORT_MC_MGCG |
Aaron Liuf1e9aa652021-01-11 13:16:31 +0800948 AMD_CG_SUPPORT_MC_LS |
Aaron Liu6bd95572021-01-12 16:42:29 +0800949 AMD_CG_SUPPORT_SDMA_LS |
950 AMD_CG_SUPPORT_HDP_MGCG |
Aaron Liub7dd14c2021-01-12 16:48:09 +0800951 AMD_CG_SUPPORT_HDP_LS |
952 AMD_CG_SUPPORT_ATHUB_MGCG |
Aaron Liudb72c3f2021-01-12 16:51:59 +0800953 AMD_CG_SUPPORT_ATHUB_LS |
Aaron Liu948b1212021-01-20 15:48:47 +0800954 AMD_CG_SUPPORT_IH_CG |
955 AMD_CG_SUPPORT_VCN_MGCG |
956 AMD_CG_SUPPORT_JPEG_MGCG;
James Zhu54f4f6f2021-01-13 14:36:36 -0500957 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
Aaron Liu948b1212021-01-20 15:48:47 +0800958 AMD_PG_SUPPORT_VCN |
959 AMD_PG_SUPPORT_VCN_DPG |
960 AMD_PG_SUPPORT_JPEG;
Aaron Liue97c8d82021-06-02 10:32:41 +0800961 if (adev->pdev->device == 0x1681)
Aaron Liu5efacdf2021-10-19 11:13:25 +0800962 adev->external_rev_id = 0x20;
Aaron Liue97c8d82021-06-02 10:32:41 +0800963 else
964 adev->external_rev_id = adev->rev_id + 0x01;
Aaron Liue7990722020-11-04 13:21:55 +0800965 break;
Alex Deucher3e67f4f2021-07-28 12:10:20 -0400966 case IP_VERSION(10, 1, 3):
Tao Zhoub5159372021-07-13 17:45:40 -0400967 adev->cg_flags = 0;
968 adev->pg_flags = 0;
969 adev->external_rev_id = adev->rev_id + 0x82;
970 break;
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800971 default:
972 /* FIXME: not supported yet */
973 return -EINVAL;
974 }
975
Likun GAO7bd939d2021-04-29 14:08:13 +0800976 if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
977 adev->pg_flags &= ~(AMD_PG_SUPPORT_VCN |
978 AMD_PG_SUPPORT_VCN_DPG |
979 AMD_PG_SUPPORT_JPEG);
980
Jiange Zhaob05b6902019-09-11 17:29:07 +0800981 if (amdgpu_sriov_vf(adev)) {
982 amdgpu_virt_init_setting(adev);
983 xgpu_nv_mailbox_set_irq_funcs(adev);
984 }
985
Hawking Zhangc6b6a422019-03-04 14:07:37 +0800986 return 0;
987}
988
989static int nv_common_late_init(void *handle)
990{
Jiange Zhaob05b6902019-09-11 17:29:07 +0800991 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
992
Bokun Zhanged9d2052021-05-13 01:17:54 -0400993 if (amdgpu_sriov_vf(adev)) {
Jiange Zhaob05b6902019-09-11 17:29:07 +0800994 xgpu_nv_mailbox_get_irq(adev);
Bokun Zhanged9d2052021-05-13 01:17:54 -0400995 amdgpu_virt_update_sriov_video_codec(adev,
996 sriov_sc_video_codecs_encode_array, ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
997 sriov_sc_video_codecs_decode_array, ARRAY_SIZE(sriov_sc_video_codecs_decode_array));
998 }
Jiange Zhaob05b6902019-09-11 17:29:07 +0800999
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001000 return 0;
1001}
1002
1003static int nv_common_sw_init(void *handle)
1004{
Jiange Zhaob05b6902019-09-11 17:29:07 +08001005 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1006
1007 if (amdgpu_sriov_vf(adev))
1008 xgpu_nv_mailbox_add_irq_id(adev);
1009
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001010 return 0;
1011}
1012
1013static int nv_common_sw_fini(void *handle)
1014{
1015 return 0;
1016}
1017
1018static int nv_common_hw_init(void *handle)
1019{
1020 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1021
Evan Quan5a5da8a2021-05-25 12:08:53 +08001022 if (adev->nbio.funcs->apply_lc_spc_mode_wa)
1023 adev->nbio.funcs->apply_lc_spc_mode_wa(adev);
1024
Evan Quanadcf9492021-05-25 14:36:29 +08001025 if (adev->nbio.funcs->apply_l1_link_width_reconfig_wa)
1026 adev->nbio.funcs->apply_l1_link_width_reconfig_wa(adev);
1027
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001028 /* enable pcie gen2/3 link */
1029 nv_pcie_gen3_enable(adev);
1030 /* enable aspm */
1031 nv_program_aspm(adev);
1032 /* setup nbio registers */
Hawking Zhangbebc0762019-08-23 19:39:18 +08001033 adev->nbio.funcs->init_registers(adev);
Yong Zhao923c0872019-09-27 23:30:05 -04001034 /* remap HDP registers to a hole in mmio space,
1035 * for the purpose of expose those registers
1036 * to process space
1037 */
Felix Kuehlingd3a21f72021-11-04 16:15:43 -04001038 if (adev->nbio.funcs->remap_hdp_registers && !amdgpu_sriov_vf(adev))
Yong Zhao923c0872019-09-27 23:30:05 -04001039 adev->nbio.funcs->remap_hdp_registers(adev);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001040 /* enable the doorbell aperture */
1041 nv_enable_doorbell_aperture(adev, true);
1042
1043 return 0;
1044}
1045
1046static int nv_common_hw_fini(void *handle)
1047{
1048 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1049
1050 /* disable the doorbell aperture */
1051 nv_enable_doorbell_aperture(adev, false);
1052
1053 return 0;
1054}
1055
1056static int nv_common_suspend(void *handle)
1057{
1058 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1059
1060 return nv_common_hw_fini(adev);
1061}
1062
1063static int nv_common_resume(void *handle)
1064{
1065 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1066
1067 return nv_common_hw_init(adev);
1068}
1069
1070static bool nv_common_is_idle(void *handle)
1071{
1072 return true;
1073}
1074
1075static int nv_common_wait_for_idle(void *handle)
1076{
1077 return 0;
1078}
1079
1080static int nv_common_soft_reset(void *handle)
1081{
1082 return 0;
1083}
1084
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001085static int nv_common_set_clockgating_state(void *handle,
1086 enum amd_clockgating_state state)
1087{
1088 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1089
1090 if (amdgpu_sriov_vf(adev))
1091 return 0;
1092
Alex Deucher1d789532021-10-04 15:19:10 -04001093 switch (adev->ip_versions[NBIO_HWIP][0]) {
Alex Deucher3e67f4f2021-07-28 12:10:20 -04001094 case IP_VERSION(2, 3, 0):
1095 case IP_VERSION(2, 3, 1):
1096 case IP_VERSION(2, 3, 2):
1097 case IP_VERSION(3, 3, 0):
1098 case IP_VERSION(3, 3, 1):
1099 case IP_VERSION(3, 3, 2):
1100 case IP_VERSION(3, 3, 3):
Hawking Zhangbebc0762019-08-23 19:39:18 +08001101 adev->nbio.funcs->update_medium_grain_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001102 state == AMD_CG_STATE_GATE);
Hawking Zhangbebc0762019-08-23 19:39:18 +08001103 adev->nbio.funcs->update_medium_grain_light_sleep(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001104 state == AMD_CG_STATE_GATE);
Likun Gaobf087282020-12-28 17:02:21 +08001105 adev->hdp.funcs->update_clock_gating(adev,
Nirmoy Dasa9d4fe22020-01-20 13:54:30 +01001106 state == AMD_CG_STATE_GATE);
Likun Gao1001f2a2021-02-03 18:45:42 +08001107 adev->smuio.funcs->update_rom_clock_gating(adev,
1108 state == AMD_CG_STATE_GATE);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001109 break;
1110 default:
1111 break;
1112 }
1113 return 0;
1114}
1115
1116static int nv_common_set_powergating_state(void *handle,
1117 enum amd_powergating_state state)
1118{
1119 /* TODO */
1120 return 0;
1121}
1122
1123static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1124{
1125 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001126
1127 if (amdgpu_sriov_vf(adev))
1128 *flags = 0;
1129
Hawking Zhangbebc0762019-08-23 19:39:18 +08001130 adev->nbio.funcs->get_clockgating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001131
Likun Gaobf087282020-12-28 17:02:21 +08001132 adev->hdp.funcs->get_clock_gating_state(adev, flags);
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001133
Likun Gao1001f2a2021-02-03 18:45:42 +08001134 adev->smuio.funcs->get_clock_gating_state(adev, flags);
1135
Hawking Zhangc6b6a422019-03-04 14:07:37 +08001136 return;
1137}
1138
1139static const struct amd_ip_funcs nv_common_ip_funcs = {
1140 .name = "nv_common",
1141 .early_init = nv_common_early_init,
1142 .late_init = nv_common_late_init,
1143 .sw_init = nv_common_sw_init,
1144 .sw_fini = nv_common_sw_fini,
1145 .hw_init = nv_common_hw_init,
1146 .hw_fini = nv_common_hw_fini,
1147 .suspend = nv_common_suspend,
1148 .resume = nv_common_resume,
1149 .is_idle = nv_common_is_idle,
1150 .wait_for_idle = nv_common_wait_for_idle,
1151 .soft_reset = nv_common_soft_reset,
1152 .set_clockgating_state = nv_common_set_clockgating_state,
1153 .set_powergating_state = nv_common_set_powergating_state,
1154 .get_clockgating_state = nv_common_get_clockgating_state,
1155};