xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/nv.c (revision 338b3cf0)
1c6b6a421SHawking Zhang /*
2c6b6a421SHawking Zhang  * Copyright 2019 Advanced Micro Devices, Inc.
3c6b6a421SHawking Zhang  *
4c6b6a421SHawking Zhang  * Permission is hereby granted, free of charge, to any person obtaining a
5c6b6a421SHawking Zhang  * copy of this software and associated documentation files (the "Software"),
6c6b6a421SHawking Zhang  * to deal in the Software without restriction, including without limitation
7c6b6a421SHawking Zhang  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c6b6a421SHawking Zhang  * and/or sell copies of the Software, and to permit persons to whom the
9c6b6a421SHawking Zhang  * Software is furnished to do so, subject to the following conditions:
10c6b6a421SHawking Zhang  *
11c6b6a421SHawking Zhang  * The above copyright notice and this permission notice shall be included in
12c6b6a421SHawking Zhang  * all copies or substantial portions of the Software.
13c6b6a421SHawking Zhang  *
14c6b6a421SHawking Zhang  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c6b6a421SHawking Zhang  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c6b6a421SHawking Zhang  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c6b6a421SHawking Zhang  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c6b6a421SHawking Zhang  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c6b6a421SHawking Zhang  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c6b6a421SHawking Zhang  * OTHER DEALINGS IN THE SOFTWARE.
21c6b6a421SHawking Zhang  *
22c6b6a421SHawking Zhang  */
23c6b6a421SHawking Zhang #include <linux/firmware.h>
24c6b6a421SHawking Zhang #include <linux/slab.h>
25c6b6a421SHawking Zhang #include <linux/module.h>
26e9eea902SAlex Deucher #include <linux/pci.h>
27e9eea902SAlex Deucher 
286f786950SAlex Deucher #include <drm/amdgpu_drm.h>
296f786950SAlex Deucher 
30c6b6a421SHawking Zhang #include "amdgpu.h"
31c6b6a421SHawking Zhang #include "amdgpu_atombios.h"
32c6b6a421SHawking Zhang #include "amdgpu_ih.h"
33c6b6a421SHawking Zhang #include "amdgpu_uvd.h"
34c6b6a421SHawking Zhang #include "amdgpu_vce.h"
35c6b6a421SHawking Zhang #include "amdgpu_ucode.h"
36c6b6a421SHawking Zhang #include "amdgpu_psp.h"
37c6b6a421SHawking Zhang #include "atom.h"
38c6b6a421SHawking Zhang #include "amd_pcie.h"
39c6b6a421SHawking Zhang 
40c6b6a421SHawking Zhang #include "gc/gc_10_1_0_offset.h"
41c6b6a421SHawking Zhang #include "gc/gc_10_1_0_sh_mask.h"
423967ae6dSAlex Deucher #include "mp/mp_11_0_offset.h"
43c6b6a421SHawking Zhang 
44c6b6a421SHawking Zhang #include "soc15.h"
45c6b6a421SHawking Zhang #include "soc15_common.h"
46c6b6a421SHawking Zhang #include "gmc_v10_0.h"
47c6b6a421SHawking Zhang #include "gfxhub_v2_0.h"
48c6b6a421SHawking Zhang #include "mmhub_v2_0.h"
49bebc0762SHawking Zhang #include "nbio_v2_3.h"
50a7e91bd7SHuang Rui #include "nbio_v7_2.h"
51bf087285SLikun Gao #include "hdp_v5_0.h"
52c6b6a421SHawking Zhang #include "nv.h"
53c6b6a421SHawking Zhang #include "navi10_ih.h"
54c6b6a421SHawking Zhang #include "gfx_v10_0.h"
55c6b6a421SHawking Zhang #include "sdma_v5_0.h"
56157e72e8SLikun Gao #include "sdma_v5_2.h"
57c6b6a421SHawking Zhang #include "vcn_v2_0.h"
585be45a26SLeo Liu #include "jpeg_v2_0.h"
59b8f10585SLeo Liu #include "vcn_v3_0.h"
604d72dd12SLeo Liu #include "jpeg_v3_0.h"
61c6b6a421SHawking Zhang #include "dce_virtual.h"
62c6b6a421SHawking Zhang #include "mes_v10_1.h"
63b05b6903SJiange Zhao #include "mxgpu_nv.h"
640bf7f2dcSLikun Gao #include "smuio_v11_0.h"
650bf7f2dcSLikun Gao #include "smuio_v11_0_6.h"
66c6b6a421SHawking Zhang 
67c6b6a421SHawking Zhang static const struct amd_ip_funcs nv_common_ip_funcs;
68c6b6a421SHawking Zhang 
693b246e8bSAlex Deucher /* Navi */
703b246e8bSAlex Deucher static const struct amdgpu_video_codec_info nv_video_codecs_encode_array[] =
713b246e8bSAlex Deucher {
729075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
739075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
743b246e8bSAlex Deucher };
753b246e8bSAlex Deucher 
763b246e8bSAlex Deucher static const struct amdgpu_video_codecs nv_video_codecs_encode =
773b246e8bSAlex Deucher {
783b246e8bSAlex Deucher 	.codec_count = ARRAY_SIZE(nv_video_codecs_encode_array),
793b246e8bSAlex Deucher 	.codec_array = nv_video_codecs_encode_array,
803b246e8bSAlex Deucher };
813b246e8bSAlex Deucher 
823b246e8bSAlex Deucher /* Navi1x */
833b246e8bSAlex Deucher static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] =
843b246e8bSAlex Deucher {
859075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
869075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
879075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
889075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
899075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
909075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
919075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
923b246e8bSAlex Deucher };
933b246e8bSAlex Deucher 
943b246e8bSAlex Deucher static const struct amdgpu_video_codecs nv_video_codecs_decode =
953b246e8bSAlex Deucher {
963b246e8bSAlex Deucher 	.codec_count = ARRAY_SIZE(nv_video_codecs_decode_array),
973b246e8bSAlex Deucher 	.codec_array = nv_video_codecs_decode_array,
983b246e8bSAlex Deucher };
993b246e8bSAlex Deucher 
1003b246e8bSAlex Deucher /* Sienna Cichlid */
1013b246e8bSAlex Deucher static const struct amdgpu_video_codec_info sc_video_codecs_decode_array[] =
1023b246e8bSAlex Deucher {
1039075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
1049075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
1059075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
1069075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
1079075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
1089075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
1099075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
1109075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
1113b246e8bSAlex Deucher };
1123b246e8bSAlex Deucher 
1133b246e8bSAlex Deucher static const struct amdgpu_video_codecs sc_video_codecs_decode =
1143b246e8bSAlex Deucher {
1153b246e8bSAlex Deucher 	.codec_count = ARRAY_SIZE(sc_video_codecs_decode_array),
1163b246e8bSAlex Deucher 	.codec_array = sc_video_codecs_decode_array,
1173b246e8bSAlex Deucher };
1183b246e8bSAlex Deucher 
119ed9d2053SBokun Zhang /* SRIOV Sienna Cichlid, not const since data is controlled by host */
120ed9d2053SBokun Zhang static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array[] =
121ed9d2053SBokun Zhang {
1229075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
1239075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
124ed9d2053SBokun Zhang };
125ed9d2053SBokun Zhang 
126ed9d2053SBokun Zhang static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array[] =
127ed9d2053SBokun Zhang {
1289075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
1299075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
1309075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
1319075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
1329075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
1339075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
1349075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
1359075096bSVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
136ed9d2053SBokun Zhang };
137ed9d2053SBokun Zhang 
138ed9d2053SBokun Zhang static struct amdgpu_video_codecs sriov_sc_video_codecs_encode =
139ed9d2053SBokun Zhang {
140ed9d2053SBokun Zhang 	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
141ed9d2053SBokun Zhang 	.codec_array = sriov_sc_video_codecs_encode_array,
142ed9d2053SBokun Zhang };
143ed9d2053SBokun Zhang 
144ed9d2053SBokun Zhang static struct amdgpu_video_codecs sriov_sc_video_codecs_decode =
145ed9d2053SBokun Zhang {
146ed9d2053SBokun Zhang 	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array),
147ed9d2053SBokun Zhang 	.codec_array = sriov_sc_video_codecs_decode_array,
148ed9d2053SBokun Zhang };
149ed9d2053SBokun Zhang 
150b3a24461SVeerabadhran Gopalakrishnan /* Beige Goby*/
151b3a24461SVeerabadhran Gopalakrishnan static const struct amdgpu_video_codec_info bg_video_codecs_decode_array[] = {
152b3a24461SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
153b3a24461SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
154b3a24461SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
155b3a24461SVeerabadhran Gopalakrishnan };
156b3a24461SVeerabadhran Gopalakrishnan 
157b3a24461SVeerabadhran Gopalakrishnan static const struct amdgpu_video_codecs bg_video_codecs_decode = {
158b3a24461SVeerabadhran Gopalakrishnan 	.codec_count = ARRAY_SIZE(bg_video_codecs_decode_array),
159b3a24461SVeerabadhran Gopalakrishnan 	.codec_array = bg_video_codecs_decode_array,
160b3a24461SVeerabadhran Gopalakrishnan };
161b3a24461SVeerabadhran Gopalakrishnan 
162b3a24461SVeerabadhran Gopalakrishnan static const struct amdgpu_video_codecs bg_video_codecs_encode = {
163b3a24461SVeerabadhran Gopalakrishnan 	.codec_count = 0,
164b3a24461SVeerabadhran Gopalakrishnan 	.codec_array = NULL,
165b3a24461SVeerabadhran Gopalakrishnan };
166b3a24461SVeerabadhran Gopalakrishnan 
16755439817SVeerabadhran Gopalakrishnan /* Yellow Carp*/
16855439817SVeerabadhran Gopalakrishnan static const struct amdgpu_video_codec_info yc_video_codecs_decode_array[] = {
16955439817SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
17055439817SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
17155439817SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
17255439817SVeerabadhran Gopalakrishnan 	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
17355439817SVeerabadhran Gopalakrishnan };
17455439817SVeerabadhran Gopalakrishnan 
17555439817SVeerabadhran Gopalakrishnan static const struct amdgpu_video_codecs yc_video_codecs_decode = {
176f72ac409SVeerabadhran Gopalakrishnan 	.codec_count = ARRAY_SIZE(yc_video_codecs_decode_array),
177f72ac409SVeerabadhran Gopalakrishnan 	.codec_array = yc_video_codecs_decode_array,
17855439817SVeerabadhran Gopalakrishnan };
17955439817SVeerabadhran Gopalakrishnan 
1803b246e8bSAlex Deucher static int nv_query_video_codecs(struct amdgpu_device *adev, bool encode,
1813b246e8bSAlex Deucher 				 const struct amdgpu_video_codecs **codecs)
1823b246e8bSAlex Deucher {
1833b246e8bSAlex Deucher 	switch (adev->asic_type) {
1843b246e8bSAlex Deucher 	case CHIP_SIENNA_CICHLID:
185ed9d2053SBokun Zhang 		if (amdgpu_sriov_vf(adev)) {
186ed9d2053SBokun Zhang 			if (encode)
187ed9d2053SBokun Zhang 				*codecs = &sriov_sc_video_codecs_encode;
188ed9d2053SBokun Zhang 			else
189ed9d2053SBokun Zhang 				*codecs = &sriov_sc_video_codecs_decode;
190ed9d2053SBokun Zhang 		} else {
191ed9d2053SBokun Zhang 			if (encode)
192ed9d2053SBokun Zhang 				*codecs = &nv_video_codecs_encode;
193ed9d2053SBokun Zhang 			else
194ed9d2053SBokun Zhang 				*codecs = &sc_video_codecs_decode;
195ed9d2053SBokun Zhang 		}
196ed9d2053SBokun Zhang 		return 0;
1973b246e8bSAlex Deucher 	case CHIP_NAVY_FLOUNDER:
1983b246e8bSAlex Deucher 	case CHIP_DIMGREY_CAVEFISH:
1993b246e8bSAlex Deucher 	case CHIP_VANGOGH:
2003b246e8bSAlex Deucher 		if (encode)
2013b246e8bSAlex Deucher 			*codecs = &nv_video_codecs_encode;
2023b246e8bSAlex Deucher 		else
2033b246e8bSAlex Deucher 			*codecs = &sc_video_codecs_decode;
2043b246e8bSAlex Deucher 		return 0;
20555439817SVeerabadhran Gopalakrishnan 	case CHIP_YELLOW_CARP:
20655439817SVeerabadhran Gopalakrishnan 		if (encode)
20755439817SVeerabadhran Gopalakrishnan 			*codecs = &nv_video_codecs_encode;
20855439817SVeerabadhran Gopalakrishnan 		else
20955439817SVeerabadhran Gopalakrishnan 			*codecs = &yc_video_codecs_decode;
21055439817SVeerabadhran Gopalakrishnan 		return 0;
211b3a24461SVeerabadhran Gopalakrishnan 	case CHIP_BEIGE_GOBY:
212b3a24461SVeerabadhran Gopalakrishnan 		if (encode)
213b3a24461SVeerabadhran Gopalakrishnan 			*codecs = &bg_video_codecs_encode;
214b3a24461SVeerabadhran Gopalakrishnan 		else
215b3a24461SVeerabadhran Gopalakrishnan 			*codecs = &bg_video_codecs_decode;
216b3a24461SVeerabadhran Gopalakrishnan 		return 0;
2173b246e8bSAlex Deucher 	case CHIP_NAVI10:
2183b246e8bSAlex Deucher 	case CHIP_NAVI14:
2193b246e8bSAlex Deucher 	case CHIP_NAVI12:
2203b246e8bSAlex Deucher 		if (encode)
2213b246e8bSAlex Deucher 			*codecs = &nv_video_codecs_encode;
2223b246e8bSAlex Deucher 		else
2233b246e8bSAlex Deucher 			*codecs = &nv_video_codecs_decode;
2243b246e8bSAlex Deucher 		return 0;
2253b246e8bSAlex Deucher 	default:
2263b246e8bSAlex Deucher 		return -EINVAL;
2273b246e8bSAlex Deucher 	}
2283b246e8bSAlex Deucher }
2293b246e8bSAlex Deucher 
230c6b6a421SHawking Zhang /*
231c6b6a421SHawking Zhang  * Indirect registers accessor
232c6b6a421SHawking Zhang  */
233c6b6a421SHawking Zhang static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
234c6b6a421SHawking Zhang {
235705a2b5bSHawking Zhang 	unsigned long address, data;
236bebc0762SHawking Zhang 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
237bebc0762SHawking Zhang 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
238c6b6a421SHawking Zhang 
239705a2b5bSHawking Zhang 	return amdgpu_device_indirect_rreg(adev, address, data, reg);
240c6b6a421SHawking Zhang }
241c6b6a421SHawking Zhang 
242c6b6a421SHawking Zhang static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
243c6b6a421SHawking Zhang {
244705a2b5bSHawking Zhang 	unsigned long address, data;
245c6b6a421SHawking Zhang 
246bebc0762SHawking Zhang 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
247bebc0762SHawking Zhang 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
248c6b6a421SHawking Zhang 
249705a2b5bSHawking Zhang 	amdgpu_device_indirect_wreg(adev, address, data, reg, v);
250c6b6a421SHawking Zhang }
251c6b6a421SHawking Zhang 
2524922f1bcSJohn Clements static u64 nv_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
2534922f1bcSJohn Clements {
254705a2b5bSHawking Zhang 	unsigned long address, data;
2554922f1bcSJohn Clements 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
2564922f1bcSJohn Clements 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
2574922f1bcSJohn Clements 
258705a2b5bSHawking Zhang 	return amdgpu_device_indirect_rreg64(adev, address, data, reg);
2594922f1bcSJohn Clements }
2604922f1bcSJohn Clements 
2615de54343SHuang Rui static u32 nv_pcie_port_rreg(struct amdgpu_device *adev, u32 reg)
2625de54343SHuang Rui {
2635de54343SHuang Rui 	unsigned long flags, address, data;
2645de54343SHuang Rui 	u32 r;
2655de54343SHuang Rui 	address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
2665de54343SHuang Rui 	data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
2675de54343SHuang Rui 
2685de54343SHuang Rui 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
2695de54343SHuang Rui 	WREG32(address, reg * 4);
2705de54343SHuang Rui 	(void)RREG32(address);
2715de54343SHuang Rui 	r = RREG32(data);
2725de54343SHuang Rui 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
2735de54343SHuang Rui 	return r;
2745de54343SHuang Rui }
2755de54343SHuang Rui 
2764922f1bcSJohn Clements static void nv_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
2774922f1bcSJohn Clements {
278705a2b5bSHawking Zhang 	unsigned long address, data;
2794922f1bcSJohn Clements 
2804922f1bcSJohn Clements 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
2814922f1bcSJohn Clements 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
2824922f1bcSJohn Clements 
283705a2b5bSHawking Zhang 	amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
2844922f1bcSJohn Clements }
2854922f1bcSJohn Clements 
2865de54343SHuang Rui static void nv_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
2875de54343SHuang Rui {
2885de54343SHuang Rui 	unsigned long flags, address, data;
2895de54343SHuang Rui 
2905de54343SHuang Rui 	address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
2915de54343SHuang Rui 	data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
2925de54343SHuang Rui 
2935de54343SHuang Rui 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
2945de54343SHuang Rui 	WREG32(address, reg * 4);
2955de54343SHuang Rui 	(void)RREG32(address);
2965de54343SHuang Rui 	WREG32(data, v);
2975de54343SHuang Rui 	(void)RREG32(data);
2985de54343SHuang Rui 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
2995de54343SHuang Rui }
3005de54343SHuang Rui 
301c6b6a421SHawking Zhang static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
302c6b6a421SHawking Zhang {
303c6b6a421SHawking Zhang 	unsigned long flags, address, data;
304c6b6a421SHawking Zhang 	u32 r;
305c6b6a421SHawking Zhang 
306c6b6a421SHawking Zhang 	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
307c6b6a421SHawking Zhang 	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
308c6b6a421SHawking Zhang 
309c6b6a421SHawking Zhang 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
310c6b6a421SHawking Zhang 	WREG32(address, (reg));
311c6b6a421SHawking Zhang 	r = RREG32(data);
312c6b6a421SHawking Zhang 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
313c6b6a421SHawking Zhang 	return r;
314c6b6a421SHawking Zhang }
315c6b6a421SHawking Zhang 
316c6b6a421SHawking Zhang static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
317c6b6a421SHawking Zhang {
318c6b6a421SHawking Zhang 	unsigned long flags, address, data;
319c6b6a421SHawking Zhang 
320c6b6a421SHawking Zhang 	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
321c6b6a421SHawking Zhang 	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
322c6b6a421SHawking Zhang 
323c6b6a421SHawking Zhang 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
324c6b6a421SHawking Zhang 	WREG32(address, (reg));
325c6b6a421SHawking Zhang 	WREG32(data, (v));
326c6b6a421SHawking Zhang 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
327c6b6a421SHawking Zhang }
328c6b6a421SHawking Zhang 
329c6b6a421SHawking Zhang static u32 nv_get_config_memsize(struct amdgpu_device *adev)
330c6b6a421SHawking Zhang {
331bebc0762SHawking Zhang 	return adev->nbio.funcs->get_memsize(adev);
332c6b6a421SHawking Zhang }
333c6b6a421SHawking Zhang 
334c6b6a421SHawking Zhang static u32 nv_get_xclk(struct amdgpu_device *adev)
335c6b6a421SHawking Zhang {
336462a70d8STao Zhou 	return adev->clock.spll.reference_freq;
337c6b6a421SHawking Zhang }
338c6b6a421SHawking Zhang 
339c6b6a421SHawking Zhang 
340c6b6a421SHawking Zhang void nv_grbm_select(struct amdgpu_device *adev,
341c6b6a421SHawking Zhang 		     u32 me, u32 pipe, u32 queue, u32 vmid)
342c6b6a421SHawking Zhang {
343c6b6a421SHawking Zhang 	u32 grbm_gfx_cntl = 0;
344c6b6a421SHawking Zhang 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
345c6b6a421SHawking Zhang 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
346c6b6a421SHawking Zhang 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
347c6b6a421SHawking Zhang 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
348c6b6a421SHawking Zhang 
349f2958a8bSPeng Ju Zhou 	WREG32_SOC15(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
350c6b6a421SHawking Zhang }
351c6b6a421SHawking Zhang 
352c6b6a421SHawking Zhang static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
353c6b6a421SHawking Zhang {
354c6b6a421SHawking Zhang 	/* todo */
355c6b6a421SHawking Zhang }
356c6b6a421SHawking Zhang 
357c6b6a421SHawking Zhang static bool nv_read_disabled_bios(struct amdgpu_device *adev)
358c6b6a421SHawking Zhang {
359c6b6a421SHawking Zhang 	/* todo */
360c6b6a421SHawking Zhang 	return false;
361c6b6a421SHawking Zhang }
362c6b6a421SHawking Zhang 
363c6b6a421SHawking Zhang static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
364c6b6a421SHawking Zhang 				  u8 *bios, u32 length_bytes)
365c6b6a421SHawking Zhang {
36629bc37b4SAlex Deucher 	u32 *dw_ptr;
36729bc37b4SAlex Deucher 	u32 i, length_dw;
3680bf7f2dcSLikun Gao 	u32 rom_index_offset, rom_data_offset;
36929bc37b4SAlex Deucher 
37029bc37b4SAlex Deucher 	if (bios == NULL)
371c6b6a421SHawking Zhang 		return false;
37229bc37b4SAlex Deucher 	if (length_bytes == 0)
37329bc37b4SAlex Deucher 		return false;
37429bc37b4SAlex Deucher 	/* APU vbios image is part of sbios image */
37529bc37b4SAlex Deucher 	if (adev->flags & AMD_IS_APU)
37629bc37b4SAlex Deucher 		return false;
37729bc37b4SAlex Deucher 
37829bc37b4SAlex Deucher 	dw_ptr = (u32 *)bios;
37929bc37b4SAlex Deucher 	length_dw = ALIGN(length_bytes, 4) / 4;
38029bc37b4SAlex Deucher 
3810bf7f2dcSLikun Gao 	rom_index_offset =
3820bf7f2dcSLikun Gao 		adev->smuio.funcs->get_rom_index_offset(adev);
3830bf7f2dcSLikun Gao 	rom_data_offset =
3840bf7f2dcSLikun Gao 		adev->smuio.funcs->get_rom_data_offset(adev);
3850bf7f2dcSLikun Gao 
38629bc37b4SAlex Deucher 	/* set rom index to 0 */
3870bf7f2dcSLikun Gao 	WREG32(rom_index_offset, 0);
38829bc37b4SAlex Deucher 	/* read out the rom data */
38929bc37b4SAlex Deucher 	for (i = 0; i < length_dw; i++)
3900bf7f2dcSLikun Gao 		dw_ptr[i] = RREG32(rom_data_offset);
39129bc37b4SAlex Deucher 
39229bc37b4SAlex Deucher 	return true;
393c6b6a421SHawking Zhang }
394c6b6a421SHawking Zhang 
395c6b6a421SHawking Zhang static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
396c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
397c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
398c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
399c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
400c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
401c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
402c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
403c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
404c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
405c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
406c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
407c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
408c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
409c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
410c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
411664fe85aSMarek Olšák 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
412c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
413c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
414c6b6a421SHawking Zhang 	{ SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
415c6b6a421SHawking Zhang };
416c6b6a421SHawking Zhang 
417c6b6a421SHawking Zhang static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
418c6b6a421SHawking Zhang 					 u32 sh_num, u32 reg_offset)
419c6b6a421SHawking Zhang {
420c6b6a421SHawking Zhang 	uint32_t val;
421c6b6a421SHawking Zhang 
422c6b6a421SHawking Zhang 	mutex_lock(&adev->grbm_idx_mutex);
423c6b6a421SHawking Zhang 	if (se_num != 0xffffffff || sh_num != 0xffffffff)
424c6b6a421SHawking Zhang 		amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
425c6b6a421SHawking Zhang 
426c6b6a421SHawking Zhang 	val = RREG32(reg_offset);
427c6b6a421SHawking Zhang 
428c6b6a421SHawking Zhang 	if (se_num != 0xffffffff || sh_num != 0xffffffff)
429c6b6a421SHawking Zhang 		amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
430c6b6a421SHawking Zhang 	mutex_unlock(&adev->grbm_idx_mutex);
431c6b6a421SHawking Zhang 	return val;
432c6b6a421SHawking Zhang }
433c6b6a421SHawking Zhang 
434c6b6a421SHawking Zhang static uint32_t nv_get_register_value(struct amdgpu_device *adev,
435c6b6a421SHawking Zhang 				      bool indexed, u32 se_num,
436c6b6a421SHawking Zhang 				      u32 sh_num, u32 reg_offset)
437c6b6a421SHawking Zhang {
438c6b6a421SHawking Zhang 	if (indexed) {
439c6b6a421SHawking Zhang 		return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
440c6b6a421SHawking Zhang 	} else {
441c6b6a421SHawking Zhang 		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
442c6b6a421SHawking Zhang 			return adev->gfx.config.gb_addr_config;
443c6b6a421SHawking Zhang 		return RREG32(reg_offset);
444c6b6a421SHawking Zhang 	}
445c6b6a421SHawking Zhang }
446c6b6a421SHawking Zhang 
447c6b6a421SHawking Zhang static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
448c6b6a421SHawking Zhang 			    u32 sh_num, u32 reg_offset, u32 *value)
449c6b6a421SHawking Zhang {
450c6b6a421SHawking Zhang 	uint32_t i;
451c6b6a421SHawking Zhang 	struct soc15_allowed_register_entry  *en;
452c6b6a421SHawking Zhang 
453c6b6a421SHawking Zhang 	*value = 0;
454c6b6a421SHawking Zhang 	for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
455c6b6a421SHawking Zhang 		en = &nv_allowed_read_registers[i];
456fced3c3aSHuang Rui 		if ((i == 7 && (adev->sdma.num_instances == 1)) || /* some asics don't have SDMA1 */
457fced3c3aSHuang Rui 		    reg_offset !=
458c6b6a421SHawking Zhang 		    (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
459c6b6a421SHawking Zhang 			continue;
460c6b6a421SHawking Zhang 
461c6b6a421SHawking Zhang 		*value = nv_get_register_value(adev,
462c6b6a421SHawking Zhang 					       nv_allowed_read_registers[i].grbm_indexed,
463c6b6a421SHawking Zhang 					       se_num, sh_num, reg_offset);
464c6b6a421SHawking Zhang 		return 0;
465c6b6a421SHawking Zhang 	}
466c6b6a421SHawking Zhang 	return -EINVAL;
467c6b6a421SHawking Zhang }
468c6b6a421SHawking Zhang 
469b913ec62SAlex Deucher static int nv_asic_mode2_reset(struct amdgpu_device *adev)
470b913ec62SAlex Deucher {
471b913ec62SAlex Deucher 	u32 i;
472b913ec62SAlex Deucher 	int ret = 0;
473b913ec62SAlex Deucher 
474b913ec62SAlex Deucher 	amdgpu_atombios_scratch_regs_engine_hung(adev, true);
475b913ec62SAlex Deucher 
476b913ec62SAlex Deucher 	/* disable BM */
477b913ec62SAlex Deucher 	pci_clear_master(adev->pdev);
478b913ec62SAlex Deucher 
479b913ec62SAlex Deucher 	amdgpu_device_cache_pci_state(adev->pdev);
480b913ec62SAlex Deucher 
481b913ec62SAlex Deucher 	ret = amdgpu_dpm_mode2_reset(adev);
482b913ec62SAlex Deucher 	if (ret)
483b913ec62SAlex Deucher 		dev_err(adev->dev, "GPU mode2 reset failed\n");
484b913ec62SAlex Deucher 
485b913ec62SAlex Deucher 	amdgpu_device_load_pci_state(adev->pdev);
486b913ec62SAlex Deucher 
487b913ec62SAlex Deucher 	/* wait for asic to come out of reset */
488b913ec62SAlex Deucher 	for (i = 0; i < adev->usec_timeout; i++) {
489b913ec62SAlex Deucher 		u32 memsize = adev->nbio.funcs->get_memsize(adev);
490b913ec62SAlex Deucher 
491b913ec62SAlex Deucher 		if (memsize != 0xffffffff)
492b913ec62SAlex Deucher 			break;
493b913ec62SAlex Deucher 		udelay(1);
494b913ec62SAlex Deucher 	}
495b913ec62SAlex Deucher 
496b913ec62SAlex Deucher 	amdgpu_atombios_scratch_regs_engine_hung(adev, false);
497b913ec62SAlex Deucher 
498b913ec62SAlex Deucher 	return ret;
499b913ec62SAlex Deucher }
500b913ec62SAlex Deucher 
5012ddc6c3eSAlex Deucher static enum amd_reset_method
5022ddc6c3eSAlex Deucher nv_asic_reset_method(struct amdgpu_device *adev)
5032ddc6c3eSAlex Deucher {
504273da6ffSWenhui Sheng 	if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
50516086355SAlex Deucher 	    amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
506f172865aSAlex Deucher 	    amdgpu_reset_method == AMD_RESET_METHOD_BACO ||
507f172865aSAlex Deucher 	    amdgpu_reset_method == AMD_RESET_METHOD_PCI)
508273da6ffSWenhui Sheng 		return amdgpu_reset_method;
509273da6ffSWenhui Sheng 
510273da6ffSWenhui Sheng 	if (amdgpu_reset_method != -1)
511273da6ffSWenhui Sheng 		dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
512273da6ffSWenhui Sheng 				  amdgpu_reset_method);
513273da6ffSWenhui Sheng 
514ca6fd7a6SLikun Gao 	switch (adev->asic_type) {
51516086355SAlex Deucher 	case CHIP_VANGOGH:
5167d38d9dcSAaron Liu 	case CHIP_YELLOW_CARP:
51716086355SAlex Deucher 		return AMD_RESET_METHOD_MODE2;
518ca6fd7a6SLikun Gao 	case CHIP_SIENNA_CICHLID:
51922dd44f4SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
52015ed44c0STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
5215ed7715dSChengming Gui 	case CHIP_BEIGE_GOBY:
522ca6fd7a6SLikun Gao 		return AMD_RESET_METHOD_MODE1;
523ca6fd7a6SLikun Gao 	default:
524181e772fSEvan Quan 		if (amdgpu_dpm_is_baco_supported(adev))
5252ddc6c3eSAlex Deucher 			return AMD_RESET_METHOD_BACO;
5262ddc6c3eSAlex Deucher 		else
5272ddc6c3eSAlex Deucher 			return AMD_RESET_METHOD_MODE1;
5282ddc6c3eSAlex Deucher 	}
529ca6fd7a6SLikun Gao }
5302ddc6c3eSAlex Deucher 
531c6b6a421SHawking Zhang static int nv_asic_reset(struct amdgpu_device *adev)
532c6b6a421SHawking Zhang {
533767acabdSKevin Wang 	int ret = 0;
534c6b6a421SHawking Zhang 
53516086355SAlex Deucher 	switch (nv_asic_reset_method(adev)) {
536f172865aSAlex Deucher 	case AMD_RESET_METHOD_PCI:
537f172865aSAlex Deucher 		dev_info(adev->dev, "PCI reset\n");
538f172865aSAlex Deucher 		ret = amdgpu_device_pci_reset(adev);
539f172865aSAlex Deucher 		break;
54016086355SAlex Deucher 	case AMD_RESET_METHOD_BACO:
54111043b7aSAlex Deucher 		dev_info(adev->dev, "BACO reset\n");
542181e772fSEvan Quan 		ret = amdgpu_dpm_baco_reset(adev);
54316086355SAlex Deucher 		break;
54416086355SAlex Deucher 	case AMD_RESET_METHOD_MODE2:
54516086355SAlex Deucher 		dev_info(adev->dev, "MODE2 reset\n");
546b913ec62SAlex Deucher 		ret = nv_asic_mode2_reset(adev);
54716086355SAlex Deucher 		break;
54816086355SAlex Deucher 	default:
54911043b7aSAlex Deucher 		dev_info(adev->dev, "MODE1 reset\n");
5505c03e584SFeifei Xu 		ret = amdgpu_device_mode1_reset(adev);
55116086355SAlex Deucher 		break;
55211043b7aSAlex Deucher 	}
553767acabdSKevin Wang 
554767acabdSKevin Wang 	return ret;
555c6b6a421SHawking Zhang }
556c6b6a421SHawking Zhang 
557c6b6a421SHawking Zhang static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
558c6b6a421SHawking Zhang {
559c6b6a421SHawking Zhang 	/* todo */
560c6b6a421SHawking Zhang 	return 0;
561c6b6a421SHawking Zhang }
562c6b6a421SHawking Zhang 
563c6b6a421SHawking Zhang static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
564c6b6a421SHawking Zhang {
565c6b6a421SHawking Zhang 	/* todo */
566c6b6a421SHawking Zhang 	return 0;
567c6b6a421SHawking Zhang }
568c6b6a421SHawking Zhang 
569c6b6a421SHawking Zhang static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
570c6b6a421SHawking Zhang {
571c6b6a421SHawking Zhang 	if (pci_is_root_bus(adev->pdev->bus))
572c6b6a421SHawking Zhang 		return;
573c6b6a421SHawking Zhang 
574c6b6a421SHawking Zhang 	if (amdgpu_pcie_gen2 == 0)
575c6b6a421SHawking Zhang 		return;
576c6b6a421SHawking Zhang 
577c6b6a421SHawking Zhang 	if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
578c6b6a421SHawking Zhang 					CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
579c6b6a421SHawking Zhang 		return;
580c6b6a421SHawking Zhang 
581c6b6a421SHawking Zhang 	/* todo */
582c6b6a421SHawking Zhang }
583c6b6a421SHawking Zhang 
584c6b6a421SHawking Zhang static void nv_program_aspm(struct amdgpu_device *adev)
585c6b6a421SHawking Zhang {
5860064b0ceSKenneth Feng 	if (!amdgpu_aspm)
587c6b6a421SHawking Zhang 		return;
588c6b6a421SHawking Zhang 
5893273f8b9SKenneth Feng 	if (!(adev->flags & AMD_IS_APU) &&
590e1edaeafSLikun Gao 	    (adev->nbio.funcs->program_aspm))
591e1edaeafSLikun Gao 		adev->nbio.funcs->program_aspm(adev);
592e1edaeafSLikun Gao 
593c6b6a421SHawking Zhang }
594c6b6a421SHawking Zhang 
595c6b6a421SHawking Zhang static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
596c6b6a421SHawking Zhang 					bool enable)
597c6b6a421SHawking Zhang {
598bebc0762SHawking Zhang 	adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
599bebc0762SHawking Zhang 	adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
600c6b6a421SHawking Zhang }
601c6b6a421SHawking Zhang 
602c6b6a421SHawking Zhang static const struct amdgpu_ip_block_version nv_common_ip_block =
603c6b6a421SHawking Zhang {
604c6b6a421SHawking Zhang 	.type = AMD_IP_BLOCK_TYPE_COMMON,
605c6b6a421SHawking Zhang 	.major = 1,
606c6b6a421SHawking Zhang 	.minor = 0,
607c6b6a421SHawking Zhang 	.rev = 0,
608c6b6a421SHawking Zhang 	.funcs = &nv_common_ip_funcs,
609c6b6a421SHawking Zhang };
610c6b6a421SHawking Zhang 
61132358093SLikun Gao static bool nv_is_headless_sku(struct pci_dev *pdev)
61232358093SLikun Gao {
61332358093SLikun Gao 	if ((pdev->device == 0x731E &&
61432358093SLikun Gao 	    (pdev->revision == 0xC6 || pdev->revision == 0xC7)) ||
61532358093SLikun Gao 	    (pdev->device == 0x7340 && pdev->revision == 0xC9)  ||
61632358093SLikun Gao 	    (pdev->device == 0x7360 && pdev->revision == 0xC7))
61732358093SLikun Gao 		return true;
61832358093SLikun Gao 	return false;
61932358093SLikun Gao }
62032358093SLikun Gao 
621b5c73856SXiaojie Yuan static int nv_reg_base_init(struct amdgpu_device *adev)
622c6b6a421SHawking Zhang {
623b5c73856SXiaojie Yuan 	int r;
624b5c73856SXiaojie Yuan 
625b5c73856SXiaojie Yuan 	if (amdgpu_discovery) {
626b5c73856SXiaojie Yuan 		r = amdgpu_discovery_reg_base_init(adev);
627b5c73856SXiaojie Yuan 		if (r) {
628b5c73856SXiaojie Yuan 			DRM_WARN("failed to init reg base from ip discovery table, "
629b5c73856SXiaojie Yuan 					"fallback to legacy init method\n");
630b5c73856SXiaojie Yuan 			goto legacy_init;
631b5c73856SXiaojie Yuan 		}
632b5c73856SXiaojie Yuan 
6337bd939d0SLikun GAO 		amdgpu_discovery_harvest_ip(adev);
63432358093SLikun Gao 		if (nv_is_headless_sku(adev->pdev)) {
63532358093SLikun Gao 			adev->harvest_ip_mask |= AMD_HARVEST_IP_VCN_MASK;
63632358093SLikun Gao 			adev->harvest_ip_mask |= AMD_HARVEST_IP_JPEG_MASK;
63732358093SLikun Gao 		}
6387bd939d0SLikun GAO 
639b5c73856SXiaojie Yuan 		return 0;
640b5c73856SXiaojie Yuan 	}
641b5c73856SXiaojie Yuan 
642b5c73856SXiaojie Yuan legacy_init:
643c6b6a421SHawking Zhang 	switch (adev->asic_type) {
644c6b6a421SHawking Zhang 	case CHIP_NAVI10:
645c6b6a421SHawking Zhang 		navi10_reg_base_init(adev);
646c6b6a421SHawking Zhang 		break;
647a0f6d926SXiaojie Yuan 	case CHIP_NAVI14:
648a0f6d926SXiaojie Yuan 		navi14_reg_base_init(adev);
649a0f6d926SXiaojie Yuan 		break;
65003d0a073SXiaojie Yuan 	case CHIP_NAVI12:
65103d0a073SXiaojie Yuan 		navi12_reg_base_init(adev);
65203d0a073SXiaojie Yuan 		break;
653dccdbf3fSLikun Gao 	case CHIP_SIENNA_CICHLID:
654c8c959f6SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
655dccdbf3fSLikun Gao 		sienna_cichlid_reg_base_init(adev);
656dccdbf3fSLikun Gao 		break;
657026570e6SHuang Rui 	case CHIP_VANGOGH:
658026570e6SHuang Rui 		vangogh_reg_base_init(adev);
659026570e6SHuang Rui 		break;
660038d757bSTao Zhou 	case CHIP_DIMGREY_CAVEFISH:
661038d757bSTao Zhou 		dimgrey_cavefish_reg_base_init(adev);
662038d757bSTao Zhou 		break;
663fd5b4b44SChengming Gui 	case CHIP_BEIGE_GOBY:
664fd5b4b44SChengming Gui 		beige_goby_reg_base_init(adev);
665fd5b4b44SChengming Gui 		break;
666e7990721SAaron Liu 	case CHIP_YELLOW_CARP:
667e7990721SAaron Liu 		yellow_carp_reg_base_init(adev);
668e7990721SAaron Liu 		break;
66970839197STao Zhou 	case CHIP_CYAN_SKILLFISH:
67070839197STao Zhou 		cyan_skillfish_reg_base_init(adev);
67170839197STao Zhou 		break;
672c6b6a421SHawking Zhang 	default:
673c6b6a421SHawking Zhang 		return -EINVAL;
674c6b6a421SHawking Zhang 	}
675c6b6a421SHawking Zhang 
676b5c73856SXiaojie Yuan 	return 0;
677b5c73856SXiaojie Yuan }
678b5c73856SXiaojie Yuan 
679c1299461SWenhui Sheng void nv_set_virt_ops(struct amdgpu_device *adev)
680c1299461SWenhui Sheng {
681c1299461SWenhui Sheng 	adev->virt.ops = &xgpu_nv_virt_ops;
682c1299461SWenhui Sheng }
683c1299461SWenhui Sheng 
684b5c73856SXiaojie Yuan int nv_set_ip_blocks(struct amdgpu_device *adev)
685b5c73856SXiaojie Yuan {
686b5c73856SXiaojie Yuan 	int r;
687b5c73856SXiaojie Yuan 
688*338b3cf0STao Zhou 	if (adev->asic_type == CHIP_CYAN_SKILLFISH) {
689*338b3cf0STao Zhou 		adev->nbio.funcs = &nbio_v2_3_funcs;
690*338b3cf0STao Zhou 		adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
691*338b3cf0STao Zhou 	} else if (adev->flags & AMD_IS_APU) {
692a7e91bd7SHuang Rui 		adev->nbio.funcs = &nbio_v7_2_funcs;
693a7e91bd7SHuang Rui 		adev->nbio.hdp_flush_reg = &nbio_v7_2_hdp_flush_reg;
694a7e91bd7SHuang Rui 	} else {
695122078deSMonk Liu 		adev->nbio.funcs = &nbio_v2_3_funcs;
696122078deSMonk Liu 		adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
697a7e91bd7SHuang Rui 	}
698bf087285SLikun Gao 	adev->hdp.funcs = &hdp_v5_0_funcs;
699122078deSMonk Liu 
7000bf7f2dcSLikun Gao 	if (adev->asic_type >= CHIP_SIENNA_CICHLID)
7010bf7f2dcSLikun Gao 		adev->smuio.funcs = &smuio_v11_0_6_funcs;
7020bf7f2dcSLikun Gao 	else
7030bf7f2dcSLikun Gao 		adev->smuio.funcs = &smuio_v11_0_funcs;
7040bf7f2dcSLikun Gao 
705c652923aSJohn Clements 	if (adev->asic_type == CHIP_SIENNA_CICHLID)
706c652923aSJohn Clements 		adev->gmc.xgmi.supported = true;
707c652923aSJohn Clements 
708b5c73856SXiaojie Yuan 	/* Set IP register base before any HW register access */
709b5c73856SXiaojie Yuan 	r = nv_reg_base_init(adev);
710b5c73856SXiaojie Yuan 	if (r)
711b5c73856SXiaojie Yuan 		return r;
712b5c73856SXiaojie Yuan 
713c6b6a421SHawking Zhang 	switch (adev->asic_type) {
714c6b6a421SHawking Zhang 	case CHIP_NAVI10:
715d1daf850SAlex Deucher 	case CHIP_NAVI14:
716c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
717c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
718c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
719c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
720c6b6a421SHawking Zhang 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
7219530273eSEvan Quan 		    !amdgpu_sriov_vf(adev))
722c6b6a421SHawking Zhang 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
723c6b6a421SHawking Zhang 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
724c6b6a421SHawking Zhang 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
725f8a7976bSAlex Deucher #if defined(CONFIG_DRM_AMD_DC)
7268301f6b9STianci.Yin 		else if (amdgpu_device_has_dc_support(adev))
727b4f199c7SHarry Wentland 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
728f8a7976bSAlex Deucher #endif
729c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
730c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
731c6b6a421SHawking Zhang 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
7329530273eSEvan Quan 		    !amdgpu_sriov_vf(adev))
733c6b6a421SHawking Zhang 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
734c6b6a421SHawking Zhang 		amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
7355be45a26SLeo Liu 		amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
736c6b6a421SHawking Zhang 		if (adev->enable_mes)
737c6b6a421SHawking Zhang 			amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
738c6b6a421SHawking Zhang 		break;
73944e9e7c9SXiaojie Yuan 	case CHIP_NAVI12:
74044e9e7c9SXiaojie Yuan 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
74144e9e7c9SXiaojie Yuan 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
7422a4021ccSPeng Ju Zhou 		if (!amdgpu_sriov_vf(adev)) {
74344e9e7c9SXiaojie Yuan 			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
7446b66ae2eSXiaojie Yuan 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
7452a4021ccSPeng Ju Zhou 		} else {
7462a4021ccSPeng Ju Zhou 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
7472a4021ccSPeng Ju Zhou 			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
7482a4021ccSPeng Ju Zhou 		}
74979bebabbSMonk Liu 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
7507f47efebSXiaojie Yuan 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
75179902029SXiaojie Yuan 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
75279902029SXiaojie Yuan 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
75320c14ee1SPetr Cvek #if defined(CONFIG_DRM_AMD_DC)
754078655d9SLeo Li 		else if (amdgpu_device_has_dc_support(adev))
755078655d9SLeo Li 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
75620c14ee1SPetr Cvek #endif
75744e9e7c9SXiaojie Yuan 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
75844e9e7c9SXiaojie Yuan 		amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
7597f47efebSXiaojie Yuan 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
7609530273eSEvan Quan 		    !amdgpu_sriov_vf(adev))
7617f47efebSXiaojie Yuan 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
7621fbed280SBoyuan Zhang 		amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
763fe442491SMonk Liu 		if (!amdgpu_sriov_vf(adev))
7645be45a26SLeo Liu 			amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
76544e9e7c9SXiaojie Yuan 		break;
7662e1ba10eSLikun Gao 	case CHIP_SIENNA_CICHLID:
7672e1ba10eSLikun Gao 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
7680b3df16bSLikun Gao 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
7694aa7e6e0SYuBiao Wang 		if (!amdgpu_sriov_vf(adev)) {
770757b3af8SLikun Gao 			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
77156304e72SLikun Gao 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
7725aa02350SLikun Gao 				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
7734aa7e6e0SYuBiao Wang 		} else {
7744aa7e6e0SYuBiao Wang 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
7754aa7e6e0SYuBiao Wang 				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
7764aa7e6e0SYuBiao Wang 			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
7774aa7e6e0SYuBiao Wang 		}
778b07e5c60SLikun Gao 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
779acf2740fSJane Jian 		    is_support_sw_smu(adev))
780b07e5c60SLikun Gao 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
7819a986760SLikun Gao 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
7829a986760SLikun Gao 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
783464ab91aSBhawanpreet Lakha #if defined(CONFIG_DRM_AMD_DC)
784464ab91aSBhawanpreet Lakha 		else if (amdgpu_device_has_dc_support(adev))
785464ab91aSBhawanpreet Lakha 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
786464ab91aSBhawanpreet Lakha #endif
787933c8a93SLikun Gao 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
788157e72e8SLikun Gao 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
789b8f10585SLeo Liu 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
790c45fbe1bSJack Zhang 		if (!amdgpu_sriov_vf(adev))
7914d72dd12SLeo Liu 			amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
792a346ef86SJack Xiao 		if (adev->enable_mes)
793a346ef86SJack Xiao 			amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
7942e1ba10eSLikun Gao 		break;
7958515e0a4SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
7968515e0a4SJiansong Chen 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
797fc8f07daSJiansong Chen 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
798026c396bSJiansong Chen 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
7997420eab2SJiansong Chen 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
8007420eab2SJiansong Chen 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
8017420eab2SJiansong Chen 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
8027420eab2SJiansong Chen 		    is_support_sw_smu(adev))
8037420eab2SJiansong Chen 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
8045404f073SJiansong Chen 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
8055404f073SJiansong Chen 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
806a6c5308fSBhawanpreet Lakha #if defined(CONFIG_DRM_AMD_DC)
807a6c5308fSBhawanpreet Lakha 		else if (amdgpu_device_has_dc_support(adev))
808a6c5308fSBhawanpreet Lakha 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
809a6c5308fSBhawanpreet Lakha #endif
810885eb3faSJiansong Chen 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
811df2d15dfSJiansong Chen 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
812290b4ad5SBoyuan Zhang 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
813290b4ad5SBoyuan Zhang 		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
814f4497d10SJiansong Chen 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
815f4497d10SJiansong Chen 		    is_support_sw_smu(adev))
816f4497d10SJiansong Chen 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
8178515e0a4SJiansong Chen 		break;
81888edbad6SHuang Rui 	case CHIP_VANGOGH:
81988edbad6SHuang Rui 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
82088edbad6SHuang Rui 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
82188edbad6SHuang Rui 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
822ed3b7353SHuang Rui 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
823ed3b7353SHuang Rui 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
824c821e0fbSHuang Rui 		amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
82588edbad6SHuang Rui 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
82688edbad6SHuang Rui 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
82784b934bcSHuang Rui #if defined(CONFIG_DRM_AMD_DC)
82884b934bcSHuang Rui 		else if (amdgpu_device_has_dc_support(adev))
82984b934bcSHuang Rui 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
83084b934bcSHuang Rui #endif
83188edbad6SHuang Rui 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
83288edbad6SHuang Rui 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
833b4e532d6SThong Thai 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
834b4e532d6SThong Thai 		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
83588edbad6SHuang Rui 		break;
8362aa92b12STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
8372aa92b12STao Zhou 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
8383e02ad44STao Zhou 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
839771cc67eSTao Zhou 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
840aff39cdeSTao Zhou 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
841aff39cdeSTao Zhou 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
842aff39cdeSTao Zhou 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
843aff39cdeSTao Zhou 		    is_support_sw_smu(adev))
844aff39cdeSTao Zhou 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
84576a2d9eaSTao Zhou 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
84676a2d9eaSTao Zhou 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
8477cc656e2STao Zhou #if defined(CONFIG_DRM_AMD_DC)
8487cc656e2STao Zhou                 else if (amdgpu_device_has_dc_support(adev))
8497cc656e2STao Zhou                         amdgpu_device_ip_block_add(adev, &dm_ip_block);
8507cc656e2STao Zhou #endif
851feb6329cSTao Zhou 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
85201069226STao Zhou 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
8530afc770bSJames Zhu 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
854be6b1cd3SJames Zhu 		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
8552aa92b12STao Zhou 		break;
856aa2caa2aSChengming Gui 	case CHIP_BEIGE_GOBY:
857aa2caa2aSChengming Gui 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
8582d527ea6SChengming Gui 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
859a1dede36SChengming Gui 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
860c0729819SChengming Gui 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
861c0729819SChengming Gui 			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
862c0729819SChengming Gui 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
863c0729819SChengming Gui 		    is_support_sw_smu(adev))
864c0729819SChengming Gui 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
865898319caSChengming Gui 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
8668760403eSChengming Gui 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
8675663da86SChengming Gui 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
8685663da86SChengming Gui 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
869ddaed58bSAurabindo Pillai #if defined(CONFIG_DRM_AMD_DC)
870ddaed58bSAurabindo Pillai 		else if (amdgpu_device_has_dc_support(adev))
871ddaed58bSAurabindo Pillai 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
872ddaed58bSAurabindo Pillai #endif
8734d352669SChengming Gui 		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
8744d352669SChengming Gui 		    is_support_sw_smu(adev))
8754d352669SChengming Gui 			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
876f703d4b6SVeerabadhran Gopalakrishnan 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
877aa2caa2aSChengming Gui 		break;
8785c462ca9SAaron Liu 	case CHIP_YELLOW_CARP:
8795c462ca9SAaron Liu 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
8805c462ca9SAaron Liu 		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
8815c462ca9SAaron Liu 		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
882903bb18bSAaron Liu 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
883903bb18bSAaron Liu 			amdgpu_device_ip_block_add(adev, &psp_v13_0_ip_block);
884120a6db4SAaron Liu 		amdgpu_device_ip_block_add(adev, &smu_v13_0_ip_block);
8855c462ca9SAaron Liu 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
8865c462ca9SAaron Liu 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
8875c462ca9SAaron Liu 		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
8885c462ca9SAaron Liu 		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
889c8b73f7fSNicholas Kazlauskas 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
890c8b73f7fSNicholas Kazlauskas 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
891c8b73f7fSNicholas Kazlauskas #if defined(CONFIG_DRM_AMD_DC)
892c8b73f7fSNicholas Kazlauskas 		else if (amdgpu_device_has_dc_support(adev))
893c8b73f7fSNicholas Kazlauskas 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
894c8b73f7fSNicholas Kazlauskas #endif
895ee8d893fSJames Zhu 		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
896ee8d893fSJames Zhu 		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
8975c462ca9SAaron Liu 		break;
898f36fb5a0STao Zhou 	case CHIP_CYAN_SKILLFISH:
899f36fb5a0STao Zhou 		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
900f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
901f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
902f36fb5a0STao Zhou                 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
903f36fb5a0STao Zhou                         amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
904f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
905f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
906f36fb5a0STao Zhou 		break;
907c6b6a421SHawking Zhang 	default:
908c6b6a421SHawking Zhang 		return -EINVAL;
909c6b6a421SHawking Zhang 	}
910c6b6a421SHawking Zhang 
911c6b6a421SHawking Zhang 	return 0;
912c6b6a421SHawking Zhang }
913c6b6a421SHawking Zhang 
914c6b6a421SHawking Zhang static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
915c6b6a421SHawking Zhang {
916bebc0762SHawking Zhang 	return adev->nbio.funcs->get_rev_id(adev);
917c6b6a421SHawking Zhang }
918c6b6a421SHawking Zhang 
919c6b6a421SHawking Zhang static bool nv_need_full_reset(struct amdgpu_device *adev)
920c6b6a421SHawking Zhang {
921c6b6a421SHawking Zhang 	return true;
922c6b6a421SHawking Zhang }
923c6b6a421SHawking Zhang 
924c6b6a421SHawking Zhang static bool nv_need_reset_on_init(struct amdgpu_device *adev)
925c6b6a421SHawking Zhang {
926c6b6a421SHawking Zhang 	u32 sol_reg;
927c6b6a421SHawking Zhang 
928c6b6a421SHawking Zhang 	if (adev->flags & AMD_IS_APU)
929c6b6a421SHawking Zhang 		return false;
930c6b6a421SHawking Zhang 
931c6b6a421SHawking Zhang 	/* Check sOS sign of life register to confirm sys driver and sOS
932c6b6a421SHawking Zhang 	 * are already been loaded.
933c6b6a421SHawking Zhang 	 */
934c6b6a421SHawking Zhang 	sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
935c6b6a421SHawking Zhang 	if (sol_reg)
936c6b6a421SHawking Zhang 		return true;
9373967ae6dSAlex Deucher 
938c6b6a421SHawking Zhang 	return false;
939c6b6a421SHawking Zhang }
940c6b6a421SHawking Zhang 
9412af81531SKevin Wang static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
9422af81531SKevin Wang {
9432af81531SKevin Wang 
9442af81531SKevin Wang 	/* TODO
9452af81531SKevin Wang 	 * dummy implement for pcie_replay_count sysfs interface
9462af81531SKevin Wang 	 * */
9472af81531SKevin Wang 
9482af81531SKevin Wang 	return 0;
9492af81531SKevin Wang }
9502af81531SKevin Wang 
951c6b6a421SHawking Zhang static void nv_init_doorbell_index(struct amdgpu_device *adev)
952c6b6a421SHawking Zhang {
953c6b6a421SHawking Zhang 	adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
954c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
955c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
956c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
957c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
958c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
959c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
960c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
961c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
962c6b6a421SHawking Zhang 	adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
963c6b6a421SHawking Zhang 	adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
964c6b6a421SHawking Zhang 	adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
965c6b6a421SHawking Zhang 	adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
96620519232SJack Xiao 	adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
967c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
968c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
969157e72e8SLikun Gao 	adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
970157e72e8SLikun Gao 	adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
971c6b6a421SHawking Zhang 	adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
972c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
973c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
974c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
975c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
976c6b6a421SHawking Zhang 	adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
977c6b6a421SHawking Zhang 	adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
978c6b6a421SHawking Zhang 
979c6b6a421SHawking Zhang 	adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
980c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_doorbell_range = 20;
981c6b6a421SHawking Zhang }
982c6b6a421SHawking Zhang 
983a7173731SAlex Deucher static void nv_pre_asic_init(struct amdgpu_device *adev)
984a7173731SAlex Deucher {
985a7173731SAlex Deucher }
986a7173731SAlex Deucher 
98727747293SEvan Quan static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
98827747293SEvan Quan 				       bool enter)
98927747293SEvan Quan {
99027747293SEvan Quan 	if (enter)
99127747293SEvan Quan 		amdgpu_gfx_rlc_enter_safe_mode(adev);
99227747293SEvan Quan 	else
99327747293SEvan Quan 		amdgpu_gfx_rlc_exit_safe_mode(adev);
99427747293SEvan Quan 
99527747293SEvan Quan 	if (adev->gfx.funcs->update_perfmon_mgcg)
99627747293SEvan Quan 		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
99727747293SEvan Quan 
9983273f8b9SKenneth Feng 	if (!(adev->flags & AMD_IS_APU) &&
999e1edaeafSLikun Gao 	    (adev->nbio.funcs->enable_aspm))
100027747293SEvan Quan 		adev->nbio.funcs->enable_aspm(adev, !enter);
100127747293SEvan Quan 
100227747293SEvan Quan 	return 0;
100327747293SEvan Quan }
100427747293SEvan Quan 
1005c6b6a421SHawking Zhang static const struct amdgpu_asic_funcs nv_asic_funcs =
1006c6b6a421SHawking Zhang {
1007c6b6a421SHawking Zhang 	.read_disabled_bios = &nv_read_disabled_bios,
1008c6b6a421SHawking Zhang 	.read_bios_from_rom = &nv_read_bios_from_rom,
1009c6b6a421SHawking Zhang 	.read_register = &nv_read_register,
1010c6b6a421SHawking Zhang 	.reset = &nv_asic_reset,
10112ddc6c3eSAlex Deucher 	.reset_method = &nv_asic_reset_method,
1012c6b6a421SHawking Zhang 	.set_vga_state = &nv_vga_set_state,
1013c6b6a421SHawking Zhang 	.get_xclk = &nv_get_xclk,
1014c6b6a421SHawking Zhang 	.set_uvd_clocks = &nv_set_uvd_clocks,
1015c6b6a421SHawking Zhang 	.set_vce_clocks = &nv_set_vce_clocks,
1016c6b6a421SHawking Zhang 	.get_config_memsize = &nv_get_config_memsize,
1017c6b6a421SHawking Zhang 	.init_doorbell_index = &nv_init_doorbell_index,
1018c6b6a421SHawking Zhang 	.need_full_reset = &nv_need_full_reset,
1019c6b6a421SHawking Zhang 	.need_reset_on_init = &nv_need_reset_on_init,
10202af81531SKevin Wang 	.get_pcie_replay_count = &nv_get_pcie_replay_count,
1021181e772fSEvan Quan 	.supports_baco = &amdgpu_dpm_is_baco_supported,
1022a7173731SAlex Deucher 	.pre_asic_init = &nv_pre_asic_init,
102327747293SEvan Quan 	.update_umd_stable_pstate = &nv_update_umd_stable_pstate,
10243b246e8bSAlex Deucher 	.query_video_codecs = &nv_query_video_codecs,
1025c6b6a421SHawking Zhang };
1026c6b6a421SHawking Zhang 
1027c6b6a421SHawking Zhang static int nv_common_early_init(void *handle)
1028c6b6a421SHawking Zhang {
1029923c087aSYong Zhao #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1030c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1031c6b6a421SHawking Zhang 
1032923c087aSYong Zhao 	adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1033923c087aSYong Zhao 	adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
1034c6b6a421SHawking Zhang 	adev->smc_rreg = NULL;
1035c6b6a421SHawking Zhang 	adev->smc_wreg = NULL;
1036c6b6a421SHawking Zhang 	adev->pcie_rreg = &nv_pcie_rreg;
1037c6b6a421SHawking Zhang 	adev->pcie_wreg = &nv_pcie_wreg;
10384922f1bcSJohn Clements 	adev->pcie_rreg64 = &nv_pcie_rreg64;
10394922f1bcSJohn Clements 	adev->pcie_wreg64 = &nv_pcie_wreg64;
10405de54343SHuang Rui 	adev->pciep_rreg = &nv_pcie_port_rreg;
10415de54343SHuang Rui 	adev->pciep_wreg = &nv_pcie_port_wreg;
1042c6b6a421SHawking Zhang 
1043c6b6a421SHawking Zhang 	/* TODO: will add them during VCN v2 implementation */
1044c6b6a421SHawking Zhang 	adev->uvd_ctx_rreg = NULL;
1045c6b6a421SHawking Zhang 	adev->uvd_ctx_wreg = NULL;
1046c6b6a421SHawking Zhang 
1047c6b6a421SHawking Zhang 	adev->didt_rreg = &nv_didt_rreg;
1048c6b6a421SHawking Zhang 	adev->didt_wreg = &nv_didt_wreg;
1049c6b6a421SHawking Zhang 
1050c6b6a421SHawking Zhang 	adev->asic_funcs = &nv_asic_funcs;
1051c6b6a421SHawking Zhang 
1052c6b6a421SHawking Zhang 	adev->rev_id = nv_get_rev_id(adev);
1053c6b6a421SHawking Zhang 	adev->external_rev_id = 0xff;
1054c6b6a421SHawking Zhang 	switch (adev->asic_type) {
1055c6b6a421SHawking Zhang 	case CHIP_NAVI10:
1056c6b6a421SHawking Zhang 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1057c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_GFX_CGCG |
1058c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_IH_CG |
1059c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_HDP_MGCG |
1060c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_HDP_LS |
1061c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_SDMA_MGCG |
1062c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_SDMA_LS |
1063c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_MC_MGCG |
1064c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_MC_LS |
1065c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_ATHUB_MGCG |
1066c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_ATHUB_LS |
1067c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_VCN_MGCG |
1068099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG |
1069c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_BIF_MGCG |
1070c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_BIF_LS;
1071157710eaSLeo Liu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1072c12d410fSHuang Rui 			AMD_PG_SUPPORT_VCN_DPG |
1073099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
1074a201b6acSHuang Rui 			AMD_PG_SUPPORT_ATHUB;
1075c6b6a421SHawking Zhang 		adev->external_rev_id = adev->rev_id + 0x1;
1076c6b6a421SHawking Zhang 		break;
10775e71e011SXiaojie Yuan 	case CHIP_NAVI14:
1078d0c39f8cSXiaojie Yuan 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1079d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CGCG |
1080d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_IH_CG |
1081d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_MGCG |
1082d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_LS |
1083d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_MGCG |
1084d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_LS |
1085d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_MC_MGCG |
1086d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_MC_LS |
1087d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_MGCG |
1088d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_LS |
1089d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_VCN_MGCG |
1090099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG |
1091d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_BIF_MGCG |
1092d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_BIF_LS;
10930377b088SXiaojie Yuan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1094099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
10950377b088SXiaojie Yuan 			AMD_PG_SUPPORT_VCN_DPG;
109635ef88faStiancyin 		adev->external_rev_id = adev->rev_id + 20;
10975e71e011SXiaojie Yuan 		break;
109874b5e509SXiaojie Yuan 	case CHIP_NAVI12:
1099dca009e7SXiaojie Yuan 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1100dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_MGLS |
1101dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CGCG |
1102dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CP_LS |
11035211c37aSXiaojie Yuan 			AMD_CG_SUPPORT_GFX_RLC_LS |
1104fbe0bc57SXiaojie Yuan 			AMD_CG_SUPPORT_IH_CG |
11055211c37aSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_MGCG |
1106358ab97fSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_LS |
1107358ab97fSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_MGCG |
11088b797b3dSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_LS |
11098b797b3dSXiaojie Yuan 			AMD_CG_SUPPORT_MC_MGCG |
1110ca51678dSXiaojie Yuan 			AMD_CG_SUPPORT_MC_LS |
1111ca51678dSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_MGCG |
111265872e59SXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_LS |
1113099d66e4SLeo Liu 			AMD_CG_SUPPORT_VCN_MGCG |
1114099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG;
1115c1653ea0SXiaojie Yuan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
11165ef3b8acSXiaojie Yuan 			AMD_PG_SUPPORT_VCN_DPG |
1117099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
11181b0443b1SLikun Gao 			AMD_PG_SUPPORT_ATHUB;
1119df5e984cSTiecheng Zhou 		/* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
1120df5e984cSTiecheng Zhou 		 * as a consequence, the rev_id and external_rev_id are wrong.
1121df5e984cSTiecheng Zhou 		 * workaround it by hardcoding rev_id to 0 (default value).
1122df5e984cSTiecheng Zhou 		 */
1123df5e984cSTiecheng Zhou 		if (amdgpu_sriov_vf(adev))
1124df5e984cSTiecheng Zhou 			adev->rev_id = 0;
112574b5e509SXiaojie Yuan 		adev->external_rev_id = adev->rev_id + 0xa;
112674b5e509SXiaojie Yuan 		break;
1127117910edSLikun Gao 	case CHIP_SIENNA_CICHLID:
112800194defSLikun Gao 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
112900194defSLikun Gao 			AMD_CG_SUPPORT_GFX_CGCG |
11301d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
113100194defSLikun Gao 			AMD_CG_SUPPORT_GFX_3D_CGCG |
113298f8ea29SLikun Gao 			AMD_CG_SUPPORT_MC_MGCG |
113300194defSLikun Gao 			AMD_CG_SUPPORT_VCN_MGCG |
1134ca36461fSKenneth Feng 			AMD_CG_SUPPORT_JPEG_MGCG |
1135ca36461fSKenneth Feng 			AMD_CG_SUPPORT_HDP_MGCG |
11363a32c25aSKenneth Feng 			AMD_CG_SUPPORT_HDP_LS |
1137bcc8367fSKenneth Feng 			AMD_CG_SUPPORT_IH_CG |
1138bcc8367fSKenneth Feng 			AMD_CG_SUPPORT_MC_LS;
1139b467c4f5SLeo Liu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1140d00b0fa9SBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
1141b794616dSKenneth Feng 			AMD_PG_SUPPORT_JPEG |
11421b0443b1SLikun Gao 			AMD_PG_SUPPORT_ATHUB |
11431b0443b1SLikun Gao 			AMD_PG_SUPPORT_MMHUB;
1144c45fbe1bSJack Zhang 		if (amdgpu_sriov_vf(adev)) {
1145c45fbe1bSJack Zhang 			/* hypervisor control CG and PG enablement */
1146c45fbe1bSJack Zhang 			adev->cg_flags = 0;
1147c45fbe1bSJack Zhang 			adev->pg_flags = 0;
1148c45fbe1bSJack Zhang 		}
1149117910edSLikun Gao 		adev->external_rev_id = adev->rev_id + 0x28;
1150117910edSLikun Gao 		break;
1151543aa259SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
115240582e67SJiansong Chen 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
115340582e67SJiansong Chen 			AMD_CG_SUPPORT_GFX_CGCG |
11541d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
115540582e67SJiansong Chen 			AMD_CG_SUPPORT_GFX_3D_CGCG |
115640582e67SJiansong Chen 			AMD_CG_SUPPORT_VCN_MGCG |
115792c73756SJiansong Chen 			AMD_CG_SUPPORT_JPEG_MGCG |
115892c73756SJiansong Chen 			AMD_CG_SUPPORT_MC_MGCG |
11594759f887SJiansong Chen 			AMD_CG_SUPPORT_MC_LS |
11604759f887SJiansong Chen 			AMD_CG_SUPPORT_HDP_MGCG |
116185e7151bSJiansong Chen 			AMD_CG_SUPPORT_HDP_LS |
116285e7151bSJiansong Chen 			AMD_CG_SUPPORT_IH_CG;
1163c6e9dd0eSBoyuan Zhang 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
116400740df9SBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
116547fc894aSJiansong Chen 			AMD_PG_SUPPORT_JPEG |
116647fc894aSJiansong Chen 			AMD_PG_SUPPORT_ATHUB |
116747fc894aSJiansong Chen 			AMD_PG_SUPPORT_MMHUB;
1168543aa259SJiansong Chen 		adev->external_rev_id = adev->rev_id + 0x32;
1169543aa259SJiansong Chen 		break;
1170543aa259SJiansong Chen 
1171026570e6SHuang Rui 	case CHIP_VANGOGH:
117251a7e938SJinzhou.Su 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
117351a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_MGLS |
117451a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_CP_LS |
117551a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_RLC_LS |
117651a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_CGCG |
1177ac0dc4c5SHuang Rui 			AMD_CG_SUPPORT_GFX_CGLS |
1178ac0dc4c5SHuang Rui 			AMD_CG_SUPPORT_GFX_3D_CGCG |
117907f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_GFX_3D_CGLS |
11800ebce667SJinzhou.Su 			AMD_CG_SUPPORT_MC_MGCG |
11810ebce667SJinzhou.Su 			AMD_CG_SUPPORT_MC_LS |
1182a3964ec4SJinzhou.Su 			AMD_CG_SUPPORT_GFX_FGCG |
118307f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_VCN_MGCG |
1184ef9bcfdeSJinzhou Su 			AMD_CG_SUPPORT_SDMA_MGCG |
1185ec0f72cbSJinzhou Su 			AMD_CG_SUPPORT_SDMA_LS |
118607f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_JPEG_MGCG;
118707f9c22fSBoyuan Zhang 		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
118807f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_VCN |
118907f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
119007f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_JPEG;
1191c345c89bSHuang Rui 		if (adev->apu_flags & AMD_APU_IS_VANGOGH)
1192026570e6SHuang Rui 			adev->external_rev_id = adev->rev_id + 0x01;
1193026570e6SHuang Rui 		break;
1194550c58e0STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
1195583e5a5eSTao Zhou 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1196583e5a5eSTao Zhou 			AMD_CG_SUPPORT_GFX_CGCG |
11971d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
1198583e5a5eSTao Zhou 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1199583e5a5eSTao Zhou 			AMD_CG_SUPPORT_VCN_MGCG |
1200135333a0STao Zhou 			AMD_CG_SUPPORT_JPEG_MGCG |
1201135333a0STao Zhou 			AMD_CG_SUPPORT_MC_MGCG |
12022c70c332STao Zhou 			AMD_CG_SUPPORT_MC_LS |
12032c70c332STao Zhou 			AMD_CG_SUPPORT_HDP_MGCG |
12048e3bfb99STao Zhou 			AMD_CG_SUPPORT_HDP_LS |
12058e3bfb99STao Zhou 			AMD_CG_SUPPORT_IH_CG;
1206d5bc1579SJames Zhu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1207cc6161aaSJames Zhu 			AMD_PG_SUPPORT_VCN_DPG |
120873da8e86STao Zhou 			AMD_PG_SUPPORT_JPEG |
120973da8e86STao Zhou 			AMD_PG_SUPPORT_ATHUB |
121073da8e86STao Zhou 			AMD_PG_SUPPORT_MMHUB;
1211550c58e0STao Zhou 		adev->external_rev_id = adev->rev_id + 0x3c;
1212550c58e0STao Zhou 		break;
12138573035aSChengming Gui 	case CHIP_BEIGE_GOBY:
1214bc6bd46bSTao Zhou 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1215bc6bd46bSTao Zhou 			AMD_CG_SUPPORT_GFX_CGCG |
1216d69d278fSTao Zhou 			AMD_CG_SUPPORT_GFX_CGLS |
12175d36b865STao Zhou 			AMD_CG_SUPPORT_GFX_3D_CGCG |
12185d36b865STao Zhou 			AMD_CG_SUPPORT_MC_MGCG |
1219170c193fSTao Zhou 			AMD_CG_SUPPORT_MC_LS |
1220170c193fSTao Zhou 			AMD_CG_SUPPORT_HDP_MGCG |
1221a764bef3STao Zhou 			AMD_CG_SUPPORT_HDP_LS |
1222e47e4c0eSVeerabadhran Gopalakrishnan 			AMD_CG_SUPPORT_IH_CG |
1223e47e4c0eSVeerabadhran Gopalakrishnan 			AMD_CG_SUPPORT_VCN_MGCG;
1224f703d4b6SVeerabadhran Gopalakrishnan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1225147de218STao Zhou 			AMD_PG_SUPPORT_VCN_DPG |
1226147de218STao Zhou 			AMD_PG_SUPPORT_ATHUB |
1227147de218STao Zhou 			AMD_PG_SUPPORT_MMHUB;
12288573035aSChengming Gui 		adev->external_rev_id = adev->rev_id + 0x46;
12298573035aSChengming Gui 		break;
1230e7990721SAaron Liu 	case CHIP_YELLOW_CARP:
12319c6c48e6SAaron Liu 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
12329c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_MGLS |
12339c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CGCG |
12349c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CGLS |
12359c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_3D_CGCG |
12369c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_3D_CGLS |
12379c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_RLC_LS |
12389c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CP_LS |
123983ae09b5SAaron Liu 			AMD_CG_SUPPORT_GFX_FGCG |
124083ae09b5SAaron Liu 			AMD_CG_SUPPORT_MC_MGCG |
1241f1e9aa65SAaron Liu 			AMD_CG_SUPPORT_MC_LS |
12426bd95572SAaron Liu 			AMD_CG_SUPPORT_SDMA_LS |
12436bd95572SAaron Liu 			AMD_CG_SUPPORT_HDP_MGCG |
1244b7dd14c7SAaron Liu 			AMD_CG_SUPPORT_HDP_LS |
1245b7dd14c7SAaron Liu 			AMD_CG_SUPPORT_ATHUB_MGCG |
1246db72c3faSAaron Liu 			AMD_CG_SUPPORT_ATHUB_LS |
1247948b1216SAaron Liu 			AMD_CG_SUPPORT_IH_CG |
1248948b1216SAaron Liu 			AMD_CG_SUPPORT_VCN_MGCG |
1249948b1216SAaron Liu 			AMD_CG_SUPPORT_JPEG_MGCG;
125054f4f6f3SJames Zhu 		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1251948b1216SAaron Liu 			AMD_PG_SUPPORT_VCN |
1252948b1216SAaron Liu 			AMD_PG_SUPPORT_VCN_DPG |
1253948b1216SAaron Liu 			AMD_PG_SUPPORT_JPEG;
1254e97c8d86SAaron Liu 		if (adev->pdev->device == 0x1681)
1255e97c8d86SAaron Liu 			adev->external_rev_id = adev->rev_id + 0x19;
1256e97c8d86SAaron Liu 		else
1257e7990721SAaron Liu 			adev->external_rev_id = adev->rev_id + 0x01;
1258e7990721SAaron Liu 		break;
1259b515937bSTao Zhou 	case CHIP_CYAN_SKILLFISH:
1260b515937bSTao Zhou 		adev->cg_flags = 0;
1261b515937bSTao Zhou 		adev->pg_flags = 0;
1262b515937bSTao Zhou 		adev->external_rev_id = adev->rev_id + 0x82;
1263b515937bSTao Zhou 		break;
1264c6b6a421SHawking Zhang 	default:
1265c6b6a421SHawking Zhang 		/* FIXME: not supported yet */
1266c6b6a421SHawking Zhang 		return -EINVAL;
1267c6b6a421SHawking Zhang 	}
1268c6b6a421SHawking Zhang 
12697bd939d0SLikun GAO 	if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
12707bd939d0SLikun GAO 		adev->pg_flags &= ~(AMD_PG_SUPPORT_VCN |
12717bd939d0SLikun GAO 				    AMD_PG_SUPPORT_VCN_DPG |
12727bd939d0SLikun GAO 				    AMD_PG_SUPPORT_JPEG);
12737bd939d0SLikun GAO 
1274b05b6903SJiange Zhao 	if (amdgpu_sriov_vf(adev)) {
1275b05b6903SJiange Zhao 		amdgpu_virt_init_setting(adev);
1276b05b6903SJiange Zhao 		xgpu_nv_mailbox_set_irq_funcs(adev);
1277b05b6903SJiange Zhao 	}
1278b05b6903SJiange Zhao 
1279c6b6a421SHawking Zhang 	return 0;
1280c6b6a421SHawking Zhang }
1281c6b6a421SHawking Zhang 
1282c6b6a421SHawking Zhang static int nv_common_late_init(void *handle)
1283c6b6a421SHawking Zhang {
1284b05b6903SJiange Zhao 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1285b05b6903SJiange Zhao 
1286ed9d2053SBokun Zhang 	if (amdgpu_sriov_vf(adev)) {
1287b05b6903SJiange Zhao 		xgpu_nv_mailbox_get_irq(adev);
1288ed9d2053SBokun Zhang 		amdgpu_virt_update_sriov_video_codec(adev,
1289ed9d2053SBokun Zhang 				sriov_sc_video_codecs_encode_array, ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
1290ed9d2053SBokun Zhang 				sriov_sc_video_codecs_decode_array, ARRAY_SIZE(sriov_sc_video_codecs_decode_array));
1291ed9d2053SBokun Zhang 	}
1292b05b6903SJiange Zhao 
1293c6b6a421SHawking Zhang 	return 0;
1294c6b6a421SHawking Zhang }
1295c6b6a421SHawking Zhang 
1296c6b6a421SHawking Zhang static int nv_common_sw_init(void *handle)
1297c6b6a421SHawking Zhang {
1298b05b6903SJiange Zhao 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1299b05b6903SJiange Zhao 
1300b05b6903SJiange Zhao 	if (amdgpu_sriov_vf(adev))
1301b05b6903SJiange Zhao 		xgpu_nv_mailbox_add_irq_id(adev);
1302b05b6903SJiange Zhao 
1303c6b6a421SHawking Zhang 	return 0;
1304c6b6a421SHawking Zhang }
1305c6b6a421SHawking Zhang 
1306c6b6a421SHawking Zhang static int nv_common_sw_fini(void *handle)
1307c6b6a421SHawking Zhang {
1308c6b6a421SHawking Zhang 	return 0;
1309c6b6a421SHawking Zhang }
1310c6b6a421SHawking Zhang 
1311c6b6a421SHawking Zhang static int nv_common_hw_init(void *handle)
1312c6b6a421SHawking Zhang {
1313c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1314c6b6a421SHawking Zhang 
13155a5da8aeSEvan Quan 	if (adev->nbio.funcs->apply_lc_spc_mode_wa)
13165a5da8aeSEvan Quan 		adev->nbio.funcs->apply_lc_spc_mode_wa(adev);
13175a5da8aeSEvan Quan 
1318adcf949eSEvan Quan 	if (adev->nbio.funcs->apply_l1_link_width_reconfig_wa)
1319adcf949eSEvan Quan 		adev->nbio.funcs->apply_l1_link_width_reconfig_wa(adev);
1320adcf949eSEvan Quan 
1321c6b6a421SHawking Zhang 	/* enable pcie gen2/3 link */
1322c6b6a421SHawking Zhang 	nv_pcie_gen3_enable(adev);
1323c6b6a421SHawking Zhang 	/* enable aspm */
1324c6b6a421SHawking Zhang 	nv_program_aspm(adev);
1325c6b6a421SHawking Zhang 	/* setup nbio registers */
1326bebc0762SHawking Zhang 	adev->nbio.funcs->init_registers(adev);
1327923c087aSYong Zhao 	/* remap HDP registers to a hole in mmio space,
1328923c087aSYong Zhao 	 * for the purpose of expose those registers
1329923c087aSYong Zhao 	 * to process space
1330923c087aSYong Zhao 	 */
1331923c087aSYong Zhao 	if (adev->nbio.funcs->remap_hdp_registers)
1332923c087aSYong Zhao 		adev->nbio.funcs->remap_hdp_registers(adev);
1333c6b6a421SHawking Zhang 	/* enable the doorbell aperture */
1334c6b6a421SHawking Zhang 	nv_enable_doorbell_aperture(adev, true);
1335c6b6a421SHawking Zhang 
1336c6b6a421SHawking Zhang 	return 0;
1337c6b6a421SHawking Zhang }
1338c6b6a421SHawking Zhang 
1339c6b6a421SHawking Zhang static int nv_common_hw_fini(void *handle)
1340c6b6a421SHawking Zhang {
1341c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1342c6b6a421SHawking Zhang 
1343c6b6a421SHawking Zhang 	/* disable the doorbell aperture */
1344c6b6a421SHawking Zhang 	nv_enable_doorbell_aperture(adev, false);
1345c6b6a421SHawking Zhang 
1346c6b6a421SHawking Zhang 	return 0;
1347c6b6a421SHawking Zhang }
1348c6b6a421SHawking Zhang 
1349c6b6a421SHawking Zhang static int nv_common_suspend(void *handle)
1350c6b6a421SHawking Zhang {
1351c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1352c6b6a421SHawking Zhang 
1353c6b6a421SHawking Zhang 	return nv_common_hw_fini(adev);
1354c6b6a421SHawking Zhang }
1355c6b6a421SHawking Zhang 
1356c6b6a421SHawking Zhang static int nv_common_resume(void *handle)
1357c6b6a421SHawking Zhang {
1358c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1359c6b6a421SHawking Zhang 
1360c6b6a421SHawking Zhang 	return nv_common_hw_init(adev);
1361c6b6a421SHawking Zhang }
1362c6b6a421SHawking Zhang 
1363c6b6a421SHawking Zhang static bool nv_common_is_idle(void *handle)
1364c6b6a421SHawking Zhang {
1365c6b6a421SHawking Zhang 	return true;
1366c6b6a421SHawking Zhang }
1367c6b6a421SHawking Zhang 
1368c6b6a421SHawking Zhang static int nv_common_wait_for_idle(void *handle)
1369c6b6a421SHawking Zhang {
1370c6b6a421SHawking Zhang 	return 0;
1371c6b6a421SHawking Zhang }
1372c6b6a421SHawking Zhang 
1373c6b6a421SHawking Zhang static int nv_common_soft_reset(void *handle)
1374c6b6a421SHawking Zhang {
1375c6b6a421SHawking Zhang 	return 0;
1376c6b6a421SHawking Zhang }
1377c6b6a421SHawking Zhang 
1378c6b6a421SHawking Zhang static int nv_common_set_clockgating_state(void *handle,
1379c6b6a421SHawking Zhang 					   enum amd_clockgating_state state)
1380c6b6a421SHawking Zhang {
1381c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1382c6b6a421SHawking Zhang 
1383c6b6a421SHawking Zhang 	if (amdgpu_sriov_vf(adev))
1384c6b6a421SHawking Zhang 		return 0;
1385c6b6a421SHawking Zhang 
1386c6b6a421SHawking Zhang 	switch (adev->asic_type) {
1387c6b6a421SHawking Zhang 	case CHIP_NAVI10:
13885e71e011SXiaojie Yuan 	case CHIP_NAVI14:
13897e17e58bSXiaojie Yuan 	case CHIP_NAVI12:
1390117910edSLikun Gao 	case CHIP_SIENNA_CICHLID:
1391543aa259SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
1392550c58e0STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
13938573035aSChengming Gui 	case CHIP_BEIGE_GOBY:
1394bebc0762SHawking Zhang 		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1395a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
1396bebc0762SHawking Zhang 		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1397a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
1398bf087285SLikun Gao 		adev->hdp.funcs->update_clock_gating(adev,
1399a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
14001001f2a1SLikun Gao 		adev->smuio.funcs->update_rom_clock_gating(adev,
14011001f2a1SLikun Gao 				state == AMD_CG_STATE_GATE);
1402c6b6a421SHawking Zhang 		break;
1403c6b6a421SHawking Zhang 	default:
1404c6b6a421SHawking Zhang 		break;
1405c6b6a421SHawking Zhang 	}
1406c6b6a421SHawking Zhang 	return 0;
1407c6b6a421SHawking Zhang }
1408c6b6a421SHawking Zhang 
1409c6b6a421SHawking Zhang static int nv_common_set_powergating_state(void *handle,
1410c6b6a421SHawking Zhang 					   enum amd_powergating_state state)
1411c6b6a421SHawking Zhang {
1412c6b6a421SHawking Zhang 	/* TODO */
1413c6b6a421SHawking Zhang 	return 0;
1414c6b6a421SHawking Zhang }
1415c6b6a421SHawking Zhang 
1416c6b6a421SHawking Zhang static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1417c6b6a421SHawking Zhang {
1418c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1419c6b6a421SHawking Zhang 
1420c6b6a421SHawking Zhang 	if (amdgpu_sriov_vf(adev))
1421c6b6a421SHawking Zhang 		*flags = 0;
1422c6b6a421SHawking Zhang 
1423bebc0762SHawking Zhang 	adev->nbio.funcs->get_clockgating_state(adev, flags);
1424c6b6a421SHawking Zhang 
1425bf087285SLikun Gao 	adev->hdp.funcs->get_clock_gating_state(adev, flags);
1426c6b6a421SHawking Zhang 
14271001f2a1SLikun Gao 	adev->smuio.funcs->get_clock_gating_state(adev, flags);
14281001f2a1SLikun Gao 
1429c6b6a421SHawking Zhang 	return;
1430c6b6a421SHawking Zhang }
1431c6b6a421SHawking Zhang 
1432c6b6a421SHawking Zhang static const struct amd_ip_funcs nv_common_ip_funcs = {
1433c6b6a421SHawking Zhang 	.name = "nv_common",
1434c6b6a421SHawking Zhang 	.early_init = nv_common_early_init,
1435c6b6a421SHawking Zhang 	.late_init = nv_common_late_init,
1436c6b6a421SHawking Zhang 	.sw_init = nv_common_sw_init,
1437c6b6a421SHawking Zhang 	.sw_fini = nv_common_sw_fini,
1438c6b6a421SHawking Zhang 	.hw_init = nv_common_hw_init,
1439c6b6a421SHawking Zhang 	.hw_fini = nv_common_hw_fini,
1440c6b6a421SHawking Zhang 	.suspend = nv_common_suspend,
1441c6b6a421SHawking Zhang 	.resume = nv_common_resume,
1442c6b6a421SHawking Zhang 	.is_idle = nv_common_is_idle,
1443c6b6a421SHawking Zhang 	.wait_for_idle = nv_common_wait_for_idle,
1444c6b6a421SHawking Zhang 	.soft_reset = nv_common_soft_reset,
1445c6b6a421SHawking Zhang 	.set_clockgating_state = nv_common_set_clockgating_state,
1446c6b6a421SHawking Zhang 	.set_powergating_state = nv_common_set_powergating_state,
1447c6b6a421SHawking Zhang 	.get_clockgating_state = nv_common_get_clockgating_state,
1448c6b6a421SHawking Zhang };
1449