Linux Audio

Check our new training course

Loading...
v6.13.7
   1/*
   2 * Copyright 2019 Advanced Micro Devices, Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 */
  23#include <linux/firmware.h>
  24#include <linux/slab.h>
  25#include <linux/module.h>
  26#include <linux/pci.h>
  27
  28#include <drm/amdgpu_drm.h>
  29
  30#include "amdgpu.h"
  31#include "amdgpu_atombios.h"
  32#include "amdgpu_ih.h"
  33#include "amdgpu_uvd.h"
  34#include "amdgpu_vce.h"
  35#include "amdgpu_ucode.h"
  36#include "amdgpu_psp.h"
  37#include "atom.h"
  38#include "amd_pcie.h"
  39
  40#include "gc/gc_10_1_0_offset.h"
  41#include "gc/gc_10_1_0_sh_mask.h"
  42#include "mp/mp_11_0_offset.h"
  43
  44#include "soc15.h"
  45#include "soc15_common.h"
  46#include "gmc_v10_0.h"
  47#include "gfxhub_v2_0.h"
  48#include "mmhub_v2_0.h"
  49#include "nbio_v2_3.h"
  50#include "nbio_v7_2.h"
  51#include "hdp_v5_0.h"
  52#include "nv.h"
  53#include "navi10_ih.h"
  54#include "gfx_v10_0.h"
  55#include "sdma_v5_0.h"
  56#include "sdma_v5_2.h"
  57#include "vcn_v2_0.h"
  58#include "jpeg_v2_0.h"
  59#include "vcn_v3_0.h"
  60#include "jpeg_v3_0.h"
  61#include "amdgpu_vkms.h"
 
  62#include "mxgpu_nv.h"
  63#include "smuio_v11_0.h"
  64#include "smuio_v11_0_6.h"
  65
  66static const struct amd_ip_funcs nv_common_ip_funcs;
  67
  68/* Navi */
  69static const struct amdgpu_video_codec_info nv_video_codecs_encode_array[] = {
  70	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 0)},
  71	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 4096, 0)},
 
  72};
  73
  74static const struct amdgpu_video_codecs nv_video_codecs_encode = {
 
  75	.codec_count = ARRAY_SIZE(nv_video_codecs_encode_array),
  76	.codec_array = nv_video_codecs_encode_array,
  77};
  78
  79/* Navi1x */
  80static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] = {
  81	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
  82	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
  83	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
  84	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
 
  85	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
  86	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
  87	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
  88};
  89
  90static const struct amdgpu_video_codecs nv_video_codecs_decode = {
 
  91	.codec_count = ARRAY_SIZE(nv_video_codecs_decode_array),
  92	.codec_array = nv_video_codecs_decode_array,
  93};
  94
  95/* Sienna Cichlid */
  96static const struct amdgpu_video_codec_info sc_video_codecs_encode_array[] = {
  97	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 0)},
  98	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 0)},
  99};
 100
 101static const struct amdgpu_video_codecs sc_video_codecs_encode = {
 102	.codec_count = ARRAY_SIZE(sc_video_codecs_encode_array),
 103	.codec_array = sc_video_codecs_encode_array,
 104};
 105
 106static const struct amdgpu_video_codec_info sc_video_codecs_decode_array_vcn0[] = {
 107	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
 108	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
 109	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 110	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
 111	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 112	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 16384, 16384, 0)},
 113	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 114	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 115};
 116
 117static const struct amdgpu_video_codec_info sc_video_codecs_decode_array_vcn1[] = {
 118	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
 119	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
 120	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 121	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
 122	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 123	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 16384, 16384, 0)},
 124	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 125};
 126
 127static const struct amdgpu_video_codecs sc_video_codecs_decode_vcn0 = {
 128	.codec_count = ARRAY_SIZE(sc_video_codecs_decode_array_vcn0),
 129	.codec_array = sc_video_codecs_decode_array_vcn0,
 130};
 131
 132static const struct amdgpu_video_codecs sc_video_codecs_decode_vcn1 = {
 133	.codec_count = ARRAY_SIZE(sc_video_codecs_decode_array_vcn1),
 134	.codec_array = sc_video_codecs_decode_array_vcn1,
 135};
 136
 137/* SRIOV Sienna Cichlid, not const since data is controlled by host */
 138static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array[] = {
 139	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 0)},
 140	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 0)},
 
 141};
 142
 143static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array_vcn0[] = {
 144	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
 145	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
 146	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 147	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
 
 148	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 149	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
 150	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 151	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 152};
 153
 154static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array_vcn1[] = {
 155	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
 156	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
 157	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 158	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
 159	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 160	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
 161	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 162};
 163
 164static struct amdgpu_video_codecs sriov_sc_video_codecs_encode = {
 165	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
 166	.codec_array = sriov_sc_video_codecs_encode_array,
 167};
 168
 169static struct amdgpu_video_codecs sriov_sc_video_codecs_decode_vcn0 = {
 170	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array_vcn0),
 171	.codec_array = sriov_sc_video_codecs_decode_array_vcn0,
 172};
 173
 174static struct amdgpu_video_codecs sriov_sc_video_codecs_decode_vcn1 = {
 175	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array_vcn1),
 176	.codec_array = sriov_sc_video_codecs_decode_array_vcn1,
 177};
 178
 179/* Beige Goby*/
 180static const struct amdgpu_video_codec_info bg_video_codecs_decode_array[] = {
 181	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 182	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 183	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 184};
 185
 186static const struct amdgpu_video_codecs bg_video_codecs_decode = {
 187	.codec_count = ARRAY_SIZE(bg_video_codecs_decode_array),
 188	.codec_array = bg_video_codecs_decode_array,
 189};
 190
 191static const struct amdgpu_video_codecs bg_video_codecs_encode = {
 192	.codec_count = 0,
 193	.codec_array = NULL,
 194};
 195
 196/* Yellow Carp*/
 197static const struct amdgpu_video_codec_info yc_video_codecs_decode_array[] = {
 198	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
 199	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 200	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 201	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 16384, 16384, 0)},
 202	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 203};
 204
 205static const struct amdgpu_video_codecs yc_video_codecs_decode = {
 206	.codec_count = ARRAY_SIZE(yc_video_codecs_decode_array),
 207	.codec_array = yc_video_codecs_decode_array,
 208};
 209
 210static int nv_query_video_codecs(struct amdgpu_device *adev, bool encode,
 211				 const struct amdgpu_video_codecs **codecs)
 212{
 213	if (adev->vcn.num_vcn_inst == hweight8(adev->vcn.harvest_config))
 214		return -EINVAL;
 215
 216	switch (amdgpu_ip_version(adev, UVD_HWIP, 0)) {
 217	case IP_VERSION(3, 0, 0):
 218	case IP_VERSION(3, 0, 64):
 219	case IP_VERSION(3, 0, 192):
 220		if (amdgpu_sriov_vf(adev)) {
 221			if (adev->vcn.harvest_config & AMDGPU_VCN_HARVEST_VCN0) {
 222				if (encode)
 223					*codecs = &sriov_sc_video_codecs_encode;
 224				else
 225					*codecs = &sriov_sc_video_codecs_decode_vcn1;
 226			} else {
 227				if (encode)
 228					*codecs = &sriov_sc_video_codecs_encode;
 229				else
 230					*codecs = &sriov_sc_video_codecs_decode_vcn0;
 231			}
 232		} else {
 233			if (adev->vcn.harvest_config & AMDGPU_VCN_HARVEST_VCN0) {
 234				if (encode)
 235					*codecs = &sc_video_codecs_encode;
 236				else
 237					*codecs = &sc_video_codecs_decode_vcn1;
 238			} else {
 239				if (encode)
 240					*codecs = &sc_video_codecs_encode;
 241				else
 242					*codecs = &sc_video_codecs_decode_vcn0;
 243			}
 244		}
 245		return 0;
 246	case IP_VERSION(3, 0, 16):
 247	case IP_VERSION(3, 0, 2):
 
 248		if (encode)
 249			*codecs = &sc_video_codecs_encode;
 250		else
 251			*codecs = &sc_video_codecs_decode_vcn0;
 252		return 0;
 253	case IP_VERSION(3, 1, 1):
 254	case IP_VERSION(3, 1, 2):
 255		if (encode)
 256			*codecs = &sc_video_codecs_encode;
 257		else
 258			*codecs = &yc_video_codecs_decode;
 259		return 0;
 260	case IP_VERSION(3, 0, 33):
 261		if (encode)
 262			*codecs = &bg_video_codecs_encode;
 263		else
 264			*codecs = &bg_video_codecs_decode;
 265		return 0;
 266	case IP_VERSION(2, 0, 0):
 267	case IP_VERSION(2, 0, 2):
 
 268		if (encode)
 269			*codecs = &nv_video_codecs_encode;
 270		else
 271			*codecs = &nv_video_codecs_decode;
 272		return 0;
 273	default:
 274		return -EINVAL;
 275	}
 276}
 277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 278static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
 279{
 280	unsigned long flags, address, data;
 281	u32 r;
 282
 283	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
 284	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
 285
 286	spin_lock_irqsave(&adev->didt_idx_lock, flags);
 287	WREG32(address, (reg));
 288	r = RREG32(data);
 289	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
 290	return r;
 291}
 292
 293static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
 294{
 295	unsigned long flags, address, data;
 296
 297	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
 298	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
 299
 300	spin_lock_irqsave(&adev->didt_idx_lock, flags);
 301	WREG32(address, (reg));
 302	WREG32(data, (v));
 303	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
 304}
 305
 306static u32 nv_get_config_memsize(struct amdgpu_device *adev)
 307{
 308	return adev->nbio.funcs->get_memsize(adev);
 309}
 310
 311static u32 nv_get_xclk(struct amdgpu_device *adev)
 312{
 313	return adev->clock.spll.reference_freq;
 314}
 315
 316
 317void nv_grbm_select(struct amdgpu_device *adev,
 318		     u32 me, u32 pipe, u32 queue, u32 vmid)
 319{
 320	u32 grbm_gfx_cntl = 0;
 321	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
 322	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
 323	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
 324	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
 325
 326	WREG32_SOC15(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
 327}
 328
 
 
 
 
 
 329static bool nv_read_disabled_bios(struct amdgpu_device *adev)
 330{
 331	/* todo */
 332	return false;
 333}
 334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 335static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
 336	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
 337	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
 338	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
 339	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
 340	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
 341	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
 342	{ SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
 343	{ SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
 344	{ SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
 345	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
 346	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
 347	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
 348	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
 349	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
 350	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
 351	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
 352	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
 353	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
 354	{ SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
 355};
 356
 357static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
 358					 u32 sh_num, u32 reg_offset)
 359{
 360	uint32_t val;
 361
 362	mutex_lock(&adev->grbm_idx_mutex);
 363	if (se_num != 0xffffffff || sh_num != 0xffffffff)
 364		amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff, 0);
 365
 366	val = RREG32(reg_offset);
 367
 368	if (se_num != 0xffffffff || sh_num != 0xffffffff)
 369		amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
 370	mutex_unlock(&adev->grbm_idx_mutex);
 371	return val;
 372}
 373
 374static uint32_t nv_get_register_value(struct amdgpu_device *adev,
 375				      bool indexed, u32 se_num,
 376				      u32 sh_num, u32 reg_offset)
 377{
 378	if (indexed) {
 379		return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
 380	} else {
 381		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
 382			return adev->gfx.config.gb_addr_config;
 383		return RREG32(reg_offset);
 384	}
 385}
 386
 387static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
 388			    u32 sh_num, u32 reg_offset, u32 *value)
 389{
 390	uint32_t i;
 391	struct soc15_allowed_register_entry  *en;
 392
 393	*value = 0;
 394	for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
 395		en = &nv_allowed_read_registers[i];
 396		if (!adev->reg_offset[en->hwip][en->inst])
 397			continue;
 398		else if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
 399					+ en->reg_offset))
 400			continue;
 401
 402		*value = nv_get_register_value(adev,
 403					       nv_allowed_read_registers[i].grbm_indexed,
 404					       se_num, sh_num, reg_offset);
 405		return 0;
 406	}
 407	return -EINVAL;
 408}
 409
 410static int nv_asic_mode2_reset(struct amdgpu_device *adev)
 411{
 412	u32 i;
 413	int ret = 0;
 414
 415	amdgpu_atombios_scratch_regs_engine_hung(adev, true);
 416
 417	/* disable BM */
 418	pci_clear_master(adev->pdev);
 419
 420	amdgpu_device_cache_pci_state(adev->pdev);
 421
 422	ret = amdgpu_dpm_mode2_reset(adev);
 423	if (ret)
 424		dev_err(adev->dev, "GPU mode2 reset failed\n");
 425
 426	amdgpu_device_load_pci_state(adev->pdev);
 427
 428	/* wait for asic to come out of reset */
 429	for (i = 0; i < adev->usec_timeout; i++) {
 430		u32 memsize = adev->nbio.funcs->get_memsize(adev);
 431
 432		if (memsize != 0xffffffff)
 433			break;
 434		udelay(1);
 435	}
 436
 437	amdgpu_atombios_scratch_regs_engine_hung(adev, false);
 438
 439	return ret;
 440}
 441
 442static enum amd_reset_method
 443nv_asic_reset_method(struct amdgpu_device *adev)
 444{
 445	if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
 446	    amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
 447	    amdgpu_reset_method == AMD_RESET_METHOD_BACO ||
 448	    amdgpu_reset_method == AMD_RESET_METHOD_PCI)
 449		return amdgpu_reset_method;
 450
 451	if (amdgpu_reset_method != -1)
 452		dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
 453				  amdgpu_reset_method);
 454
 455	switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
 456	case IP_VERSION(11, 5, 0):
 457	case IP_VERSION(13, 0, 1):
 458	case IP_VERSION(13, 0, 3):
 459	case IP_VERSION(13, 0, 5):
 460	case IP_VERSION(13, 0, 8):
 461		return AMD_RESET_METHOD_MODE2;
 462	case IP_VERSION(11, 0, 7):
 463	case IP_VERSION(11, 0, 11):
 464	case IP_VERSION(11, 0, 12):
 465	case IP_VERSION(11, 0, 13):
 466		return AMD_RESET_METHOD_MODE1;
 467	default:
 468		if (amdgpu_dpm_is_baco_supported(adev))
 469			return AMD_RESET_METHOD_BACO;
 470		else
 471			return AMD_RESET_METHOD_MODE1;
 472	}
 473}
 474
 475static int nv_asic_reset(struct amdgpu_device *adev)
 476{
 477	int ret = 0;
 478
 479	switch (nv_asic_reset_method(adev)) {
 480	case AMD_RESET_METHOD_PCI:
 481		dev_info(adev->dev, "PCI reset\n");
 482		ret = amdgpu_device_pci_reset(adev);
 483		break;
 484	case AMD_RESET_METHOD_BACO:
 485		dev_info(adev->dev, "BACO reset\n");
 486		ret = amdgpu_dpm_baco_reset(adev);
 487		break;
 488	case AMD_RESET_METHOD_MODE2:
 489		dev_info(adev->dev, "MODE2 reset\n");
 490		ret = nv_asic_mode2_reset(adev);
 491		break;
 492	default:
 493		dev_info(adev->dev, "MODE1 reset\n");
 494		ret = amdgpu_device_mode1_reset(adev);
 495		break;
 496	}
 497
 498	return ret;
 499}
 500
 501static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
 502{
 503	/* todo */
 504	return 0;
 505}
 506
 507static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
 508{
 509	/* todo */
 510	return 0;
 511}
 512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 513static void nv_program_aspm(struct amdgpu_device *adev)
 514{
 515	if (!amdgpu_device_should_use_aspm(adev))
 516		return;
 517
 518	if (adev->nbio.funcs->program_aspm)
 
 519		adev->nbio.funcs->program_aspm(adev);
 520
 521}
 522
 523const struct amdgpu_ip_block_version nv_common_ip_block = {
 
 
 
 
 
 
 
 
 524	.type = AMD_IP_BLOCK_TYPE_COMMON,
 525	.major = 1,
 526	.minor = 0,
 527	.rev = 0,
 528	.funcs = &nv_common_ip_funcs,
 529};
 530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 531void nv_set_virt_ops(struct amdgpu_device *adev)
 532{
 533	adev->virt.ops = &xgpu_nv_virt_ops;
 534}
 535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 536static bool nv_need_full_reset(struct amdgpu_device *adev)
 537{
 538	return true;
 539}
 540
 541static bool nv_need_reset_on_init(struct amdgpu_device *adev)
 542{
 543	u32 sol_reg;
 544
 545	if (adev->flags & AMD_IS_APU)
 546		return false;
 547
 548	/* Check sOS sign of life register to confirm sys driver and sOS
 549	 * are already been loaded.
 550	 */
 551	sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
 552	if (sol_reg)
 553		return true;
 554
 555	return false;
 556}
 557
 
 
 
 
 
 
 
 
 
 
 558static void nv_init_doorbell_index(struct amdgpu_device *adev)
 559{
 560	adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
 561	adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
 562	adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
 563	adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
 564	adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
 565	adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
 566	adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
 567	adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
 568	adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
 569	adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
 570	adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
 571	adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
 572	adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
 573	adev->doorbell_index.gfx_userqueue_start =
 574		AMDGPU_NAVI10_DOORBELL_GFX_USERQUEUE_START;
 575	adev->doorbell_index.gfx_userqueue_end =
 576		AMDGPU_NAVI10_DOORBELL_GFX_USERQUEUE_END;
 577	adev->doorbell_index.mes_ring0 = AMDGPU_NAVI10_DOORBELL_MES_RING0;
 578	adev->doorbell_index.mes_ring1 = AMDGPU_NAVI10_DOORBELL_MES_RING1;
 579	adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
 580	adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
 581	adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
 582	adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
 583	adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
 584	adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
 585	adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
 586	adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
 587	adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
 588	adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
 589	adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
 590
 591	adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
 592	adev->doorbell_index.sdma_doorbell_range = 20;
 593}
 594
 595static void nv_pre_asic_init(struct amdgpu_device *adev)
 596{
 597}
 598
 599static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
 600				       bool enter)
 601{
 602	if (enter)
 603		amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 604	else
 605		amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
 606
 607	if (adev->gfx.funcs->update_perfmon_mgcg)
 608		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
 609
 610	if (adev->nbio.funcs->enable_aspm &&
 611	    amdgpu_device_should_use_aspm(adev))
 612		adev->nbio.funcs->enable_aspm(adev, !enter);
 613
 614	return 0;
 615}
 616
 617static const struct amdgpu_asic_funcs nv_asic_funcs = {
 
 618	.read_disabled_bios = &nv_read_disabled_bios,
 619	.read_bios_from_rom = &amdgpu_soc15_read_bios_from_rom,
 620	.read_register = &nv_read_register,
 621	.reset = &nv_asic_reset,
 622	.reset_method = &nv_asic_reset_method,
 
 623	.get_xclk = &nv_get_xclk,
 624	.set_uvd_clocks = &nv_set_uvd_clocks,
 625	.set_vce_clocks = &nv_set_vce_clocks,
 626	.get_config_memsize = &nv_get_config_memsize,
 627	.init_doorbell_index = &nv_init_doorbell_index,
 628	.need_full_reset = &nv_need_full_reset,
 629	.need_reset_on_init = &nv_need_reset_on_init,
 630	.get_pcie_replay_count = &amdgpu_nbio_get_pcie_replay_count,
 631	.supports_baco = &amdgpu_dpm_is_baco_supported,
 632	.pre_asic_init = &nv_pre_asic_init,
 633	.update_umd_stable_pstate = &nv_update_umd_stable_pstate,
 634	.query_video_codecs = &nv_query_video_codecs,
 635};
 636
 637static int nv_common_early_init(struct amdgpu_ip_block *ip_block)
 638{
 639	struct amdgpu_device *adev = ip_block->adev;
 
 640
 641	adev->nbio.funcs->set_reg_remap(adev);
 
 642	adev->smc_rreg = NULL;
 643	adev->smc_wreg = NULL;
 644	adev->pcie_rreg = &amdgpu_device_indirect_rreg;
 645	adev->pcie_wreg = &amdgpu_device_indirect_wreg;
 646	adev->pcie_rreg64 = &amdgpu_device_indirect_rreg64;
 647	adev->pcie_wreg64 = &amdgpu_device_indirect_wreg64;
 648	adev->pciep_rreg = amdgpu_device_pcie_port_rreg;
 649	adev->pciep_wreg = amdgpu_device_pcie_port_wreg;
 650
 651	/* TODO: will add them during VCN v2 implementation */
 652	adev->uvd_ctx_rreg = NULL;
 653	adev->uvd_ctx_wreg = NULL;
 654
 655	adev->didt_rreg = &nv_didt_rreg;
 656	adev->didt_wreg = &nv_didt_wreg;
 657
 658	adev->asic_funcs = &nv_asic_funcs;
 659
 660	adev->rev_id = amdgpu_device_get_rev_id(adev);
 661	adev->external_rev_id = 0xff;
 662	/* TODO: split the GC and PG flags based on the relevant IP version for which
 663	 * they are relevant.
 664	 */
 665	switch (amdgpu_ip_version(adev, GC_HWIP, 0)) {
 666	case IP_VERSION(10, 1, 10):
 667		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 668			AMD_CG_SUPPORT_GFX_CGCG |
 669			AMD_CG_SUPPORT_IH_CG |
 670			AMD_CG_SUPPORT_HDP_MGCG |
 671			AMD_CG_SUPPORT_HDP_LS |
 672			AMD_CG_SUPPORT_SDMA_MGCG |
 673			AMD_CG_SUPPORT_SDMA_LS |
 674			AMD_CG_SUPPORT_MC_MGCG |
 675			AMD_CG_SUPPORT_MC_LS |
 676			AMD_CG_SUPPORT_ATHUB_MGCG |
 677			AMD_CG_SUPPORT_ATHUB_LS |
 678			AMD_CG_SUPPORT_VCN_MGCG |
 679			AMD_CG_SUPPORT_JPEG_MGCG |
 680			AMD_CG_SUPPORT_BIF_MGCG |
 681			AMD_CG_SUPPORT_BIF_LS;
 682		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 683			AMD_PG_SUPPORT_VCN_DPG |
 684			AMD_PG_SUPPORT_JPEG |
 685			AMD_PG_SUPPORT_ATHUB;
 686		adev->external_rev_id = adev->rev_id + 0x1;
 687		break;
 688	case IP_VERSION(10, 1, 1):
 689		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 690			AMD_CG_SUPPORT_GFX_CGCG |
 691			AMD_CG_SUPPORT_IH_CG |
 692			AMD_CG_SUPPORT_HDP_MGCG |
 693			AMD_CG_SUPPORT_HDP_LS |
 694			AMD_CG_SUPPORT_SDMA_MGCG |
 695			AMD_CG_SUPPORT_SDMA_LS |
 696			AMD_CG_SUPPORT_MC_MGCG |
 697			AMD_CG_SUPPORT_MC_LS |
 698			AMD_CG_SUPPORT_ATHUB_MGCG |
 699			AMD_CG_SUPPORT_ATHUB_LS |
 700			AMD_CG_SUPPORT_VCN_MGCG |
 701			AMD_CG_SUPPORT_JPEG_MGCG |
 702			AMD_CG_SUPPORT_BIF_MGCG |
 703			AMD_CG_SUPPORT_BIF_LS;
 704		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 705			AMD_PG_SUPPORT_JPEG |
 706			AMD_PG_SUPPORT_VCN_DPG;
 707		adev->external_rev_id = adev->rev_id + 20;
 708		break;
 709	case IP_VERSION(10, 1, 2):
 710		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 711			AMD_CG_SUPPORT_GFX_MGLS |
 712			AMD_CG_SUPPORT_GFX_CGCG |
 713			AMD_CG_SUPPORT_GFX_CP_LS |
 714			AMD_CG_SUPPORT_GFX_RLC_LS |
 715			AMD_CG_SUPPORT_IH_CG |
 716			AMD_CG_SUPPORT_HDP_MGCG |
 717			AMD_CG_SUPPORT_HDP_LS |
 718			AMD_CG_SUPPORT_SDMA_MGCG |
 719			AMD_CG_SUPPORT_SDMA_LS |
 720			AMD_CG_SUPPORT_MC_MGCG |
 721			AMD_CG_SUPPORT_MC_LS |
 722			AMD_CG_SUPPORT_ATHUB_MGCG |
 723			AMD_CG_SUPPORT_ATHUB_LS |
 724			AMD_CG_SUPPORT_VCN_MGCG |
 725			AMD_CG_SUPPORT_JPEG_MGCG;
 726		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 727			AMD_PG_SUPPORT_VCN_DPG |
 728			AMD_PG_SUPPORT_JPEG |
 729			AMD_PG_SUPPORT_ATHUB;
 730		/* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
 731		 * as a consequence, the rev_id and external_rev_id are wrong.
 732		 * workaround it by hardcoding rev_id to 0 (default value).
 733		 */
 734		if (amdgpu_sriov_vf(adev))
 735			adev->rev_id = 0;
 736		adev->external_rev_id = adev->rev_id + 0xa;
 737		break;
 738	case IP_VERSION(10, 3, 0):
 739		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 740			AMD_CG_SUPPORT_GFX_CGCG |
 741			AMD_CG_SUPPORT_GFX_CGLS |
 742			AMD_CG_SUPPORT_GFX_3D_CGCG |
 743			AMD_CG_SUPPORT_MC_MGCG |
 744			AMD_CG_SUPPORT_VCN_MGCG |
 745			AMD_CG_SUPPORT_JPEG_MGCG |
 746			AMD_CG_SUPPORT_HDP_MGCG |
 747			AMD_CG_SUPPORT_HDP_LS |
 748			AMD_CG_SUPPORT_IH_CG |
 749			AMD_CG_SUPPORT_MC_LS;
 750		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 751			AMD_PG_SUPPORT_VCN_DPG |
 752			AMD_PG_SUPPORT_JPEG |
 753			AMD_PG_SUPPORT_ATHUB |
 754			AMD_PG_SUPPORT_MMHUB;
 755		if (amdgpu_sriov_vf(adev)) {
 756			/* hypervisor control CG and PG enablement */
 757			adev->cg_flags = 0;
 758			adev->pg_flags = 0;
 759		}
 760		adev->external_rev_id = adev->rev_id + 0x28;
 761		break;
 762	case IP_VERSION(10, 3, 2):
 763		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 764			AMD_CG_SUPPORT_GFX_CGCG |
 765			AMD_CG_SUPPORT_GFX_CGLS |
 766			AMD_CG_SUPPORT_GFX_3D_CGCG |
 767			AMD_CG_SUPPORT_VCN_MGCG |
 768			AMD_CG_SUPPORT_JPEG_MGCG |
 769			AMD_CG_SUPPORT_MC_MGCG |
 770			AMD_CG_SUPPORT_MC_LS |
 771			AMD_CG_SUPPORT_HDP_MGCG |
 772			AMD_CG_SUPPORT_HDP_LS |
 773			AMD_CG_SUPPORT_IH_CG;
 774		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 775			AMD_PG_SUPPORT_VCN_DPG |
 776			AMD_PG_SUPPORT_JPEG |
 777			AMD_PG_SUPPORT_ATHUB |
 778			AMD_PG_SUPPORT_MMHUB;
 779		adev->external_rev_id = adev->rev_id + 0x32;
 780		break;
 781	case IP_VERSION(10, 3, 1):
 
 782		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 783			AMD_CG_SUPPORT_GFX_MGLS |
 784			AMD_CG_SUPPORT_GFX_CP_LS |
 785			AMD_CG_SUPPORT_GFX_RLC_LS |
 786			AMD_CG_SUPPORT_GFX_CGCG |
 787			AMD_CG_SUPPORT_GFX_CGLS |
 788			AMD_CG_SUPPORT_GFX_3D_CGCG |
 789			AMD_CG_SUPPORT_GFX_3D_CGLS |
 790			AMD_CG_SUPPORT_MC_MGCG |
 791			AMD_CG_SUPPORT_MC_LS |
 792			AMD_CG_SUPPORT_GFX_FGCG |
 793			AMD_CG_SUPPORT_VCN_MGCG |
 794			AMD_CG_SUPPORT_SDMA_MGCG |
 795			AMD_CG_SUPPORT_SDMA_LS |
 796			AMD_CG_SUPPORT_JPEG_MGCG;
 797		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
 798			AMD_PG_SUPPORT_VCN |
 799			AMD_PG_SUPPORT_VCN_DPG |
 800			AMD_PG_SUPPORT_JPEG;
 801		if (adev->apu_flags & AMD_APU_IS_VANGOGH)
 802			adev->external_rev_id = adev->rev_id + 0x01;
 803		break;
 804	case IP_VERSION(10, 3, 4):
 805		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 806			AMD_CG_SUPPORT_GFX_CGCG |
 807			AMD_CG_SUPPORT_GFX_CGLS |
 808			AMD_CG_SUPPORT_GFX_3D_CGCG |
 809			AMD_CG_SUPPORT_VCN_MGCG |
 810			AMD_CG_SUPPORT_JPEG_MGCG |
 811			AMD_CG_SUPPORT_MC_MGCG |
 812			AMD_CG_SUPPORT_MC_LS |
 813			AMD_CG_SUPPORT_HDP_MGCG |
 814			AMD_CG_SUPPORT_HDP_LS |
 815			AMD_CG_SUPPORT_IH_CG;
 816		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 817			AMD_PG_SUPPORT_VCN_DPG |
 818			AMD_PG_SUPPORT_JPEG |
 819			AMD_PG_SUPPORT_ATHUB |
 820			AMD_PG_SUPPORT_MMHUB;
 821		adev->external_rev_id = adev->rev_id + 0x3c;
 822		break;
 823	case IP_VERSION(10, 3, 5):
 824		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 825			AMD_CG_SUPPORT_GFX_CGCG |
 826			AMD_CG_SUPPORT_GFX_CGLS |
 827			AMD_CG_SUPPORT_GFX_3D_CGCG |
 828			AMD_CG_SUPPORT_MC_MGCG |
 829			AMD_CG_SUPPORT_MC_LS |
 830			AMD_CG_SUPPORT_HDP_MGCG |
 831			AMD_CG_SUPPORT_HDP_LS |
 832			AMD_CG_SUPPORT_IH_CG |
 833			AMD_CG_SUPPORT_VCN_MGCG;
 834		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 835			AMD_PG_SUPPORT_VCN_DPG |
 836			AMD_PG_SUPPORT_ATHUB |
 837			AMD_PG_SUPPORT_MMHUB;
 838		adev->external_rev_id = adev->rev_id + 0x46;
 839		break;
 840	case IP_VERSION(10, 3, 3):
 841		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 842			AMD_CG_SUPPORT_GFX_MGLS |
 843			AMD_CG_SUPPORT_GFX_CGCG |
 844			AMD_CG_SUPPORT_GFX_CGLS |
 845			AMD_CG_SUPPORT_GFX_3D_CGCG |
 846			AMD_CG_SUPPORT_GFX_3D_CGLS |
 847			AMD_CG_SUPPORT_GFX_RLC_LS |
 848			AMD_CG_SUPPORT_GFX_CP_LS |
 849			AMD_CG_SUPPORT_GFX_FGCG |
 850			AMD_CG_SUPPORT_MC_MGCG |
 851			AMD_CG_SUPPORT_MC_LS |
 852			AMD_CG_SUPPORT_SDMA_LS |
 853			AMD_CG_SUPPORT_HDP_MGCG |
 854			AMD_CG_SUPPORT_HDP_LS |
 855			AMD_CG_SUPPORT_ATHUB_MGCG |
 856			AMD_CG_SUPPORT_ATHUB_LS |
 857			AMD_CG_SUPPORT_IH_CG |
 858			AMD_CG_SUPPORT_VCN_MGCG |
 859			AMD_CG_SUPPORT_JPEG_MGCG |
 860			AMD_CG_SUPPORT_SDMA_MGCG;
 861		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
 862			AMD_PG_SUPPORT_VCN |
 863			AMD_PG_SUPPORT_VCN_DPG |
 864			AMD_PG_SUPPORT_JPEG;
 865		if (adev->pdev->device == 0x1681)
 866			adev->external_rev_id = 0x20;
 867		else
 868			adev->external_rev_id = adev->rev_id + 0x01;
 869		break;
 870	case IP_VERSION(10, 1, 3):
 871	case IP_VERSION(10, 1, 4):
 872		adev->cg_flags = 0;
 873		adev->pg_flags = 0;
 874		adev->external_rev_id = adev->rev_id + 0x82;
 875		break;
 876	case IP_VERSION(10, 3, 6):
 877		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
 878			AMD_CG_SUPPORT_GFX_MGLS |
 879			AMD_CG_SUPPORT_GFX_CGCG |
 880			AMD_CG_SUPPORT_GFX_CGLS |
 881			AMD_CG_SUPPORT_GFX_3D_CGCG |
 882			AMD_CG_SUPPORT_GFX_3D_CGLS |
 883			AMD_CG_SUPPORT_GFX_RLC_LS |
 884			AMD_CG_SUPPORT_GFX_CP_LS |
 885			AMD_CG_SUPPORT_GFX_FGCG |
 886			AMD_CG_SUPPORT_MC_MGCG |
 887			AMD_CG_SUPPORT_MC_LS |
 888			AMD_CG_SUPPORT_SDMA_LS |
 889			AMD_CG_SUPPORT_HDP_MGCG |
 890			AMD_CG_SUPPORT_HDP_LS |
 891			AMD_CG_SUPPORT_ATHUB_MGCG |
 892			AMD_CG_SUPPORT_ATHUB_LS |
 893			AMD_CG_SUPPORT_IH_CG |
 894			AMD_CG_SUPPORT_VCN_MGCG |
 895			AMD_CG_SUPPORT_JPEG_MGCG;
 896		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
 897			AMD_PG_SUPPORT_VCN |
 898			AMD_PG_SUPPORT_VCN_DPG |
 899			AMD_PG_SUPPORT_JPEG;
 900		adev->external_rev_id = adev->rev_id + 0x01;
 901		break;
 902	case IP_VERSION(10, 3, 7):
 903		adev->cg_flags =  AMD_CG_SUPPORT_GFX_MGCG |
 904			AMD_CG_SUPPORT_GFX_MGLS |
 905			AMD_CG_SUPPORT_GFX_CGCG |
 906			AMD_CG_SUPPORT_GFX_CGLS |
 907			AMD_CG_SUPPORT_GFX_3D_CGCG |
 908			AMD_CG_SUPPORT_GFX_3D_CGLS |
 909			AMD_CG_SUPPORT_GFX_RLC_LS |
 910			AMD_CG_SUPPORT_GFX_CP_LS |
 911			AMD_CG_SUPPORT_GFX_FGCG |
 912			AMD_CG_SUPPORT_MC_MGCG |
 913			AMD_CG_SUPPORT_MC_LS |
 914			AMD_CG_SUPPORT_SDMA_LS |
 915			AMD_CG_SUPPORT_HDP_MGCG |
 916			AMD_CG_SUPPORT_HDP_LS |
 917			AMD_CG_SUPPORT_ATHUB_MGCG |
 918			AMD_CG_SUPPORT_ATHUB_LS |
 919			AMD_CG_SUPPORT_IH_CG |
 920			AMD_CG_SUPPORT_VCN_MGCG |
 921			AMD_CG_SUPPORT_JPEG_MGCG |
 922			AMD_CG_SUPPORT_SDMA_MGCG;
 923		adev->pg_flags = AMD_PG_SUPPORT_VCN |
 924			AMD_PG_SUPPORT_VCN_DPG |
 925			AMD_PG_SUPPORT_JPEG |
 926			AMD_PG_SUPPORT_GFX_PG;
 927		adev->external_rev_id = adev->rev_id + 0x01;
 928		break;
 929	default:
 930		/* FIXME: not supported yet */
 931		return -EINVAL;
 932	}
 933
 934	if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
 935		adev->pg_flags &= ~(AMD_PG_SUPPORT_VCN |
 936				    AMD_PG_SUPPORT_VCN_DPG |
 937				    AMD_PG_SUPPORT_JPEG);
 938
 939	if (amdgpu_sriov_vf(adev)) {
 940		amdgpu_virt_init_setting(adev);
 941		xgpu_nv_mailbox_set_irq_funcs(adev);
 942	}
 943
 944	return 0;
 945}
 946
 947static int nv_common_late_init(struct amdgpu_ip_block *ip_block)
 948{
 949	struct amdgpu_device *adev = ip_block->adev;
 950
 951	if (amdgpu_sriov_vf(adev)) {
 952		xgpu_nv_mailbox_get_irq(adev);
 953		if (adev->vcn.harvest_config & AMDGPU_VCN_HARVEST_VCN0) {
 954			amdgpu_virt_update_sriov_video_codec(adev,
 955							     sriov_sc_video_codecs_encode_array,
 956							     ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
 957							     sriov_sc_video_codecs_decode_array_vcn1,
 958							     ARRAY_SIZE(sriov_sc_video_codecs_decode_array_vcn1));
 959		} else {
 960			amdgpu_virt_update_sriov_video_codec(adev,
 961							     sriov_sc_video_codecs_encode_array,
 962							     ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
 963							     sriov_sc_video_codecs_decode_array_vcn0,
 964							     ARRAY_SIZE(sriov_sc_video_codecs_decode_array_vcn0));
 965		}
 966	}
 967
 968	/* Enable selfring doorbell aperture late because doorbell BAR
 969	 * aperture will change if resize BAR successfully in gmc sw_init.
 970	 */
 971	adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, true);
 972
 973	return 0;
 974}
 975
 976static int nv_common_sw_init(struct amdgpu_ip_block *ip_block)
 977{
 978	struct amdgpu_device *adev = ip_block->adev;
 979
 980	if (amdgpu_sriov_vf(adev))
 981		xgpu_nv_mailbox_add_irq_id(adev);
 982
 983	return 0;
 984}
 985
 986static int nv_common_hw_init(struct amdgpu_ip_block *ip_block)
 987{
 988	struct amdgpu_device *adev = ip_block->adev;
 
 
 
 
 
 989
 990	if (adev->nbio.funcs->apply_lc_spc_mode_wa)
 991		adev->nbio.funcs->apply_lc_spc_mode_wa(adev);
 992
 993	if (adev->nbio.funcs->apply_l1_link_width_reconfig_wa)
 994		adev->nbio.funcs->apply_l1_link_width_reconfig_wa(adev);
 995
 
 
 996	/* enable aspm */
 997	nv_program_aspm(adev);
 998	/* setup nbio registers */
 999	adev->nbio.funcs->init_registers(adev);
1000	/* remap HDP registers to a hole in mmio space,
1001	 * for the purpose of expose those registers
1002	 * to process space
1003	 */
1004	if (adev->nbio.funcs->remap_hdp_registers && !amdgpu_sriov_vf(adev))
1005		adev->nbio.funcs->remap_hdp_registers(adev);
1006	/* enable the doorbell aperture */
1007	adev->nbio.funcs->enable_doorbell_aperture(adev, true);
1008
1009	return 0;
1010}
1011
1012static int nv_common_hw_fini(struct amdgpu_ip_block *ip_block)
1013{
1014	struct amdgpu_device *adev = ip_block->adev;
1015
1016	/* Disable the doorbell aperture and selfring doorbell aperture
1017	 * separately in hw_fini because nv_enable_doorbell_aperture
1018	 * has been removed and there is no need to delay disabling
1019	 * selfring doorbell.
1020	 */
1021	adev->nbio.funcs->enable_doorbell_aperture(adev, false);
1022	adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, false);
1023
1024	return 0;
1025}
1026
1027static int nv_common_suspend(struct amdgpu_ip_block *ip_block)
1028{
1029	return nv_common_hw_fini(ip_block);
 
 
1030}
1031
1032static int nv_common_resume(struct amdgpu_ip_block *ip_block)
1033{
1034	return nv_common_hw_init(ip_block);
 
 
1035}
1036
1037static bool nv_common_is_idle(void *handle)
1038{
1039	return true;
1040}
1041
 
 
 
 
 
 
 
 
 
 
1042static int nv_common_set_clockgating_state(void *handle,
1043					   enum amd_clockgating_state state)
1044{
1045	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1046
1047	if (amdgpu_sriov_vf(adev))
1048		return 0;
1049
1050	switch (amdgpu_ip_version(adev, NBIO_HWIP, 0)) {
1051	case IP_VERSION(2, 3, 0):
1052	case IP_VERSION(2, 3, 1):
1053	case IP_VERSION(2, 3, 2):
1054	case IP_VERSION(3, 3, 0):
1055	case IP_VERSION(3, 3, 1):
1056	case IP_VERSION(3, 3, 2):
1057	case IP_VERSION(3, 3, 3):
1058		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1059				state == AMD_CG_STATE_GATE);
1060		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1061				state == AMD_CG_STATE_GATE);
1062		adev->hdp.funcs->update_clock_gating(adev,
1063				state == AMD_CG_STATE_GATE);
1064		adev->smuio.funcs->update_rom_clock_gating(adev,
1065				state == AMD_CG_STATE_GATE);
1066		break;
1067	default:
1068		break;
1069	}
1070	return 0;
1071}
1072
1073static int nv_common_set_powergating_state(void *handle,
1074					   enum amd_powergating_state state)
1075{
1076	/* TODO */
1077	return 0;
1078}
1079
1080static void nv_common_get_clockgating_state(void *handle, u64 *flags)
1081{
1082	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1083
1084	if (amdgpu_sriov_vf(adev))
1085		*flags = 0;
1086
1087	adev->nbio.funcs->get_clockgating_state(adev, flags);
1088
1089	adev->hdp.funcs->get_clock_gating_state(adev, flags);
1090
1091	adev->smuio.funcs->get_clock_gating_state(adev, flags);
 
 
1092}
1093
1094static const struct amd_ip_funcs nv_common_ip_funcs = {
1095	.name = "nv_common",
1096	.early_init = nv_common_early_init,
1097	.late_init = nv_common_late_init,
1098	.sw_init = nv_common_sw_init,
 
1099	.hw_init = nv_common_hw_init,
1100	.hw_fini = nv_common_hw_fini,
1101	.suspend = nv_common_suspend,
1102	.resume = nv_common_resume,
1103	.is_idle = nv_common_is_idle,
 
 
1104	.set_clockgating_state = nv_common_set_clockgating_state,
1105	.set_powergating_state = nv_common_set_powergating_state,
1106	.get_clockgating_state = nv_common_get_clockgating_state,
1107};
v5.14.15
   1/*
   2 * Copyright 2019 Advanced Micro Devices, Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 */
  23#include <linux/firmware.h>
  24#include <linux/slab.h>
  25#include <linux/module.h>
  26#include <linux/pci.h>
  27
  28#include <drm/amdgpu_drm.h>
  29
  30#include "amdgpu.h"
  31#include "amdgpu_atombios.h"
  32#include "amdgpu_ih.h"
  33#include "amdgpu_uvd.h"
  34#include "amdgpu_vce.h"
  35#include "amdgpu_ucode.h"
  36#include "amdgpu_psp.h"
  37#include "atom.h"
  38#include "amd_pcie.h"
  39
  40#include "gc/gc_10_1_0_offset.h"
  41#include "gc/gc_10_1_0_sh_mask.h"
  42#include "mp/mp_11_0_offset.h"
  43
  44#include "soc15.h"
  45#include "soc15_common.h"
  46#include "gmc_v10_0.h"
  47#include "gfxhub_v2_0.h"
  48#include "mmhub_v2_0.h"
  49#include "nbio_v2_3.h"
  50#include "nbio_v7_2.h"
  51#include "hdp_v5_0.h"
  52#include "nv.h"
  53#include "navi10_ih.h"
  54#include "gfx_v10_0.h"
  55#include "sdma_v5_0.h"
  56#include "sdma_v5_2.h"
  57#include "vcn_v2_0.h"
  58#include "jpeg_v2_0.h"
  59#include "vcn_v3_0.h"
  60#include "jpeg_v3_0.h"
  61#include "dce_virtual.h"
  62#include "mes_v10_1.h"
  63#include "mxgpu_nv.h"
  64#include "smuio_v11_0.h"
  65#include "smuio_v11_0_6.h"
  66
  67static const struct amd_ip_funcs nv_common_ip_funcs;
  68
  69/* Navi */
  70static const struct amdgpu_video_codec_info nv_video_codecs_encode_array[] =
  71{
  72	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
  73	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
  74};
  75
  76static const struct amdgpu_video_codecs nv_video_codecs_encode =
  77{
  78	.codec_count = ARRAY_SIZE(nv_video_codecs_encode_array),
  79	.codec_array = nv_video_codecs_encode_array,
  80};
  81
  82/* Navi1x */
  83static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] =
  84{
  85	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
  86	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
  87	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
  88	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
  89	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
  90	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
  91	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
  92};
  93
  94static const struct amdgpu_video_codecs nv_video_codecs_decode =
  95{
  96	.codec_count = ARRAY_SIZE(nv_video_codecs_decode_array),
  97	.codec_array = nv_video_codecs_decode_array,
  98};
  99
 100/* Sienna Cichlid */
 101static const struct amdgpu_video_codec_info sc_video_codecs_decode_array[] =
 102{
 103	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
 104	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
 105	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
 106	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
 
 
 
 
 
 
 
 
 
 107	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 108	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
 109	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 110	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 111};
 112
 113static const struct amdgpu_video_codecs sc_video_codecs_decode =
 114{
 115	.codec_count = ARRAY_SIZE(sc_video_codecs_decode_array),
 116	.codec_array = sc_video_codecs_decode_array,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 117};
 118
 119/* SRIOV Sienna Cichlid, not const since data is controlled by host */
 120static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array[] =
 121{
 122	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 2304, 0)},
 123	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 2304, 0)},
 124};
 125
 126static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array[] =
 127{
 128	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
 129	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
 130	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
 131	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
 132	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 133	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
 134	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 135	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1, 8192, 4352, 0)},
 136};
 137
 138static struct amdgpu_video_codecs sriov_sc_video_codecs_encode =
 139{
 
 
 
 
 
 
 
 
 
 140	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
 141	.codec_array = sriov_sc_video_codecs_encode_array,
 142};
 143
 144static struct amdgpu_video_codecs sriov_sc_video_codecs_decode =
 145{
 146	.codec_count = ARRAY_SIZE(sriov_sc_video_codecs_decode_array),
 147	.codec_array = sriov_sc_video_codecs_decode_array,
 
 
 
 
 148};
 149
 150/* Beige Goby*/
 151static const struct amdgpu_video_codec_info bg_video_codecs_decode_array[] = {
 152	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
 153	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 154	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 155};
 156
 157static const struct amdgpu_video_codecs bg_video_codecs_decode = {
 158	.codec_count = ARRAY_SIZE(bg_video_codecs_decode_array),
 159	.codec_array = bg_video_codecs_decode_array,
 160};
 161
 162static const struct amdgpu_video_codecs bg_video_codecs_encode = {
 163	.codec_count = 0,
 164	.codec_array = NULL,
 165};
 166
 167/* Yellow Carp*/
 168static const struct amdgpu_video_codec_info yc_video_codecs_decode_array[] = {
 169	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
 170	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
 171	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
 172	{codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
 
 173};
 174
 175static const struct amdgpu_video_codecs yc_video_codecs_decode = {
 176	.codec_count = ARRAY_SIZE(yc_video_codecs_decode_array),
 177	.codec_array = yc_video_codecs_decode_array,
 178};
 179
 180static int nv_query_video_codecs(struct amdgpu_device *adev, bool encode,
 181				 const struct amdgpu_video_codecs **codecs)
 182{
 183	switch (adev->asic_type) {
 184	case CHIP_SIENNA_CICHLID:
 
 
 
 
 
 185		if (amdgpu_sriov_vf(adev)) {
 186			if (encode)
 187				*codecs = &sriov_sc_video_codecs_encode;
 188			else
 189				*codecs = &sriov_sc_video_codecs_decode;
 
 
 
 
 
 
 
 190		} else {
 191			if (encode)
 192				*codecs = &nv_video_codecs_encode;
 193			else
 194				*codecs = &sc_video_codecs_decode;
 
 
 
 
 
 
 
 195		}
 196		return 0;
 197	case CHIP_NAVY_FLOUNDER:
 198	case CHIP_DIMGREY_CAVEFISH:
 199	case CHIP_VANGOGH:
 200		if (encode)
 201			*codecs = &nv_video_codecs_encode;
 202		else
 203			*codecs = &sc_video_codecs_decode;
 204		return 0;
 205	case CHIP_YELLOW_CARP:
 
 206		if (encode)
 207			*codecs = &nv_video_codecs_encode;
 208		else
 209			*codecs = &yc_video_codecs_decode;
 210		return 0;
 211	case CHIP_BEIGE_GOBY:
 212		if (encode)
 213			*codecs = &bg_video_codecs_encode;
 214		else
 215			*codecs = &bg_video_codecs_decode;
 216		return 0;
 217	case CHIP_NAVI10:
 218	case CHIP_NAVI14:
 219	case CHIP_NAVI12:
 220		if (encode)
 221			*codecs = &nv_video_codecs_encode;
 222		else
 223			*codecs = &nv_video_codecs_decode;
 224		return 0;
 225	default:
 226		return -EINVAL;
 227	}
 228}
 229
 230/*
 231 * Indirect registers accessor
 232 */
 233static u32 nv_pcie_rreg(struct amdgpu_device *adev, u32 reg)
 234{
 235	unsigned long address, data;
 236	address = adev->nbio.funcs->get_pcie_index_offset(adev);
 237	data = adev->nbio.funcs->get_pcie_data_offset(adev);
 238
 239	return amdgpu_device_indirect_rreg(adev, address, data, reg);
 240}
 241
 242static void nv_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
 243{
 244	unsigned long address, data;
 245
 246	address = adev->nbio.funcs->get_pcie_index_offset(adev);
 247	data = adev->nbio.funcs->get_pcie_data_offset(adev);
 248
 249	amdgpu_device_indirect_wreg(adev, address, data, reg, v);
 250}
 251
 252static u64 nv_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
 253{
 254	unsigned long address, data;
 255	address = adev->nbio.funcs->get_pcie_index_offset(adev);
 256	data = adev->nbio.funcs->get_pcie_data_offset(adev);
 257
 258	return amdgpu_device_indirect_rreg64(adev, address, data, reg);
 259}
 260
 261static u32 nv_pcie_port_rreg(struct amdgpu_device *adev, u32 reg)
 262{
 263	unsigned long flags, address, data;
 264	u32 r;
 265	address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
 266	data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
 267
 268	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
 269	WREG32(address, reg * 4);
 270	(void)RREG32(address);
 271	r = RREG32(data);
 272	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
 273	return r;
 274}
 275
 276static void nv_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
 277{
 278	unsigned long address, data;
 279
 280	address = adev->nbio.funcs->get_pcie_index_offset(adev);
 281	data = adev->nbio.funcs->get_pcie_data_offset(adev);
 282
 283	amdgpu_device_indirect_wreg64(adev, address, data, reg, v);
 284}
 285
 286static void nv_pcie_port_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
 287{
 288	unsigned long flags, address, data;
 289
 290	address = adev->nbio.funcs->get_pcie_port_index_offset(adev);
 291	data = adev->nbio.funcs->get_pcie_port_data_offset(adev);
 292
 293	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
 294	WREG32(address, reg * 4);
 295	(void)RREG32(address);
 296	WREG32(data, v);
 297	(void)RREG32(data);
 298	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
 299}
 300
 301static u32 nv_didt_rreg(struct amdgpu_device *adev, u32 reg)
 302{
 303	unsigned long flags, address, data;
 304	u32 r;
 305
 306	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
 307	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
 308
 309	spin_lock_irqsave(&adev->didt_idx_lock, flags);
 310	WREG32(address, (reg));
 311	r = RREG32(data);
 312	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
 313	return r;
 314}
 315
 316static void nv_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
 317{
 318	unsigned long flags, address, data;
 319
 320	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
 321	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
 322
 323	spin_lock_irqsave(&adev->didt_idx_lock, flags);
 324	WREG32(address, (reg));
 325	WREG32(data, (v));
 326	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
 327}
 328
 329static u32 nv_get_config_memsize(struct amdgpu_device *adev)
 330{
 331	return adev->nbio.funcs->get_memsize(adev);
 332}
 333
 334static u32 nv_get_xclk(struct amdgpu_device *adev)
 335{
 336	return adev->clock.spll.reference_freq;
 337}
 338
 339
 340void nv_grbm_select(struct amdgpu_device *adev,
 341		     u32 me, u32 pipe, u32 queue, u32 vmid)
 342{
 343	u32 grbm_gfx_cntl = 0;
 344	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
 345	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
 346	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
 347	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
 348
 349	WREG32_SOC15(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
 350}
 351
 352static void nv_vga_set_state(struct amdgpu_device *adev, bool state)
 353{
 354	/* todo */
 355}
 356
 357static bool nv_read_disabled_bios(struct amdgpu_device *adev)
 358{
 359	/* todo */
 360	return false;
 361}
 362
 363static bool nv_read_bios_from_rom(struct amdgpu_device *adev,
 364				  u8 *bios, u32 length_bytes)
 365{
 366	u32 *dw_ptr;
 367	u32 i, length_dw;
 368	u32 rom_index_offset, rom_data_offset;
 369
 370	if (bios == NULL)
 371		return false;
 372	if (length_bytes == 0)
 373		return false;
 374	/* APU vbios image is part of sbios image */
 375	if (adev->flags & AMD_IS_APU)
 376		return false;
 377
 378	dw_ptr = (u32 *)bios;
 379	length_dw = ALIGN(length_bytes, 4) / 4;
 380
 381	rom_index_offset =
 382		adev->smuio.funcs->get_rom_index_offset(adev);
 383	rom_data_offset =
 384		adev->smuio.funcs->get_rom_data_offset(adev);
 385
 386	/* set rom index to 0 */
 387	WREG32(rom_index_offset, 0);
 388	/* read out the rom data */
 389	for (i = 0; i < length_dw; i++)
 390		dw_ptr[i] = RREG32(rom_data_offset);
 391
 392	return true;
 393}
 394
 395static struct soc15_allowed_register_entry nv_allowed_read_registers[] = {
 396	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
 397	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
 398	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
 399	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
 400	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
 401	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
 402	{ SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
 403	{ SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
 404	{ SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
 405	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
 406	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
 407	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
 408	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
 409	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
 410	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
 411	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
 412	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
 413	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
 414	{ SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
 415};
 416
 417static uint32_t nv_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
 418					 u32 sh_num, u32 reg_offset)
 419{
 420	uint32_t val;
 421
 422	mutex_lock(&adev->grbm_idx_mutex);
 423	if (se_num != 0xffffffff || sh_num != 0xffffffff)
 424		amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
 425
 426	val = RREG32(reg_offset);
 427
 428	if (se_num != 0xffffffff || sh_num != 0xffffffff)
 429		amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
 430	mutex_unlock(&adev->grbm_idx_mutex);
 431	return val;
 432}
 433
 434static uint32_t nv_get_register_value(struct amdgpu_device *adev,
 435				      bool indexed, u32 se_num,
 436				      u32 sh_num, u32 reg_offset)
 437{
 438	if (indexed) {
 439		return nv_read_indexed_register(adev, se_num, sh_num, reg_offset);
 440	} else {
 441		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
 442			return adev->gfx.config.gb_addr_config;
 443		return RREG32(reg_offset);
 444	}
 445}
 446
 447static int nv_read_register(struct amdgpu_device *adev, u32 se_num,
 448			    u32 sh_num, u32 reg_offset, u32 *value)
 449{
 450	uint32_t i;
 451	struct soc15_allowed_register_entry  *en;
 452
 453	*value = 0;
 454	for (i = 0; i < ARRAY_SIZE(nv_allowed_read_registers); i++) {
 455		en = &nv_allowed_read_registers[i];
 456		if ((i == 7 && (adev->sdma.num_instances == 1)) || /* some asics don't have SDMA1 */
 457		    reg_offset !=
 458		    (adev->reg_offset[en->hwip][en->inst][en->seg] + en->reg_offset))
 
 459			continue;
 460
 461		*value = nv_get_register_value(adev,
 462					       nv_allowed_read_registers[i].grbm_indexed,
 463					       se_num, sh_num, reg_offset);
 464		return 0;
 465	}
 466	return -EINVAL;
 467}
 468
 469static int nv_asic_mode2_reset(struct amdgpu_device *adev)
 470{
 471	u32 i;
 472	int ret = 0;
 473
 474	amdgpu_atombios_scratch_regs_engine_hung(adev, true);
 475
 476	/* disable BM */
 477	pci_clear_master(adev->pdev);
 478
 479	amdgpu_device_cache_pci_state(adev->pdev);
 480
 481	ret = amdgpu_dpm_mode2_reset(adev);
 482	if (ret)
 483		dev_err(adev->dev, "GPU mode2 reset failed\n");
 484
 485	amdgpu_device_load_pci_state(adev->pdev);
 486
 487	/* wait for asic to come out of reset */
 488	for (i = 0; i < adev->usec_timeout; i++) {
 489		u32 memsize = adev->nbio.funcs->get_memsize(adev);
 490
 491		if (memsize != 0xffffffff)
 492			break;
 493		udelay(1);
 494	}
 495
 496	amdgpu_atombios_scratch_regs_engine_hung(adev, false);
 497
 498	return ret;
 499}
 500
 501static enum amd_reset_method
 502nv_asic_reset_method(struct amdgpu_device *adev)
 503{
 504	if (amdgpu_reset_method == AMD_RESET_METHOD_MODE1 ||
 505	    amdgpu_reset_method == AMD_RESET_METHOD_MODE2 ||
 506	    amdgpu_reset_method == AMD_RESET_METHOD_BACO ||
 507	    amdgpu_reset_method == AMD_RESET_METHOD_PCI)
 508		return amdgpu_reset_method;
 509
 510	if (amdgpu_reset_method != -1)
 511		dev_warn(adev->dev, "Specified reset method:%d isn't supported, using AUTO instead.\n",
 512				  amdgpu_reset_method);
 513
 514	switch (adev->asic_type) {
 515	case CHIP_VANGOGH:
 516	case CHIP_YELLOW_CARP:
 
 
 
 517		return AMD_RESET_METHOD_MODE2;
 518	case CHIP_SIENNA_CICHLID:
 519	case CHIP_NAVY_FLOUNDER:
 520	case CHIP_DIMGREY_CAVEFISH:
 521	case CHIP_BEIGE_GOBY:
 522		return AMD_RESET_METHOD_MODE1;
 523	default:
 524		if (amdgpu_dpm_is_baco_supported(adev))
 525			return AMD_RESET_METHOD_BACO;
 526		else
 527			return AMD_RESET_METHOD_MODE1;
 528	}
 529}
 530
 531static int nv_asic_reset(struct amdgpu_device *adev)
 532{
 533	int ret = 0;
 534
 535	switch (nv_asic_reset_method(adev)) {
 536	case AMD_RESET_METHOD_PCI:
 537		dev_info(adev->dev, "PCI reset\n");
 538		ret = amdgpu_device_pci_reset(adev);
 539		break;
 540	case AMD_RESET_METHOD_BACO:
 541		dev_info(adev->dev, "BACO reset\n");
 542		ret = amdgpu_dpm_baco_reset(adev);
 543		break;
 544	case AMD_RESET_METHOD_MODE2:
 545		dev_info(adev->dev, "MODE2 reset\n");
 546		ret = nv_asic_mode2_reset(adev);
 547		break;
 548	default:
 549		dev_info(adev->dev, "MODE1 reset\n");
 550		ret = amdgpu_device_mode1_reset(adev);
 551		break;
 552	}
 553
 554	return ret;
 555}
 556
 557static int nv_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
 558{
 559	/* todo */
 560	return 0;
 561}
 562
 563static int nv_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
 564{
 565	/* todo */
 566	return 0;
 567}
 568
 569static void nv_pcie_gen3_enable(struct amdgpu_device *adev)
 570{
 571	if (pci_is_root_bus(adev->pdev->bus))
 572		return;
 573
 574	if (amdgpu_pcie_gen2 == 0)
 575		return;
 576
 577	if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
 578					CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
 579		return;
 580
 581	/* todo */
 582}
 583
 584static void nv_program_aspm(struct amdgpu_device *adev)
 585{
 586	if (!amdgpu_aspm)
 587		return;
 588
 589	if (!(adev->flags & AMD_IS_APU) &&
 590	    (adev->nbio.funcs->program_aspm))
 591		adev->nbio.funcs->program_aspm(adev);
 592
 593}
 594
 595static void nv_enable_doorbell_aperture(struct amdgpu_device *adev,
 596					bool enable)
 597{
 598	adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
 599	adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
 600}
 601
 602static const struct amdgpu_ip_block_version nv_common_ip_block =
 603{
 604	.type = AMD_IP_BLOCK_TYPE_COMMON,
 605	.major = 1,
 606	.minor = 0,
 607	.rev = 0,
 608	.funcs = &nv_common_ip_funcs,
 609};
 610
 611static bool nv_is_headless_sku(struct pci_dev *pdev)
 612{
 613	if ((pdev->device == 0x731E &&
 614	    (pdev->revision == 0xC6 || pdev->revision == 0xC7)) ||
 615	    (pdev->device == 0x7340 && pdev->revision == 0xC9)  ||
 616	    (pdev->device == 0x7360 && pdev->revision == 0xC7))
 617		return true;
 618	return false;
 619}
 620
 621static int nv_reg_base_init(struct amdgpu_device *adev)
 622{
 623	int r;
 624
 625	if (amdgpu_discovery) {
 626		r = amdgpu_discovery_reg_base_init(adev);
 627		if (r) {
 628			DRM_WARN("failed to init reg base from ip discovery table, "
 629					"fallback to legacy init method\n");
 630			goto legacy_init;
 631		}
 632
 633		amdgpu_discovery_harvest_ip(adev);
 634		if (nv_is_headless_sku(adev->pdev)) {
 635			adev->harvest_ip_mask |= AMD_HARVEST_IP_VCN_MASK;
 636			adev->harvest_ip_mask |= AMD_HARVEST_IP_JPEG_MASK;
 637		}
 638
 639		return 0;
 640	}
 641
 642legacy_init:
 643	switch (adev->asic_type) {
 644	case CHIP_NAVI10:
 645		navi10_reg_base_init(adev);
 646		break;
 647	case CHIP_NAVI14:
 648		navi14_reg_base_init(adev);
 649		break;
 650	case CHIP_NAVI12:
 651		navi12_reg_base_init(adev);
 652		break;
 653	case CHIP_SIENNA_CICHLID:
 654	case CHIP_NAVY_FLOUNDER:
 655		sienna_cichlid_reg_base_init(adev);
 656		break;
 657	case CHIP_VANGOGH:
 658		vangogh_reg_base_init(adev);
 659		break;
 660	case CHIP_DIMGREY_CAVEFISH:
 661		dimgrey_cavefish_reg_base_init(adev);
 662		break;
 663	case CHIP_BEIGE_GOBY:
 664		beige_goby_reg_base_init(adev);
 665		break;
 666	case CHIP_YELLOW_CARP:
 667		yellow_carp_reg_base_init(adev);
 668		break;
 669	default:
 670		return -EINVAL;
 671	}
 672
 673	return 0;
 674}
 675
 676void nv_set_virt_ops(struct amdgpu_device *adev)
 677{
 678	adev->virt.ops = &xgpu_nv_virt_ops;
 679}
 680
 681int nv_set_ip_blocks(struct amdgpu_device *adev)
 682{
 683	int r;
 684
 685	if (adev->flags & AMD_IS_APU) {
 686		adev->nbio.funcs = &nbio_v7_2_funcs;
 687		adev->nbio.hdp_flush_reg = &nbio_v7_2_hdp_flush_reg;
 688	} else {
 689		adev->nbio.funcs = &nbio_v2_3_funcs;
 690		adev->nbio.hdp_flush_reg = &nbio_v2_3_hdp_flush_reg;
 691	}
 692	adev->hdp.funcs = &hdp_v5_0_funcs;
 693
 694	if (adev->asic_type >= CHIP_SIENNA_CICHLID)
 695		adev->smuio.funcs = &smuio_v11_0_6_funcs;
 696	else
 697		adev->smuio.funcs = &smuio_v11_0_funcs;
 698
 699	if (adev->asic_type == CHIP_SIENNA_CICHLID)
 700		adev->gmc.xgmi.supported = true;
 701
 702	/* Set IP register base before any HW register access */
 703	r = nv_reg_base_init(adev);
 704	if (r)
 705		return r;
 706
 707	switch (adev->asic_type) {
 708	case CHIP_NAVI10:
 709	case CHIP_NAVI14:
 710		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 711		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 712		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 713		amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 714		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
 715		    !amdgpu_sriov_vf(adev))
 716			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 717		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 718			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 719#if defined(CONFIG_DRM_AMD_DC)
 720		else if (amdgpu_device_has_dc_support(adev))
 721			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 722#endif
 723		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 724		amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
 725		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
 726		    !amdgpu_sriov_vf(adev))
 727			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 728		amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
 729		amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
 730		if (adev->enable_mes)
 731			amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
 732		break;
 733	case CHIP_NAVI12:
 734		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 735		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 736		if (!amdgpu_sriov_vf(adev)) {
 737			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 738			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 739		} else {
 740			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 741			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 742		}
 743		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)
 744			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 745		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 746			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 747#if defined(CONFIG_DRM_AMD_DC)
 748		else if (amdgpu_device_has_dc_support(adev))
 749			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 750#endif
 751		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 752		amdgpu_device_ip_block_add(adev, &sdma_v5_0_ip_block);
 753		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
 754		    !amdgpu_sriov_vf(adev))
 755			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 756		amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
 757		if (!amdgpu_sriov_vf(adev))
 758			amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
 759		break;
 760	case CHIP_SIENNA_CICHLID:
 761		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 762		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 763		if (!amdgpu_sriov_vf(adev)) {
 764			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 765			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 766				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 767		} else {
 768			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 769				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 770			amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 771		}
 772		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
 773		    is_support_sw_smu(adev))
 774			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 775		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 776			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 777#if defined(CONFIG_DRM_AMD_DC)
 778		else if (amdgpu_device_has_dc_support(adev))
 779			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 780#endif
 781		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 782		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 783		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 784		if (!amdgpu_sriov_vf(adev))
 785			amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
 786		if (adev->enable_mes)
 787			amdgpu_device_ip_block_add(adev, &mes_v10_1_ip_block);
 788		break;
 789	case CHIP_NAVY_FLOUNDER:
 790		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 791		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 792		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 793		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 794			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 795		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
 796		    is_support_sw_smu(adev))
 797			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 798		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 799			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 800#if defined(CONFIG_DRM_AMD_DC)
 801		else if (amdgpu_device_has_dc_support(adev))
 802			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 803#endif
 804		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 805		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 806		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 807		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
 808		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
 809		    is_support_sw_smu(adev))
 810			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 811		break;
 812	case CHIP_VANGOGH:
 813		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 814		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 815		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 816		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 817			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 818		amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 819		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 820			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 821#if defined(CONFIG_DRM_AMD_DC)
 822		else if (amdgpu_device_has_dc_support(adev))
 823			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 824#endif
 825		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 826		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 827		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 828		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
 829		break;
 830	case CHIP_DIMGREY_CAVEFISH:
 831		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 832		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 833		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 834		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 835			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 836		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
 837		    is_support_sw_smu(adev))
 838			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 839		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 840			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 841#if defined(CONFIG_DRM_AMD_DC)
 842                else if (amdgpu_device_has_dc_support(adev))
 843                        amdgpu_device_ip_block_add(adev, &dm_ip_block);
 844#endif
 845		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 846		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 847		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 848		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
 849		break;
 850	case CHIP_BEIGE_GOBY:
 851		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 852		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 853		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 854		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 855			amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
 856		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP &&
 857		    is_support_sw_smu(adev))
 858			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 859		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 860		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 861		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 862			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 863#if defined(CONFIG_DRM_AMD_DC)
 864		else if (amdgpu_device_has_dc_support(adev))
 865			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 866#endif
 867		if (adev->firmware.load_type == AMDGPU_FW_LOAD_DIRECT &&
 868		    is_support_sw_smu(adev))
 869			amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
 870		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 871		break;
 872	case CHIP_YELLOW_CARP:
 873		amdgpu_device_ip_block_add(adev, &nv_common_ip_block);
 874		amdgpu_device_ip_block_add(adev, &gmc_v10_0_ip_block);
 875		amdgpu_device_ip_block_add(adev, &navi10_ih_ip_block);
 876		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
 877			amdgpu_device_ip_block_add(adev, &psp_v13_0_ip_block);
 878		amdgpu_device_ip_block_add(adev, &smu_v13_0_ip_block);
 879		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 880			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 881		amdgpu_device_ip_block_add(adev, &gfx_v10_0_ip_block);
 882		amdgpu_device_ip_block_add(adev, &sdma_v5_2_ip_block);
 883		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
 884			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
 885#if defined(CONFIG_DRM_AMD_DC)
 886		else if (amdgpu_device_has_dc_support(adev))
 887			amdgpu_device_ip_block_add(adev, &dm_ip_block);
 888#endif
 889		amdgpu_device_ip_block_add(adev, &vcn_v3_0_ip_block);
 890		amdgpu_device_ip_block_add(adev, &jpeg_v3_0_ip_block);
 891		break;
 892	default:
 893		return -EINVAL;
 894	}
 895
 896	return 0;
 897}
 898
 899static uint32_t nv_get_rev_id(struct amdgpu_device *adev)
 900{
 901	return adev->nbio.funcs->get_rev_id(adev);
 902}
 903
 904static bool nv_need_full_reset(struct amdgpu_device *adev)
 905{
 906	return true;
 907}
 908
 909static bool nv_need_reset_on_init(struct amdgpu_device *adev)
 910{
 911	u32 sol_reg;
 912
 913	if (adev->flags & AMD_IS_APU)
 914		return false;
 915
 916	/* Check sOS sign of life register to confirm sys driver and sOS
 917	 * are already been loaded.
 918	 */
 919	sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
 920	if (sol_reg)
 921		return true;
 922
 923	return false;
 924}
 925
 926static uint64_t nv_get_pcie_replay_count(struct amdgpu_device *adev)
 927{
 928
 929	/* TODO
 930	 * dummy implement for pcie_replay_count sysfs interface
 931	 * */
 932
 933	return 0;
 934}
 935
 936static void nv_init_doorbell_index(struct amdgpu_device *adev)
 937{
 938	adev->doorbell_index.kiq = AMDGPU_NAVI10_DOORBELL_KIQ;
 939	adev->doorbell_index.mec_ring0 = AMDGPU_NAVI10_DOORBELL_MEC_RING0;
 940	adev->doorbell_index.mec_ring1 = AMDGPU_NAVI10_DOORBELL_MEC_RING1;
 941	adev->doorbell_index.mec_ring2 = AMDGPU_NAVI10_DOORBELL_MEC_RING2;
 942	adev->doorbell_index.mec_ring3 = AMDGPU_NAVI10_DOORBELL_MEC_RING3;
 943	adev->doorbell_index.mec_ring4 = AMDGPU_NAVI10_DOORBELL_MEC_RING4;
 944	adev->doorbell_index.mec_ring5 = AMDGPU_NAVI10_DOORBELL_MEC_RING5;
 945	adev->doorbell_index.mec_ring6 = AMDGPU_NAVI10_DOORBELL_MEC_RING6;
 946	adev->doorbell_index.mec_ring7 = AMDGPU_NAVI10_DOORBELL_MEC_RING7;
 947	adev->doorbell_index.userqueue_start = AMDGPU_NAVI10_DOORBELL_USERQUEUE_START;
 948	adev->doorbell_index.userqueue_end = AMDGPU_NAVI10_DOORBELL_USERQUEUE_END;
 949	adev->doorbell_index.gfx_ring0 = AMDGPU_NAVI10_DOORBELL_GFX_RING0;
 950	adev->doorbell_index.gfx_ring1 = AMDGPU_NAVI10_DOORBELL_GFX_RING1;
 951	adev->doorbell_index.mes_ring = AMDGPU_NAVI10_DOORBELL_MES_RING;
 
 
 
 
 
 952	adev->doorbell_index.sdma_engine[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0;
 953	adev->doorbell_index.sdma_engine[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1;
 954	adev->doorbell_index.sdma_engine[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2;
 955	adev->doorbell_index.sdma_engine[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3;
 956	adev->doorbell_index.ih = AMDGPU_NAVI10_DOORBELL_IH;
 957	adev->doorbell_index.vcn.vcn_ring0_1 = AMDGPU_NAVI10_DOORBELL64_VCN0_1;
 958	adev->doorbell_index.vcn.vcn_ring2_3 = AMDGPU_NAVI10_DOORBELL64_VCN2_3;
 959	adev->doorbell_index.vcn.vcn_ring4_5 = AMDGPU_NAVI10_DOORBELL64_VCN4_5;
 960	adev->doorbell_index.vcn.vcn_ring6_7 = AMDGPU_NAVI10_DOORBELL64_VCN6_7;
 961	adev->doorbell_index.first_non_cp = AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP;
 962	adev->doorbell_index.last_non_cp = AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP;
 963
 964	adev->doorbell_index.max_assignment = AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT << 1;
 965	adev->doorbell_index.sdma_doorbell_range = 20;
 966}
 967
 968static void nv_pre_asic_init(struct amdgpu_device *adev)
 969{
 970}
 971
 972static int nv_update_umd_stable_pstate(struct amdgpu_device *adev,
 973				       bool enter)
 974{
 975	if (enter)
 976		amdgpu_gfx_rlc_enter_safe_mode(adev);
 977	else
 978		amdgpu_gfx_rlc_exit_safe_mode(adev);
 979
 980	if (adev->gfx.funcs->update_perfmon_mgcg)
 981		adev->gfx.funcs->update_perfmon_mgcg(adev, !enter);
 982
 983	if (!(adev->flags & AMD_IS_APU) &&
 984	    (adev->nbio.funcs->enable_aspm))
 985		adev->nbio.funcs->enable_aspm(adev, !enter);
 986
 987	return 0;
 988}
 989
 990static const struct amdgpu_asic_funcs nv_asic_funcs =
 991{
 992	.read_disabled_bios = &nv_read_disabled_bios,
 993	.read_bios_from_rom = &nv_read_bios_from_rom,
 994	.read_register = &nv_read_register,
 995	.reset = &nv_asic_reset,
 996	.reset_method = &nv_asic_reset_method,
 997	.set_vga_state = &nv_vga_set_state,
 998	.get_xclk = &nv_get_xclk,
 999	.set_uvd_clocks = &nv_set_uvd_clocks,
1000	.set_vce_clocks = &nv_set_vce_clocks,
1001	.get_config_memsize = &nv_get_config_memsize,
1002	.init_doorbell_index = &nv_init_doorbell_index,
1003	.need_full_reset = &nv_need_full_reset,
1004	.need_reset_on_init = &nv_need_reset_on_init,
1005	.get_pcie_replay_count = &nv_get_pcie_replay_count,
1006	.supports_baco = &amdgpu_dpm_is_baco_supported,
1007	.pre_asic_init = &nv_pre_asic_init,
1008	.update_umd_stable_pstate = &nv_update_umd_stable_pstate,
1009	.query_video_codecs = &nv_query_video_codecs,
1010};
1011
1012static int nv_common_early_init(void *handle)
1013{
1014#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1015	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1016
1017	adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
1018	adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
1019	adev->smc_rreg = NULL;
1020	adev->smc_wreg = NULL;
1021	adev->pcie_rreg = &nv_pcie_rreg;
1022	adev->pcie_wreg = &nv_pcie_wreg;
1023	adev->pcie_rreg64 = &nv_pcie_rreg64;
1024	adev->pcie_wreg64 = &nv_pcie_wreg64;
1025	adev->pciep_rreg = &nv_pcie_port_rreg;
1026	adev->pciep_wreg = &nv_pcie_port_wreg;
1027
1028	/* TODO: will add them during VCN v2 implementation */
1029	adev->uvd_ctx_rreg = NULL;
1030	adev->uvd_ctx_wreg = NULL;
1031
1032	adev->didt_rreg = &nv_didt_rreg;
1033	adev->didt_wreg = &nv_didt_wreg;
1034
1035	adev->asic_funcs = &nv_asic_funcs;
1036
1037	adev->rev_id = nv_get_rev_id(adev);
1038	adev->external_rev_id = 0xff;
1039	switch (adev->asic_type) {
1040	case CHIP_NAVI10:
 
 
 
1041		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1042			AMD_CG_SUPPORT_GFX_CGCG |
1043			AMD_CG_SUPPORT_IH_CG |
1044			AMD_CG_SUPPORT_HDP_MGCG |
1045			AMD_CG_SUPPORT_HDP_LS |
1046			AMD_CG_SUPPORT_SDMA_MGCG |
1047			AMD_CG_SUPPORT_SDMA_LS |
1048			AMD_CG_SUPPORT_MC_MGCG |
1049			AMD_CG_SUPPORT_MC_LS |
1050			AMD_CG_SUPPORT_ATHUB_MGCG |
1051			AMD_CG_SUPPORT_ATHUB_LS |
1052			AMD_CG_SUPPORT_VCN_MGCG |
1053			AMD_CG_SUPPORT_JPEG_MGCG |
1054			AMD_CG_SUPPORT_BIF_MGCG |
1055			AMD_CG_SUPPORT_BIF_LS;
1056		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1057			AMD_PG_SUPPORT_VCN_DPG |
1058			AMD_PG_SUPPORT_JPEG |
1059			AMD_PG_SUPPORT_ATHUB;
1060		adev->external_rev_id = adev->rev_id + 0x1;
1061		break;
1062	case CHIP_NAVI14:
1063		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1064			AMD_CG_SUPPORT_GFX_CGCG |
1065			AMD_CG_SUPPORT_IH_CG |
1066			AMD_CG_SUPPORT_HDP_MGCG |
1067			AMD_CG_SUPPORT_HDP_LS |
1068			AMD_CG_SUPPORT_SDMA_MGCG |
1069			AMD_CG_SUPPORT_SDMA_LS |
1070			AMD_CG_SUPPORT_MC_MGCG |
1071			AMD_CG_SUPPORT_MC_LS |
1072			AMD_CG_SUPPORT_ATHUB_MGCG |
1073			AMD_CG_SUPPORT_ATHUB_LS |
1074			AMD_CG_SUPPORT_VCN_MGCG |
1075			AMD_CG_SUPPORT_JPEG_MGCG |
1076			AMD_CG_SUPPORT_BIF_MGCG |
1077			AMD_CG_SUPPORT_BIF_LS;
1078		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1079			AMD_PG_SUPPORT_JPEG |
1080			AMD_PG_SUPPORT_VCN_DPG;
1081		adev->external_rev_id = adev->rev_id + 20;
1082		break;
1083	case CHIP_NAVI12:
1084		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1085			AMD_CG_SUPPORT_GFX_MGLS |
1086			AMD_CG_SUPPORT_GFX_CGCG |
1087			AMD_CG_SUPPORT_GFX_CP_LS |
1088			AMD_CG_SUPPORT_GFX_RLC_LS |
1089			AMD_CG_SUPPORT_IH_CG |
1090			AMD_CG_SUPPORT_HDP_MGCG |
1091			AMD_CG_SUPPORT_HDP_LS |
1092			AMD_CG_SUPPORT_SDMA_MGCG |
1093			AMD_CG_SUPPORT_SDMA_LS |
1094			AMD_CG_SUPPORT_MC_MGCG |
1095			AMD_CG_SUPPORT_MC_LS |
1096			AMD_CG_SUPPORT_ATHUB_MGCG |
1097			AMD_CG_SUPPORT_ATHUB_LS |
1098			AMD_CG_SUPPORT_VCN_MGCG |
1099			AMD_CG_SUPPORT_JPEG_MGCG;
1100		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1101			AMD_PG_SUPPORT_VCN_DPG |
1102			AMD_PG_SUPPORT_JPEG |
1103			AMD_PG_SUPPORT_ATHUB;
1104		/* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
1105		 * as a consequence, the rev_id and external_rev_id are wrong.
1106		 * workaround it by hardcoding rev_id to 0 (default value).
1107		 */
1108		if (amdgpu_sriov_vf(adev))
1109			adev->rev_id = 0;
1110		adev->external_rev_id = adev->rev_id + 0xa;
1111		break;
1112	case CHIP_SIENNA_CICHLID:
1113		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1114			AMD_CG_SUPPORT_GFX_CGCG |
1115			AMD_CG_SUPPORT_GFX_CGLS |
1116			AMD_CG_SUPPORT_GFX_3D_CGCG |
1117			AMD_CG_SUPPORT_MC_MGCG |
1118			AMD_CG_SUPPORT_VCN_MGCG |
1119			AMD_CG_SUPPORT_JPEG_MGCG |
1120			AMD_CG_SUPPORT_HDP_MGCG |
1121			AMD_CG_SUPPORT_HDP_LS |
1122			AMD_CG_SUPPORT_IH_CG |
1123			AMD_CG_SUPPORT_MC_LS;
1124		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1125			AMD_PG_SUPPORT_VCN_DPG |
1126			AMD_PG_SUPPORT_JPEG |
1127			AMD_PG_SUPPORT_ATHUB |
1128			AMD_PG_SUPPORT_MMHUB;
1129		if (amdgpu_sriov_vf(adev)) {
1130			/* hypervisor control CG and PG enablement */
1131			adev->cg_flags = 0;
1132			adev->pg_flags = 0;
1133		}
1134		adev->external_rev_id = adev->rev_id + 0x28;
1135		break;
1136	case CHIP_NAVY_FLOUNDER:
1137		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1138			AMD_CG_SUPPORT_GFX_CGCG |
1139			AMD_CG_SUPPORT_GFX_CGLS |
1140			AMD_CG_SUPPORT_GFX_3D_CGCG |
1141			AMD_CG_SUPPORT_VCN_MGCG |
1142			AMD_CG_SUPPORT_JPEG_MGCG |
1143			AMD_CG_SUPPORT_MC_MGCG |
1144			AMD_CG_SUPPORT_MC_LS |
1145			AMD_CG_SUPPORT_HDP_MGCG |
1146			AMD_CG_SUPPORT_HDP_LS |
1147			AMD_CG_SUPPORT_IH_CG;
1148		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1149			AMD_PG_SUPPORT_VCN_DPG |
1150			AMD_PG_SUPPORT_JPEG |
1151			AMD_PG_SUPPORT_ATHUB |
1152			AMD_PG_SUPPORT_MMHUB;
1153		adev->external_rev_id = adev->rev_id + 0x32;
1154		break;
1155
1156	case CHIP_VANGOGH:
1157		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1158			AMD_CG_SUPPORT_GFX_MGLS |
1159			AMD_CG_SUPPORT_GFX_CP_LS |
1160			AMD_CG_SUPPORT_GFX_RLC_LS |
1161			AMD_CG_SUPPORT_GFX_CGCG |
1162			AMD_CG_SUPPORT_GFX_CGLS |
1163			AMD_CG_SUPPORT_GFX_3D_CGCG |
1164			AMD_CG_SUPPORT_GFX_3D_CGLS |
1165			AMD_CG_SUPPORT_MC_MGCG |
1166			AMD_CG_SUPPORT_MC_LS |
1167			AMD_CG_SUPPORT_GFX_FGCG |
1168			AMD_CG_SUPPORT_VCN_MGCG |
1169			AMD_CG_SUPPORT_SDMA_MGCG |
1170			AMD_CG_SUPPORT_SDMA_LS |
1171			AMD_CG_SUPPORT_JPEG_MGCG;
1172		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1173			AMD_PG_SUPPORT_VCN |
1174			AMD_PG_SUPPORT_VCN_DPG |
1175			AMD_PG_SUPPORT_JPEG;
1176		if (adev->apu_flags & AMD_APU_IS_VANGOGH)
1177			adev->external_rev_id = adev->rev_id + 0x01;
1178		break;
1179	case CHIP_DIMGREY_CAVEFISH:
1180		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1181			AMD_CG_SUPPORT_GFX_CGCG |
1182			AMD_CG_SUPPORT_GFX_CGLS |
1183			AMD_CG_SUPPORT_GFX_3D_CGCG |
1184			AMD_CG_SUPPORT_VCN_MGCG |
1185			AMD_CG_SUPPORT_JPEG_MGCG |
1186			AMD_CG_SUPPORT_MC_MGCG |
1187			AMD_CG_SUPPORT_MC_LS |
1188			AMD_CG_SUPPORT_HDP_MGCG |
1189			AMD_CG_SUPPORT_HDP_LS |
1190			AMD_CG_SUPPORT_IH_CG;
1191		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1192			AMD_PG_SUPPORT_VCN_DPG |
1193			AMD_PG_SUPPORT_JPEG |
1194			AMD_PG_SUPPORT_ATHUB |
1195			AMD_PG_SUPPORT_MMHUB;
1196		adev->external_rev_id = adev->rev_id + 0x3c;
1197		break;
1198	case CHIP_BEIGE_GOBY:
1199		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1200			AMD_CG_SUPPORT_GFX_CGCG |
1201			AMD_CG_SUPPORT_GFX_CGLS |
1202			AMD_CG_SUPPORT_GFX_3D_CGCG |
1203			AMD_CG_SUPPORT_MC_MGCG |
1204			AMD_CG_SUPPORT_MC_LS |
1205			AMD_CG_SUPPORT_HDP_MGCG |
1206			AMD_CG_SUPPORT_HDP_LS |
1207			AMD_CG_SUPPORT_IH_CG |
1208			AMD_CG_SUPPORT_VCN_MGCG;
1209		adev->pg_flags = AMD_PG_SUPPORT_VCN |
1210			AMD_PG_SUPPORT_VCN_DPG |
1211			AMD_PG_SUPPORT_ATHUB |
1212			AMD_PG_SUPPORT_MMHUB;
1213		adev->external_rev_id = adev->rev_id + 0x46;
1214		break;
1215	case CHIP_YELLOW_CARP:
1216		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
1217			AMD_CG_SUPPORT_GFX_MGLS |
1218			AMD_CG_SUPPORT_GFX_CGCG |
1219			AMD_CG_SUPPORT_GFX_CGLS |
1220			AMD_CG_SUPPORT_GFX_3D_CGCG |
1221			AMD_CG_SUPPORT_GFX_3D_CGLS |
1222			AMD_CG_SUPPORT_GFX_RLC_LS |
1223			AMD_CG_SUPPORT_GFX_CP_LS |
1224			AMD_CG_SUPPORT_GFX_FGCG |
1225			AMD_CG_SUPPORT_MC_MGCG |
1226			AMD_CG_SUPPORT_MC_LS |
1227			AMD_CG_SUPPORT_SDMA_LS |
1228			AMD_CG_SUPPORT_HDP_MGCG |
1229			AMD_CG_SUPPORT_HDP_LS |
1230			AMD_CG_SUPPORT_ATHUB_MGCG |
1231			AMD_CG_SUPPORT_ATHUB_LS |
1232			AMD_CG_SUPPORT_IH_CG |
1233			AMD_CG_SUPPORT_VCN_MGCG |
1234			AMD_CG_SUPPORT_JPEG_MGCG;
 
1235		adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1236			AMD_PG_SUPPORT_VCN |
1237			AMD_PG_SUPPORT_VCN_DPG |
1238			AMD_PG_SUPPORT_JPEG;
1239		if (adev->pdev->device == 0x1681)
1240			adev->external_rev_id = adev->rev_id + 0x19;
1241		else
1242			adev->external_rev_id = adev->rev_id + 0x01;
1243		break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1244	default:
1245		/* FIXME: not supported yet */
1246		return -EINVAL;
1247	}
1248
1249	if (adev->harvest_ip_mask & AMD_HARVEST_IP_VCN_MASK)
1250		adev->pg_flags &= ~(AMD_PG_SUPPORT_VCN |
1251				    AMD_PG_SUPPORT_VCN_DPG |
1252				    AMD_PG_SUPPORT_JPEG);
1253
1254	if (amdgpu_sriov_vf(adev)) {
1255		amdgpu_virt_init_setting(adev);
1256		xgpu_nv_mailbox_set_irq_funcs(adev);
1257	}
1258
1259	return 0;
1260}
1261
1262static int nv_common_late_init(void *handle)
1263{
1264	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1265
1266	if (amdgpu_sriov_vf(adev)) {
1267		xgpu_nv_mailbox_get_irq(adev);
1268		amdgpu_virt_update_sriov_video_codec(adev,
1269				sriov_sc_video_codecs_encode_array, ARRAY_SIZE(sriov_sc_video_codecs_encode_array),
1270				sriov_sc_video_codecs_decode_array, ARRAY_SIZE(sriov_sc_video_codecs_decode_array));
 
 
 
 
 
 
 
 
 
 
1271	}
1272
 
 
 
 
 
1273	return 0;
1274}
1275
1276static int nv_common_sw_init(void *handle)
1277{
1278	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1279
1280	if (amdgpu_sriov_vf(adev))
1281		xgpu_nv_mailbox_add_irq_id(adev);
1282
1283	return 0;
1284}
1285
1286static int nv_common_sw_fini(void *handle)
1287{
1288	return 0;
1289}
1290
1291static int nv_common_hw_init(void *handle)
1292{
1293	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1294
1295	if (adev->nbio.funcs->apply_lc_spc_mode_wa)
1296		adev->nbio.funcs->apply_lc_spc_mode_wa(adev);
1297
1298	if (adev->nbio.funcs->apply_l1_link_width_reconfig_wa)
1299		adev->nbio.funcs->apply_l1_link_width_reconfig_wa(adev);
1300
1301	/* enable pcie gen2/3 link */
1302	nv_pcie_gen3_enable(adev);
1303	/* enable aspm */
1304	nv_program_aspm(adev);
1305	/* setup nbio registers */
1306	adev->nbio.funcs->init_registers(adev);
1307	/* remap HDP registers to a hole in mmio space,
1308	 * for the purpose of expose those registers
1309	 * to process space
1310	 */
1311	if (adev->nbio.funcs->remap_hdp_registers)
1312		adev->nbio.funcs->remap_hdp_registers(adev);
1313	/* enable the doorbell aperture */
1314	nv_enable_doorbell_aperture(adev, true);
1315
1316	return 0;
1317}
1318
1319static int nv_common_hw_fini(void *handle)
1320{
1321	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1322
1323	/* disable the doorbell aperture */
1324	nv_enable_doorbell_aperture(adev, false);
 
 
 
 
 
1325
1326	return 0;
1327}
1328
1329static int nv_common_suspend(void *handle)
1330{
1331	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1332
1333	return nv_common_hw_fini(adev);
1334}
1335
1336static int nv_common_resume(void *handle)
1337{
1338	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1339
1340	return nv_common_hw_init(adev);
1341}
1342
1343static bool nv_common_is_idle(void *handle)
1344{
1345	return true;
1346}
1347
1348static int nv_common_wait_for_idle(void *handle)
1349{
1350	return 0;
1351}
1352
1353static int nv_common_soft_reset(void *handle)
1354{
1355	return 0;
1356}
1357
1358static int nv_common_set_clockgating_state(void *handle,
1359					   enum amd_clockgating_state state)
1360{
1361	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1362
1363	if (amdgpu_sriov_vf(adev))
1364		return 0;
1365
1366	switch (adev->asic_type) {
1367	case CHIP_NAVI10:
1368	case CHIP_NAVI14:
1369	case CHIP_NAVI12:
1370	case CHIP_SIENNA_CICHLID:
1371	case CHIP_NAVY_FLOUNDER:
1372	case CHIP_DIMGREY_CAVEFISH:
1373	case CHIP_BEIGE_GOBY:
1374		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
1375				state == AMD_CG_STATE_GATE);
1376		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
1377				state == AMD_CG_STATE_GATE);
1378		adev->hdp.funcs->update_clock_gating(adev,
1379				state == AMD_CG_STATE_GATE);
1380		adev->smuio.funcs->update_rom_clock_gating(adev,
1381				state == AMD_CG_STATE_GATE);
1382		break;
1383	default:
1384		break;
1385	}
1386	return 0;
1387}
1388
1389static int nv_common_set_powergating_state(void *handle,
1390					   enum amd_powergating_state state)
1391{
1392	/* TODO */
1393	return 0;
1394}
1395
1396static void nv_common_get_clockgating_state(void *handle, u32 *flags)
1397{
1398	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1399
1400	if (amdgpu_sriov_vf(adev))
1401		*flags = 0;
1402
1403	adev->nbio.funcs->get_clockgating_state(adev, flags);
1404
1405	adev->hdp.funcs->get_clock_gating_state(adev, flags);
1406
1407	adev->smuio.funcs->get_clock_gating_state(adev, flags);
1408
1409	return;
1410}
1411
1412static const struct amd_ip_funcs nv_common_ip_funcs = {
1413	.name = "nv_common",
1414	.early_init = nv_common_early_init,
1415	.late_init = nv_common_late_init,
1416	.sw_init = nv_common_sw_init,
1417	.sw_fini = nv_common_sw_fini,
1418	.hw_init = nv_common_hw_init,
1419	.hw_fini = nv_common_hw_fini,
1420	.suspend = nv_common_suspend,
1421	.resume = nv_common_resume,
1422	.is_idle = nv_common_is_idle,
1423	.wait_for_idle = nv_common_wait_for_idle,
1424	.soft_reset = nv_common_soft_reset,
1425	.set_clockgating_state = nv_common_set_clockgating_state,
1426	.set_powergating_state = nv_common_set_powergating_state,
1427	.get_clockgating_state = nv_common_get_clockgating_state,
1428};