xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/nv.c (revision 1c7916af)
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 
688338b3cf0STao Zhou 	if (adev->asic_type == CHIP_CYAN_SKILLFISH) {
689338b3cf0STao Zhou 		adev->nbio.funcs = &nbio_v2_3_funcs;
690338b3cf0STao Zhou 		adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
691338b3cf0STao 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);
902*1c7916afSLang Yu 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
903*1c7916afSLang Yu 			if (adev->apu_flags & AMD_APU_IS_CYAN_SKILLFISH2)
904*1c7916afSLang Yu 				amdgpu_device_ip_block_add(adev, &psp_v11_0_8_ip_block);
905*1c7916afSLang Yu 		}
906f36fb5a0STao Zhou                 if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
907f36fb5a0STao Zhou                         amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
908f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
909f36fb5a0STao Zhou                 amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
910f36fb5a0STao Zhou 		break;
911c6b6a421SHawking Zhang 	default:
912c6b6a421SHawking Zhang 		return -EINVAL;
913c6b6a421SHawking Zhang 	}
914c6b6a421SHawking Zhang 
915c6b6a421SHawking Zhang 	return 0;
916c6b6a421SHawking Zhang }
917c6b6a421SHawking Zhang 
918c6b6a421SHawking Zhang static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
919c6b6a421SHawking Zhang {
920bebc0762SHawking Zhang 	return adev->nbio.funcs->get_rev_id(adev);
921c6b6a421SHawking Zhang }
922c6b6a421SHawking Zhang 
923c6b6a421SHawking Zhang static bool nv_need_full_reset(struct amdgpu_device *adev)
924c6b6a421SHawking Zhang {
925c6b6a421SHawking Zhang 	return true;
926c6b6a421SHawking Zhang }
927c6b6a421SHawking Zhang 
928c6b6a421SHawking Zhang static bool nv_need_reset_on_init(struct amdgpu_device *adev)
929c6b6a421SHawking Zhang {
930c6b6a421SHawking Zhang 	u32 sol_reg;
931c6b6a421SHawking Zhang 
932c6b6a421SHawking Zhang 	if (adev->flags & AMD_IS_APU)
933c6b6a421SHawking Zhang 		return false;
934c6b6a421SHawking Zhang 
935c6b6a421SHawking Zhang 	/* Check sOS sign of life register to confirm sys driver and sOS
936c6b6a421SHawking Zhang 	 * are already been loaded.
937c6b6a421SHawking Zhang 	 */
938c6b6a421SHawking Zhang 	sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
939c6b6a421SHawking Zhang 	if (sol_reg)
940c6b6a421SHawking Zhang 		return true;
9413967ae6dSAlex Deucher 
942c6b6a421SHawking Zhang 	return false;
943c6b6a421SHawking Zhang }
944c6b6a421SHawking Zhang 
9452af81531SKevin Wang static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
9462af81531SKevin Wang {
9472af81531SKevin Wang 
9482af81531SKevin Wang 	/* TODO
9492af81531SKevin Wang 	 * dummy implement for pcie_replay_count sysfs interface
9502af81531SKevin Wang 	 * */
9512af81531SKevin Wang 
9522af81531SKevin Wang 	return 0;
9532af81531SKevin Wang }
9542af81531SKevin Wang 
955c6b6a421SHawking Zhang static void nv_init_doorbell_index(struct amdgpu_device *adev)
956c6b6a421SHawking Zhang {
957c6b6a421SHawking Zhang 	adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
958c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
959c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
960c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
961c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
962c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
963c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
964c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
965c6b6a421SHawking Zhang 	adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
966c6b6a421SHawking Zhang 	adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
967c6b6a421SHawking Zhang 	adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
968c6b6a421SHawking Zhang 	adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
969c6b6a421SHawking Zhang 	adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
97020519232SJack Xiao 	adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
971c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
972c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
973157e72e8SLikun Gao 	adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
974157e72e8SLikun Gao 	adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
975c6b6a421SHawking Zhang 	adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
976c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
977c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
978c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
979c6b6a421SHawking Zhang 	adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
980c6b6a421SHawking Zhang 	adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
981c6b6a421SHawking Zhang 	adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
982c6b6a421SHawking Zhang 
983c6b6a421SHawking Zhang 	adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
984c6b6a421SHawking Zhang 	adev->doorbell_index.sdma_doorbell_range = 20;
985c6b6a421SHawking Zhang }
986c6b6a421SHawking Zhang 
987a7173731SAlex Deucher static void nv_pre_asic_init(struct amdgpu_device *adev)
988a7173731SAlex Deucher {
989a7173731SAlex Deucher }
990a7173731SAlex Deucher 
99127747293SEvan Quan static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
99227747293SEvan Quan 				       bool enter)
99327747293SEvan Quan {
99427747293SEvan Quan 	if (enter)
99527747293SEvan Quan 		amdgpu_gfx_rlc_enter_safe_mode(adev);
99627747293SEvan Quan 	else
99727747293SEvan Quan 		amdgpu_gfx_rlc_exit_safe_mode(adev);
99827747293SEvan Quan 
99927747293SEvan Quan 	if (adev->gfx.funcs->update_perfmon_mgcg)
100027747293SEvan Quan 		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
100127747293SEvan Quan 
10023273f8b9SKenneth Feng 	if (!(adev->flags & AMD_IS_APU) &&
1003e1edaeafSLikun Gao 	    (adev->nbio.funcs->enable_aspm))
100427747293SEvan Quan 		adev->nbio.funcs->enable_aspm(adev, !enter);
100527747293SEvan Quan 
100627747293SEvan Quan 	return 0;
100727747293SEvan Quan }
100827747293SEvan Quan 
1009c6b6a421SHawking Zhang static const struct amdgpu_asic_funcs nv_asic_funcs =
1010c6b6a421SHawking Zhang {
1011c6b6a421SHawking Zhang 	.read_disabled_bios = &nv_read_disabled_bios,
1012c6b6a421SHawking Zhang 	.read_bios_from_rom = &nv_read_bios_from_rom,
1013c6b6a421SHawking Zhang 	.read_register = &nv_read_register,
1014c6b6a421SHawking Zhang 	.reset = &nv_asic_reset,
10152ddc6c3eSAlex Deucher 	.reset_method = &nv_asic_reset_method,
1016c6b6a421SHawking Zhang 	.set_vga_state = &nv_vga_set_state,
1017c6b6a421SHawking Zhang 	.get_xclk = &nv_get_xclk,
1018c6b6a421SHawking Zhang 	.set_uvd_clocks = &nv_set_uvd_clocks,
1019c6b6a421SHawking Zhang 	.set_vce_clocks = &nv_set_vce_clocks,
1020c6b6a421SHawking Zhang 	.get_config_memsize = &nv_get_config_memsize,
1021c6b6a421SHawking Zhang 	.init_doorbell_index = &nv_init_doorbell_index,
1022c6b6a421SHawking Zhang 	.need_full_reset = &nv_need_full_reset,
1023c6b6a421SHawking Zhang 	.need_reset_on_init = &nv_need_reset_on_init,
10242af81531SKevin Wang 	.get_pcie_replay_count = &nv_get_pcie_replay_count,
1025181e772fSEvan Quan 	.supports_baco = &amdgpu_dpm_is_baco_supported,
1026a7173731SAlex Deucher 	.pre_asic_init = &nv_pre_asic_init,
102727747293SEvan Quan 	.update_umd_stable_pstate = &nv_update_umd_stable_pstate,
10283b246e8bSAlex Deucher 	.query_video_codecs = &nv_query_video_codecs,
1029c6b6a421SHawking Zhang };
1030c6b6a421SHawking Zhang 
1031c6b6a421SHawking Zhang static int nv_common_early_init(void *handle)
1032c6b6a421SHawking Zhang {
1033923c087aSYong Zhao #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1034c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1035c6b6a421SHawking Zhang 
1036923c087aSYong Zhao 	adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1037923c087aSYong Zhao 	adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
1038c6b6a421SHawking Zhang 	adev->smc_rreg = NULL;
1039c6b6a421SHawking Zhang 	adev->smc_wreg = NULL;
1040c6b6a421SHawking Zhang 	adev->pcie_rreg = &nv_pcie_rreg;
1041c6b6a421SHawking Zhang 	adev->pcie_wreg = &nv_pcie_wreg;
10424922f1bcSJohn Clements 	adev->pcie_rreg64 = &nv_pcie_rreg64;
10434922f1bcSJohn Clements 	adev->pcie_wreg64 = &nv_pcie_wreg64;
10445de54343SHuang Rui 	adev->pciep_rreg = &nv_pcie_port_rreg;
10455de54343SHuang Rui 	adev->pciep_wreg = &nv_pcie_port_wreg;
1046c6b6a421SHawking Zhang 
1047c6b6a421SHawking Zhang 	/* TODO: will add them during VCN v2 implementation */
1048c6b6a421SHawking Zhang 	adev->uvd_ctx_rreg = NULL;
1049c6b6a421SHawking Zhang 	adev->uvd_ctx_wreg = NULL;
1050c6b6a421SHawking Zhang 
1051c6b6a421SHawking Zhang 	adev->didt_rreg = &nv_didt_rreg;
1052c6b6a421SHawking Zhang 	adev->didt_wreg = &nv_didt_wreg;
1053c6b6a421SHawking Zhang 
1054c6b6a421SHawking Zhang 	adev->asic_funcs = &nv_asic_funcs;
1055c6b6a421SHawking Zhang 
1056c6b6a421SHawking Zhang 	adev->rev_id = nv_get_rev_id(adev);
1057c6b6a421SHawking Zhang 	adev->external_rev_id = 0xff;
1058c6b6a421SHawking Zhang 	switch (adev->asic_type) {
1059c6b6a421SHawking Zhang 	case CHIP_NAVI10:
1060c6b6a421SHawking Zhang 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1061c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_GFX_CGCG |
1062c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_IH_CG |
1063c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_HDP_MGCG |
1064c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_HDP_LS |
1065c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_SDMA_MGCG |
1066c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_SDMA_LS |
1067c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_MC_MGCG |
1068c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_MC_LS |
1069c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_ATHUB_MGCG |
1070c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_ATHUB_LS |
1071c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_VCN_MGCG |
1072099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG |
1073c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_BIF_MGCG |
1074c6b6a421SHawking Zhang 			AMD_CG_SUPPORT_BIF_LS;
1075157710eaSLeo Liu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1076c12d410fSHuang Rui 			AMD_PG_SUPPORT_VCN_DPG |
1077099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
1078a201b6acSHuang Rui 			AMD_PG_SUPPORT_ATHUB;
1079c6b6a421SHawking Zhang 		adev->external_rev_id = adev->rev_id + 0x1;
1080c6b6a421SHawking Zhang 		break;
10815e71e011SXiaojie Yuan 	case CHIP_NAVI14:
1082d0c39f8cSXiaojie Yuan 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1083d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CGCG |
1084d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_IH_CG |
1085d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_MGCG |
1086d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_LS |
1087d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_MGCG |
1088d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_LS |
1089d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_MC_MGCG |
1090d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_MC_LS |
1091d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_MGCG |
1092d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_LS |
1093d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_VCN_MGCG |
1094099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG |
1095d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_BIF_MGCG |
1096d0c39f8cSXiaojie Yuan 			AMD_CG_SUPPORT_BIF_LS;
10970377b088SXiaojie Yuan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1098099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
10990377b088SXiaojie Yuan 			AMD_PG_SUPPORT_VCN_DPG;
110035ef88faStiancyin 		adev->external_rev_id = adev->rev_id + 20;
11015e71e011SXiaojie Yuan 		break;
110274b5e509SXiaojie Yuan 	case CHIP_NAVI12:
1103dca009e7SXiaojie Yuan 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1104dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_MGLS |
1105dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CGCG |
1106dca009e7SXiaojie Yuan 			AMD_CG_SUPPORT_GFX_CP_LS |
11075211c37aSXiaojie Yuan 			AMD_CG_SUPPORT_GFX_RLC_LS |
1108fbe0bc57SXiaojie Yuan 			AMD_CG_SUPPORT_IH_CG |
11095211c37aSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_MGCG |
1110358ab97fSXiaojie Yuan 			AMD_CG_SUPPORT_HDP_LS |
1111358ab97fSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_MGCG |
11128b797b3dSXiaojie Yuan 			AMD_CG_SUPPORT_SDMA_LS |
11138b797b3dSXiaojie Yuan 			AMD_CG_SUPPORT_MC_MGCG |
1114ca51678dSXiaojie Yuan 			AMD_CG_SUPPORT_MC_LS |
1115ca51678dSXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_MGCG |
111665872e59SXiaojie Yuan 			AMD_CG_SUPPORT_ATHUB_LS |
1117099d66e4SLeo Liu 			AMD_CG_SUPPORT_VCN_MGCG |
1118099d66e4SLeo Liu 			AMD_CG_SUPPORT_JPEG_MGCG;
1119c1653ea0SXiaojie Yuan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
11205ef3b8acSXiaojie Yuan 			AMD_PG_SUPPORT_VCN_DPG |
1121099d66e4SLeo Liu 			AMD_PG_SUPPORT_JPEG |
11221b0443b1SLikun Gao 			AMD_PG_SUPPORT_ATHUB;
1123df5e984cSTiecheng Zhou 		/* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
1124df5e984cSTiecheng Zhou 		 * as a consequence, the rev_id and external_rev_id are wrong.
1125df5e984cSTiecheng Zhou 		 * workaround it by hardcoding rev_id to 0 (default value).
1126df5e984cSTiecheng Zhou 		 */
1127df5e984cSTiecheng Zhou 		if (amdgpu_sriov_vf(adev))
1128df5e984cSTiecheng Zhou 			adev->rev_id = 0;
112974b5e509SXiaojie Yuan 		adev->external_rev_id = adev->rev_id + 0xa;
113074b5e509SXiaojie Yuan 		break;
1131117910edSLikun Gao 	case CHIP_SIENNA_CICHLID:
113200194defSLikun Gao 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
113300194defSLikun Gao 			AMD_CG_SUPPORT_GFX_CGCG |
11341d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
113500194defSLikun Gao 			AMD_CG_SUPPORT_GFX_3D_CGCG |
113698f8ea29SLikun Gao 			AMD_CG_SUPPORT_MC_MGCG |
113700194defSLikun Gao 			AMD_CG_SUPPORT_VCN_MGCG |
1138ca36461fSKenneth Feng 			AMD_CG_SUPPORT_JPEG_MGCG |
1139ca36461fSKenneth Feng 			AMD_CG_SUPPORT_HDP_MGCG |
11403a32c25aSKenneth Feng 			AMD_CG_SUPPORT_HDP_LS |
1141bcc8367fSKenneth Feng 			AMD_CG_SUPPORT_IH_CG |
1142bcc8367fSKenneth Feng 			AMD_CG_SUPPORT_MC_LS;
1143b467c4f5SLeo Liu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1144d00b0fa9SBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
1145b794616dSKenneth Feng 			AMD_PG_SUPPORT_JPEG |
11461b0443b1SLikun Gao 			AMD_PG_SUPPORT_ATHUB |
11471b0443b1SLikun Gao 			AMD_PG_SUPPORT_MMHUB;
1148c45fbe1bSJack Zhang 		if (amdgpu_sriov_vf(adev)) {
1149c45fbe1bSJack Zhang 			/* hypervisor control CG and PG enablement */
1150c45fbe1bSJack Zhang 			adev->cg_flags = 0;
1151c45fbe1bSJack Zhang 			adev->pg_flags = 0;
1152c45fbe1bSJack Zhang 		}
1153117910edSLikun Gao 		adev->external_rev_id = adev->rev_id + 0x28;
1154117910edSLikun Gao 		break;
1155543aa259SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
115640582e67SJiansong Chen 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
115740582e67SJiansong Chen 			AMD_CG_SUPPORT_GFX_CGCG |
11581d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
115940582e67SJiansong Chen 			AMD_CG_SUPPORT_GFX_3D_CGCG |
116040582e67SJiansong Chen 			AMD_CG_SUPPORT_VCN_MGCG |
116192c73756SJiansong Chen 			AMD_CG_SUPPORT_JPEG_MGCG |
116292c73756SJiansong Chen 			AMD_CG_SUPPORT_MC_MGCG |
11634759f887SJiansong Chen 			AMD_CG_SUPPORT_MC_LS |
11644759f887SJiansong Chen 			AMD_CG_SUPPORT_HDP_MGCG |
116585e7151bSJiansong Chen 			AMD_CG_SUPPORT_HDP_LS |
116685e7151bSJiansong Chen 			AMD_CG_SUPPORT_IH_CG;
1167c6e9dd0eSBoyuan Zhang 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
116800740df9SBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
116947fc894aSJiansong Chen 			AMD_PG_SUPPORT_JPEG |
117047fc894aSJiansong Chen 			AMD_PG_SUPPORT_ATHUB |
117147fc894aSJiansong Chen 			AMD_PG_SUPPORT_MMHUB;
1172543aa259SJiansong Chen 		adev->external_rev_id = adev->rev_id + 0x32;
1173543aa259SJiansong Chen 		break;
1174543aa259SJiansong Chen 
1175026570e6SHuang Rui 	case CHIP_VANGOGH:
117651a7e938SJinzhou.Su 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
117751a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_MGLS |
117851a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_CP_LS |
117951a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_RLC_LS |
118051a7e938SJinzhou.Su 			AMD_CG_SUPPORT_GFX_CGCG |
1181ac0dc4c5SHuang Rui 			AMD_CG_SUPPORT_GFX_CGLS |
1182ac0dc4c5SHuang Rui 			AMD_CG_SUPPORT_GFX_3D_CGCG |
118307f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_GFX_3D_CGLS |
11840ebce667SJinzhou.Su 			AMD_CG_SUPPORT_MC_MGCG |
11850ebce667SJinzhou.Su 			AMD_CG_SUPPORT_MC_LS |
1186a3964ec4SJinzhou.Su 			AMD_CG_SUPPORT_GFX_FGCG |
118707f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_VCN_MGCG |
1188ef9bcfdeSJinzhou Su 			AMD_CG_SUPPORT_SDMA_MGCG |
1189ec0f72cbSJinzhou Su 			AMD_CG_SUPPORT_SDMA_LS |
119007f9c22fSBoyuan Zhang 			AMD_CG_SUPPORT_JPEG_MGCG;
119107f9c22fSBoyuan Zhang 		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
119207f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_VCN |
119307f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_VCN_DPG |
119407f9c22fSBoyuan Zhang 			AMD_PG_SUPPORT_JPEG;
1195c345c89bSHuang Rui 		if (adev->apu_flags & AMD_APU_IS_VANGOGH)
1196026570e6SHuang Rui 			adev->external_rev_id = adev->rev_id + 0x01;
1197026570e6SHuang Rui 		break;
1198550c58e0STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
1199583e5a5eSTao Zhou 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1200583e5a5eSTao Zhou 			AMD_CG_SUPPORT_GFX_CGCG |
12011d712be9SKenneth Feng 			AMD_CG_SUPPORT_GFX_CGLS |
1202583e5a5eSTao Zhou 			AMD_CG_SUPPORT_GFX_3D_CGCG |
1203583e5a5eSTao Zhou 			AMD_CG_SUPPORT_VCN_MGCG |
1204135333a0STao Zhou 			AMD_CG_SUPPORT_JPEG_MGCG |
1205135333a0STao Zhou 			AMD_CG_SUPPORT_MC_MGCG |
12062c70c332STao Zhou 			AMD_CG_SUPPORT_MC_LS |
12072c70c332STao Zhou 			AMD_CG_SUPPORT_HDP_MGCG |
12088e3bfb99STao Zhou 			AMD_CG_SUPPORT_HDP_LS |
12098e3bfb99STao Zhou 			AMD_CG_SUPPORT_IH_CG;
1210d5bc1579SJames Zhu 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1211cc6161aaSJames Zhu 			AMD_PG_SUPPORT_VCN_DPG |
121273da8e86STao Zhou 			AMD_PG_SUPPORT_JPEG |
121373da8e86STao Zhou 			AMD_PG_SUPPORT_ATHUB |
121473da8e86STao Zhou 			AMD_PG_SUPPORT_MMHUB;
1215550c58e0STao Zhou 		adev->external_rev_id = adev->rev_id + 0x3c;
1216550c58e0STao Zhou 		break;
12178573035aSChengming Gui 	case CHIP_BEIGE_GOBY:
1218bc6bd46bSTao Zhou 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1219bc6bd46bSTao Zhou 			AMD_CG_SUPPORT_GFX_CGCG |
1220d69d278fSTao Zhou 			AMD_CG_SUPPORT_GFX_CGLS |
12215d36b865STao Zhou 			AMD_CG_SUPPORT_GFX_3D_CGCG |
12225d36b865STao Zhou 			AMD_CG_SUPPORT_MC_MGCG |
1223170c193fSTao Zhou 			AMD_CG_SUPPORT_MC_LS |
1224170c193fSTao Zhou 			AMD_CG_SUPPORT_HDP_MGCG |
1225a764bef3STao Zhou 			AMD_CG_SUPPORT_HDP_LS |
1226e47e4c0eSVeerabadhran Gopalakrishnan 			AMD_CG_SUPPORT_IH_CG |
1227e47e4c0eSVeerabadhran Gopalakrishnan 			AMD_CG_SUPPORT_VCN_MGCG;
1228f703d4b6SVeerabadhran Gopalakrishnan 		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1229147de218STao Zhou 			AMD_PG_SUPPORT_VCN_DPG |
1230147de218STao Zhou 			AMD_PG_SUPPORT_ATHUB |
1231147de218STao Zhou 			AMD_PG_SUPPORT_MMHUB;
12328573035aSChengming Gui 		adev->external_rev_id = adev->rev_id + 0x46;
12338573035aSChengming Gui 		break;
1234e7990721SAaron Liu 	case CHIP_YELLOW_CARP:
12359c6c48e6SAaron Liu 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
12369c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_MGLS |
12379c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CGCG |
12389c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CGLS |
12399c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_3D_CGCG |
12409c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_3D_CGLS |
12419c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_RLC_LS |
12429c6c48e6SAaron Liu 			AMD_CG_SUPPORT_GFX_CP_LS |
124383ae09b5SAaron Liu 			AMD_CG_SUPPORT_GFX_FGCG |
124483ae09b5SAaron Liu 			AMD_CG_SUPPORT_MC_MGCG |
1245f1e9aa65SAaron Liu 			AMD_CG_SUPPORT_MC_LS |
12466bd95572SAaron Liu 			AMD_CG_SUPPORT_SDMA_LS |
12476bd95572SAaron Liu 			AMD_CG_SUPPORT_HDP_MGCG |
1248b7dd14c7SAaron Liu 			AMD_CG_SUPPORT_HDP_LS |
1249b7dd14c7SAaron Liu 			AMD_CG_SUPPORT_ATHUB_MGCG |
1250db72c3faSAaron Liu 			AMD_CG_SUPPORT_ATHUB_LS |
1251948b1216SAaron Liu 			AMD_CG_SUPPORT_IH_CG |
1252948b1216SAaron Liu 			AMD_CG_SUPPORT_VCN_MGCG |
1253948b1216SAaron Liu 			AMD_CG_SUPPORT_JPEG_MGCG;
125454f4f6f3SJames Zhu 		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1255948b1216SAaron Liu 			AMD_PG_SUPPORT_VCN |
1256948b1216SAaron Liu 			AMD_PG_SUPPORT_VCN_DPG |
1257948b1216SAaron Liu 			AMD_PG_SUPPORT_JPEG;
1258e97c8d86SAaron Liu 		if (adev->pdev->device == 0x1681)
1259e97c8d86SAaron Liu 			adev->external_rev_id = adev->rev_id + 0x19;
1260e97c8d86SAaron Liu 		else
1261e7990721SAaron Liu 			adev->external_rev_id = adev->rev_id + 0x01;
1262e7990721SAaron Liu 		break;
1263b515937bSTao Zhou 	case CHIP_CYAN_SKILLFISH:
1264b515937bSTao Zhou 		adev->cg_flags = 0;
1265b515937bSTao Zhou 		adev->pg_flags = 0;
1266b515937bSTao Zhou 		adev->external_rev_id = adev->rev_id + 0x82;
1267b515937bSTao Zhou 		break;
1268c6b6a421SHawking Zhang 	default:
1269c6b6a421SHawking Zhang 		/* FIXME: not supported yet */
1270c6b6a421SHawking Zhang 		return -EINVAL;
1271c6b6a421SHawking Zhang 	}
1272c6b6a421SHawking Zhang 
12737bd939d0SLikun GAO 	if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
12747bd939d0SLikun GAO 		adev->pg_flags &= ~(AMD_PG_SUPPORT_VCN |
12757bd939d0SLikun GAO 				    AMD_PG_SUPPORT_VCN_DPG |
12767bd939d0SLikun GAO 				    AMD_PG_SUPPORT_JPEG);
12777bd939d0SLikun GAO 
1278b05b6903SJiange Zhao 	if (amdgpu_sriov_vf(adev)) {
1279b05b6903SJiange Zhao 		amdgpu_virt_init_setting(adev);
1280b05b6903SJiange Zhao 		xgpu_nv_mailbox_set_irq_funcs(adev);
1281b05b6903SJiange Zhao 	}
1282b05b6903SJiange Zhao 
1283c6b6a421SHawking Zhang 	return 0;
1284c6b6a421SHawking Zhang }
1285c6b6a421SHawking Zhang 
1286c6b6a421SHawking Zhang static int nv_common_late_init(void *handle)
1287c6b6a421SHawking Zhang {
1288b05b6903SJiange Zhao 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1289b05b6903SJiange Zhao 
1290ed9d2053SBokun Zhang 	if (amdgpu_sriov_vf(adev)) {
1291b05b6903SJiange Zhao 		xgpu_nv_mailbox_get_irq(adev);
1292ed9d2053SBokun Zhang 		amdgpu_virt_update_sriov_video_codec(adev,
1293ed9d2053SBokun Zhang 				sriov_sc_video_codecs_encode_array, ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
1294ed9d2053SBokun Zhang 				sriov_sc_video_codecs_decode_array, ARRAY_SIZE(sriov_sc_video_codecs_decode_array));
1295ed9d2053SBokun Zhang 	}
1296b05b6903SJiange Zhao 
1297c6b6a421SHawking Zhang 	return 0;
1298c6b6a421SHawking Zhang }
1299c6b6a421SHawking Zhang 
1300c6b6a421SHawking Zhang static int nv_common_sw_init(void *handle)
1301c6b6a421SHawking Zhang {
1302b05b6903SJiange Zhao 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1303b05b6903SJiange Zhao 
1304b05b6903SJiange Zhao 	if (amdgpu_sriov_vf(adev))
1305b05b6903SJiange Zhao 		xgpu_nv_mailbox_add_irq_id(adev);
1306b05b6903SJiange Zhao 
1307c6b6a421SHawking Zhang 	return 0;
1308c6b6a421SHawking Zhang }
1309c6b6a421SHawking Zhang 
1310c6b6a421SHawking Zhang static int nv_common_sw_fini(void *handle)
1311c6b6a421SHawking Zhang {
1312c6b6a421SHawking Zhang 	return 0;
1313c6b6a421SHawking Zhang }
1314c6b6a421SHawking Zhang 
1315c6b6a421SHawking Zhang static int nv_common_hw_init(void *handle)
1316c6b6a421SHawking Zhang {
1317c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1318c6b6a421SHawking Zhang 
13195a5da8aeSEvan Quan 	if (adev->nbio.funcs->apply_lc_spc_mode_wa)
13205a5da8aeSEvan Quan 		adev->nbio.funcs->apply_lc_spc_mode_wa(adev);
13215a5da8aeSEvan Quan 
1322adcf949eSEvan Quan 	if (adev->nbio.funcs->apply_l1_link_width_reconfig_wa)
1323adcf949eSEvan Quan 		adev->nbio.funcs->apply_l1_link_width_reconfig_wa(adev);
1324adcf949eSEvan Quan 
1325c6b6a421SHawking Zhang 	/* enable pcie gen2/3 link */
1326c6b6a421SHawking Zhang 	nv_pcie_gen3_enable(adev);
1327c6b6a421SHawking Zhang 	/* enable aspm */
1328c6b6a421SHawking Zhang 	nv_program_aspm(adev);
1329c6b6a421SHawking Zhang 	/* setup nbio registers */
1330bebc0762SHawking Zhang 	adev->nbio.funcs->init_registers(adev);
1331923c087aSYong Zhao 	/* remap HDP registers to a hole in mmio space,
1332923c087aSYong Zhao 	 * for the purpose of expose those registers
1333923c087aSYong Zhao 	 * to process space
1334923c087aSYong Zhao 	 */
1335923c087aSYong Zhao 	if (adev->nbio.funcs->remap_hdp_registers)
1336923c087aSYong Zhao 		adev->nbio.funcs->remap_hdp_registers(adev);
1337c6b6a421SHawking Zhang 	/* enable the doorbell aperture */
1338c6b6a421SHawking Zhang 	nv_enable_doorbell_aperture(adev, true);
1339c6b6a421SHawking Zhang 
1340c6b6a421SHawking Zhang 	return 0;
1341c6b6a421SHawking Zhang }
1342c6b6a421SHawking Zhang 
1343c6b6a421SHawking Zhang static int nv_common_hw_fini(void *handle)
1344c6b6a421SHawking Zhang {
1345c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1346c6b6a421SHawking Zhang 
1347c6b6a421SHawking Zhang 	/* disable the doorbell aperture */
1348c6b6a421SHawking Zhang 	nv_enable_doorbell_aperture(adev, false);
1349c6b6a421SHawking Zhang 
1350c6b6a421SHawking Zhang 	return 0;
1351c6b6a421SHawking Zhang }
1352c6b6a421SHawking Zhang 
1353c6b6a421SHawking Zhang static int nv_common_suspend(void *handle)
1354c6b6a421SHawking Zhang {
1355c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1356c6b6a421SHawking Zhang 
1357c6b6a421SHawking Zhang 	return nv_common_hw_fini(adev);
1358c6b6a421SHawking Zhang }
1359c6b6a421SHawking Zhang 
1360c6b6a421SHawking Zhang static int nv_common_resume(void *handle)
1361c6b6a421SHawking Zhang {
1362c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1363c6b6a421SHawking Zhang 
1364c6b6a421SHawking Zhang 	return nv_common_hw_init(adev);
1365c6b6a421SHawking Zhang }
1366c6b6a421SHawking Zhang 
1367c6b6a421SHawking Zhang static bool nv_common_is_idle(void *handle)
1368c6b6a421SHawking Zhang {
1369c6b6a421SHawking Zhang 	return true;
1370c6b6a421SHawking Zhang }
1371c6b6a421SHawking Zhang 
1372c6b6a421SHawking Zhang static int nv_common_wait_for_idle(void *handle)
1373c6b6a421SHawking Zhang {
1374c6b6a421SHawking Zhang 	return 0;
1375c6b6a421SHawking Zhang }
1376c6b6a421SHawking Zhang 
1377c6b6a421SHawking Zhang static int nv_common_soft_reset(void *handle)
1378c6b6a421SHawking Zhang {
1379c6b6a421SHawking Zhang 	return 0;
1380c6b6a421SHawking Zhang }
1381c6b6a421SHawking Zhang 
1382c6b6a421SHawking Zhang static int nv_common_set_clockgating_state(void *handle,
1383c6b6a421SHawking Zhang 					   enum amd_clockgating_state state)
1384c6b6a421SHawking Zhang {
1385c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1386c6b6a421SHawking Zhang 
1387c6b6a421SHawking Zhang 	if (amdgpu_sriov_vf(adev))
1388c6b6a421SHawking Zhang 		return 0;
1389c6b6a421SHawking Zhang 
1390c6b6a421SHawking Zhang 	switch (adev->asic_type) {
1391c6b6a421SHawking Zhang 	case CHIP_NAVI10:
13925e71e011SXiaojie Yuan 	case CHIP_NAVI14:
13937e17e58bSXiaojie Yuan 	case CHIP_NAVI12:
1394117910edSLikun Gao 	case CHIP_SIENNA_CICHLID:
1395543aa259SJiansong Chen 	case CHIP_NAVY_FLOUNDER:
1396550c58e0STao Zhou 	case CHIP_DIMGREY_CAVEFISH:
13978573035aSChengming Gui 	case CHIP_BEIGE_GOBY:
1398bebc0762SHawking Zhang 		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1399a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
1400bebc0762SHawking Zhang 		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1401a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
1402bf087285SLikun Gao 		adev->hdp.funcs->update_clock_gating(adev,
1403a9d4fe2fSNirmoy Das 				state == AMD_CG_STATE_GATE);
14041001f2a1SLikun Gao 		adev->smuio.funcs->update_rom_clock_gating(adev,
14051001f2a1SLikun Gao 				state == AMD_CG_STATE_GATE);
1406c6b6a421SHawking Zhang 		break;
1407c6b6a421SHawking Zhang 	default:
1408c6b6a421SHawking Zhang 		break;
1409c6b6a421SHawking Zhang 	}
1410c6b6a421SHawking Zhang 	return 0;
1411c6b6a421SHawking Zhang }
1412c6b6a421SHawking Zhang 
1413c6b6a421SHawking Zhang static int nv_common_set_powergating_state(void *handle,
1414c6b6a421SHawking Zhang 					   enum amd_powergating_state state)
1415c6b6a421SHawking Zhang {
1416c6b6a421SHawking Zhang 	/* TODO */
1417c6b6a421SHawking Zhang 	return 0;
1418c6b6a421SHawking Zhang }
1419c6b6a421SHawking Zhang 
1420c6b6a421SHawking Zhang static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1421c6b6a421SHawking Zhang {
1422c6b6a421SHawking Zhang 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1423c6b6a421SHawking Zhang 
1424c6b6a421SHawking Zhang 	if (amdgpu_sriov_vf(adev))
1425c6b6a421SHawking Zhang 		*flags = 0;
1426c6b6a421SHawking Zhang 
1427bebc0762SHawking Zhang 	adev->nbio.funcs->get_clockgating_state(adev, flags);
1428c6b6a421SHawking Zhang 
1429bf087285SLikun Gao 	adev->hdp.funcs->get_clock_gating_state(adev, flags);
1430c6b6a421SHawking Zhang 
14311001f2a1SLikun Gao 	adev->smuio.funcs->get_clock_gating_state(adev, flags);
14321001f2a1SLikun Gao 
1433c6b6a421SHawking Zhang 	return;
1434c6b6a421SHawking Zhang }
1435c6b6a421SHawking Zhang 
1436c6b6a421SHawking Zhang static const struct amd_ip_funcs nv_common_ip_funcs = {
1437c6b6a421SHawking Zhang 	.name = "nv_common",
1438c6b6a421SHawking Zhang 	.early_init = nv_common_early_init,
1439c6b6a421SHawking Zhang 	.late_init = nv_common_late_init,
1440c6b6a421SHawking Zhang 	.sw_init = nv_common_sw_init,
1441c6b6a421SHawking Zhang 	.sw_fini = nv_common_sw_fini,
1442c6b6a421SHawking Zhang 	.hw_init = nv_common_hw_init,
1443c6b6a421SHawking Zhang 	.hw_fini = nv_common_hw_fini,
1444c6b6a421SHawking Zhang 	.suspend = nv_common_suspend,
1445c6b6a421SHawking Zhang 	.resume = nv_common_resume,
1446c6b6a421SHawking Zhang 	.is_idle = nv_common_is_idle,
1447c6b6a421SHawking Zhang 	.wait_for_idle = nv_common_wait_for_idle,
1448c6b6a421SHawking Zhang 	.soft_reset = nv_common_soft_reset,
1449c6b6a421SHawking Zhang 	.set_clockgating_state = nv_common_set_clockgating_state,
1450c6b6a421SHawking Zhang 	.set_powergating_state = nv_common_set_powergating_state,
1451c6b6a421SHawking Zhang 	.get_clockgating_state = nv_common_get_clockgating_state,
1452c6b6a421SHawking Zhang };
1453