2333 lines · 65.4 KB · C
RawDownload
/* * Copyright 2012 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Alex Deucher */#include <linux/firmware.h>#include <linux/slab.h>#include <linux/module.h>#include <linux/pci.h> #include <drm/amdgpu_drm.h> #include "amdgpu.h"#include "amdgpu_atombios.h"#include "amdgpu_ih.h"#include "amdgpu_uvd.h"#include "amdgpu_vce.h"#include "cikd.h"#include "atom.h"#include "amd_pcie.h" #include "cik.h"#include "gmc_v7_0.h"#include "cik_ih.h"#include "dce_v8_0.h"#include "gfx_v7_0.h"#include "cik_sdma.h"#include "uvd_v4_2.h"#include "vce_v2_0.h"#include "cik_dpm.h" #include "uvd/uvd_4_2_d.h" #include "smu/smu_7_0_1_d.h"#include "smu/smu_7_0_1_sh_mask.h" #include "dce/dce_8_0_d.h"#include "dce/dce_8_0_sh_mask.h" #include "bif/bif_4_1_d.h"#include "bif/bif_4_1_sh_mask.h" #include "gca/gfx_7_2_d.h"#include "gca/gfx_7_2_enum.h"#include "gca/gfx_7_2_sh_mask.h" #include "gmc/gmc_7_1_d.h"#include "gmc/gmc_7_1_sh_mask.h" #include "oss/oss_2_0_d.h"#include "oss/oss_2_0_sh_mask.h" #include "amdgpu_dm.h"#include "amdgpu_amdkfd.h"#include "dce_virtual.h" static const struct amdgpu_video_codec_info cik_video_codecs_encode_array[] ={	{		.codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,		.max_width = 2048,		.max_height = 1152,		.max_pixels_per_frame = 2048 * 1152,		.max_level = 0,	},}; static const struct amdgpu_video_codecs cik_video_codecs_encode ={	.codec_count = ARRAY_SIZE(cik_video_codecs_encode_array),	.codec_array = cik_video_codecs_encode_array,}; static const struct amdgpu_video_codec_info cik_video_codecs_decode_array[] ={	{		.codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2,		.max_width = 2048,		.max_height = 1152,		.max_pixels_per_frame = 2048 * 1152,		.max_level = 3,	},	{		.codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4,		.max_width = 2048,		.max_height = 1152,		.max_pixels_per_frame = 2048 * 1152,		.max_level = 5,	},	{		.codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC,		.max_width = 2048,		.max_height = 1152,		.max_pixels_per_frame = 2048 * 1152,		.max_level = 41,	},	{		.codec_type = AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1,		.max_width = 2048,		.max_height = 1152,		.max_pixels_per_frame = 2048 * 1152,		.max_level = 4,	},}; static const struct amdgpu_video_codecs cik_video_codecs_decode ={	.codec_count = ARRAY_SIZE(cik_video_codecs_decode_array),	.codec_array = cik_video_codecs_decode_array,}; static int cik_query_video_codecs(struct amdgpu_device *adev, bool encode,				  const struct amdgpu_video_codecs **codecs){	switch (adev->asic_type) {	case CHIP_BONAIRE:	case CHIP_HAWAII:	case CHIP_KAVERI:	case CHIP_KABINI:	case CHIP_MULLINS:		if (encode)			*codecs = &cik_video_codecs_encode;		else			*codecs = &cik_video_codecs_decode;		return 0;	default:		return -EINVAL;	}} /* * Indirect registers accessor */static u32 cik_pcie_rreg(struct amdgpu_device *adev, u32 reg){	unsigned long flags;	u32 r; 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);	WREG32(mmPCIE_INDEX, reg);	(void)RREG32(mmPCIE_INDEX);	r = RREG32(mmPCIE_DATA);	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);	return r;} static void cik_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v){	unsigned long flags; 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);	WREG32(mmPCIE_INDEX, reg);	(void)RREG32(mmPCIE_INDEX);	WREG32(mmPCIE_DATA, v);	(void)RREG32(mmPCIE_DATA);	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);} static u32 cik_smc_rreg(struct amdgpu_device *adev, u32 reg){	unsigned long flags;	u32 r; 	spin_lock_irqsave(&adev->smc_idx_lock, flags);	WREG32(mmSMC_IND_INDEX_0, (reg));	r = RREG32(mmSMC_IND_DATA_0);	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);	return r;} static void cik_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v){	unsigned long flags; 	spin_lock_irqsave(&adev->smc_idx_lock, flags);	WREG32(mmSMC_IND_INDEX_0, (reg));	WREG32(mmSMC_IND_DATA_0, (v));	spin_unlock_irqrestore(&adev->smc_idx_lock, flags);} static u32 cik_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg){	unsigned long flags;	u32 r; 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);	WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));	r = RREG32(mmUVD_CTX_DATA);	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);	return r;} static void cik_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v){	unsigned long flags; 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);	WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));	WREG32(mmUVD_CTX_DATA, (v));	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);} static u32 cik_didt_rreg(struct amdgpu_device *adev, u32 reg){	unsigned long flags;	u32 r; 	spin_lock_irqsave(&adev->didt_idx_lock, flags);	WREG32(mmDIDT_IND_INDEX, (reg));	r = RREG32(mmDIDT_IND_DATA);	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);	return r;} static void cik_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v){	unsigned long flags; 	spin_lock_irqsave(&adev->didt_idx_lock, flags);	WREG32(mmDIDT_IND_INDEX, (reg));	WREG32(mmDIDT_IND_DATA, (v));	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);} static const u32 bonaire_golden_spm_registers[] ={	0xc200, 0xe0ffffff, 0xe0000000}; static const u32 bonaire_golden_common_registers[] ={	0x31dc, 0xffffffff, 0x00000800,	0x31dd, 0xffffffff, 0x00000800,	0x31e6, 0xffffffff, 0x00007fbf,	0x31e7, 0xffffffff, 0x00007faf}; static const u32 bonaire_golden_registers[] ={	0xcd5, 0x00000333, 0x00000333,	0xcd4, 0x000c0fc0, 0x00040200,	0x2684, 0x00010000, 0x00058208,	0xf000, 0xffff1fff, 0x00140000,	0xf080, 0xfdfc0fff, 0x00000100,	0xf08d, 0x40000000, 0x40000200,	0x260c, 0xffffffff, 0x00000000,	0x260d, 0xf00fffff, 0x00000400,	0x260e, 0x0002021c, 0x00020200,	0x31e, 0x00000080, 0x00000000,	0x16ec, 0x000000f0, 0x00000070,	0x16f0, 0xf0311fff, 0x80300000,	0x263e, 0x73773777, 0x12010001,	0xd43, 0x00810000, 0x408af000,	0x1c0c, 0x31000111, 0x00000011,	0xbd2, 0x73773777, 0x12010001,	0x883, 0x00007fb6, 0x0021a1b1,	0x884, 0x00007fb6, 0x002021b1,	0x860, 0x00007fb6, 0x00002191,	0x886, 0x00007fb6, 0x002121b1,	0x887, 0x00007fb6, 0x002021b1,	0x877, 0x00007fb6, 0x00002191,	0x878, 0x00007fb6, 0x00002191,	0xd8a, 0x0000003f, 0x0000000a,	0xd8b, 0x0000003f, 0x0000000a,	0xab9, 0x00073ffe, 0x000022a2,	0x903, 0x000007ff, 0x00000000,	0x2285, 0xf000003f, 0x00000007,	0x22fc, 0x00002001, 0x00000001,	0x22c9, 0xffffffff, 0x00ffffff,	0xc281, 0x0000ff0f, 0x00000000,	0xa293, 0x07ffffff, 0x06000000,	0x136, 0x00000fff, 0x00000100,	0xf9e, 0x00000001, 0x00000002,	0x2440, 0x03000000, 0x0362c688,	0x2300, 0x000000ff, 0x00000001,	0x390, 0x00001fff, 0x00001fff,	0x2418, 0x0000007f, 0x00000020,	0x2542, 0x00010000, 0x00010000,	0x2b05, 0x000003ff, 0x000000f3,	0x2b03, 0xffffffff, 0x00001032}; static const u32 bonaire_mgcg_cgcg_init[] ={	0x3108, 0xffffffff, 0xfffffffc,	0xc200, 0xffffffff, 0xe0000000,	0xf0a8, 0xffffffff, 0x00000100,	0xf082, 0xffffffff, 0x00000100,	0xf0b0, 0xffffffff, 0xc0000100,	0xf0b2, 0xffffffff, 0xc0000100,	0xf0b1, 0xffffffff, 0xc0000100,	0x1579, 0xffffffff, 0x00600100,	0xf0a0, 0xffffffff, 0x00000100,	0xf085, 0xffffffff, 0x06000100,	0xf088, 0xffffffff, 0x00000100,	0xf086, 0xffffffff, 0x06000100,	0xf081, 0xffffffff, 0x00000100,	0xf0b8, 0xffffffff, 0x00000100,	0xf089, 0xffffffff, 0x00000100,	0xf080, 0xffffffff, 0x00000100,	0xf08c, 0xffffffff, 0x00000100,	0xf08d, 0xffffffff, 0x00000100,	0xf094, 0xffffffff, 0x00000100,	0xf095, 0xffffffff, 0x00000100,	0xf096, 0xffffffff, 0x00000100,	0xf097, 0xffffffff, 0x00000100,	0xf098, 0xffffffff, 0x00000100,	0xf09f, 0xffffffff, 0x00000100,	0xf09e, 0xffffffff, 0x00000100,	0xf084, 0xffffffff, 0x06000100,	0xf0a4, 0xffffffff, 0x00000100,	0xf09d, 0xffffffff, 0x00000100,	0xf0ad, 0xffffffff, 0x00000100,	0xf0ac, 0xffffffff, 0x00000100,	0xf09c, 0xffffffff, 0x00000100,	0xc200, 0xffffffff, 0xe0000000,	0xf008, 0xffffffff, 0x00010000,	0xf009, 0xffffffff, 0x00030002,	0xf00a, 0xffffffff, 0x00040007,	0xf00b, 0xffffffff, 0x00060005,	0xf00c, 0xffffffff, 0x00090008,	0xf00d, 0xffffffff, 0x00010000,	0xf00e, 0xffffffff, 0x00030002,	0xf00f, 0xffffffff, 0x00040007,	0xf010, 0xffffffff, 0x00060005,	0xf011, 0xffffffff, 0x00090008,	0xf012, 0xffffffff, 0x00010000,	0xf013, 0xffffffff, 0x00030002,	0xf014, 0xffffffff, 0x00040007,	0xf015, 0xffffffff, 0x00060005,	0xf016, 0xffffffff, 0x00090008,	0xf017, 0xffffffff, 0x00010000,	0xf018, 0xffffffff, 0x00030002,	0xf019, 0xffffffff, 0x00040007,	0xf01a, 0xffffffff, 0x00060005,	0xf01b, 0xffffffff, 0x00090008,	0xf01c, 0xffffffff, 0x00010000,	0xf01d, 0xffffffff, 0x00030002,	0xf01e, 0xffffffff, 0x00040007,	0xf01f, 0xffffffff, 0x00060005,	0xf020, 0xffffffff, 0x00090008,	0xf021, 0xffffffff, 0x00010000,	0xf022, 0xffffffff, 0x00030002,	0xf023, 0xffffffff, 0x00040007,	0xf024, 0xffffffff, 0x00060005,	0xf025, 0xffffffff, 0x00090008,	0xf026, 0xffffffff, 0x00010000,	0xf027, 0xffffffff, 0x00030002,	0xf028, 0xffffffff, 0x00040007,	0xf029, 0xffffffff, 0x00060005,	0xf02a, 0xffffffff, 0x00090008,	0xf000, 0xffffffff, 0x96e00200,	0x21c2, 0xffffffff, 0x00900100,	0x3109, 0xffffffff, 0x0020003f,	0xe, 0xffffffff, 0x0140001c,	0xf, 0x000f0000, 0x000f0000,	0x88, 0xffffffff, 0xc060000c,	0x89, 0xc0000fff, 0x00000100,	0x3e4, 0xffffffff, 0x00000100,	0x3e6, 0x00000101, 0x00000000,	0x82a, 0xffffffff, 0x00000104,	0x1579, 0xff000fff, 0x00000100,	0xc33, 0xc0000fff, 0x00000104,	0x3079, 0x00000001, 0x00000001,	0x3403, 0xff000ff0, 0x00000100,	0x3603, 0xff000ff0, 0x00000100}; static const u32 spectre_golden_spm_registers[] ={	0xc200, 0xe0ffffff, 0xe0000000}; static const u32 spectre_golden_common_registers[] ={	0x31dc, 0xffffffff, 0x00000800,	0x31dd, 0xffffffff, 0x00000800,	0x31e6, 0xffffffff, 0x00007fbf,	0x31e7, 0xffffffff, 0x00007faf}; static const u32 spectre_golden_registers[] ={	0xf000, 0xffff1fff, 0x96940200,	0xf003, 0xffff0001, 0xff000000,	0xf080, 0xfffc0fff, 0x00000100,	0x1bb6, 0x00010101, 0x00010000,	0x260d, 0xf00fffff, 0x00000400,	0x260e, 0xfffffffc, 0x00020200,	0x16ec, 0x000000f0, 0x00000070,	0x16f0, 0xf0311fff, 0x80300000,	0x263e, 0x73773777, 0x12010001,	0x26df, 0x00ff0000, 0x00fc0000,	0xbd2, 0x73773777, 0x12010001,	0x2285, 0xf000003f, 0x00000007,	0x22c9, 0xffffffff, 0x00ffffff,	0xa0d4, 0x3f3f3fff, 0x00000082,	0xa0d5, 0x0000003f, 0x00000000,	0xf9e, 0x00000001, 0x00000002,	0x244f, 0xffff03df, 0x00000004,	0x31da, 0x00000008, 0x00000008,	0x2300, 0x000008ff, 0x00000800,	0x2542, 0x00010000, 0x00010000,	0x2b03, 0xffffffff, 0x54763210,	0x853e, 0x01ff01ff, 0x00000002,	0x8526, 0x007ff800, 0x00200000,	0x8057, 0xffffffff, 0x00000f40,	0xc24d, 0xffffffff, 0x00000001}; static const u32 spectre_mgcg_cgcg_init[] ={	0x3108, 0xffffffff, 0xfffffffc,	0xc200, 0xffffffff, 0xe0000000,	0xf0a8, 0xffffffff, 0x00000100,	0xf082, 0xffffffff, 0x00000100,	0xf0b0, 0xffffffff, 0x00000100,	0xf0b2, 0xffffffff, 0x00000100,	0xf0b1, 0xffffffff, 0x00000100,	0x1579, 0xffffffff, 0x00600100,	0xf0a0, 0xffffffff, 0x00000100,	0xf085, 0xffffffff, 0x06000100,	0xf088, 0xffffffff, 0x00000100,	0xf086, 0xffffffff, 0x06000100,	0xf081, 0xffffffff, 0x00000100,	0xf0b8, 0xffffffff, 0x00000100,	0xf089, 0xffffffff, 0x00000100,	0xf080, 0xffffffff, 0x00000100,	0xf08c, 0xffffffff, 0x00000100,	0xf08d, 0xffffffff, 0x00000100,	0xf094, 0xffffffff, 0x00000100,	0xf095, 0xffffffff, 0x00000100,	0xf096, 0xffffffff, 0x00000100,	0xf097, 0xffffffff, 0x00000100,	0xf098, 0xffffffff, 0x00000100,	0xf09f, 0xffffffff, 0x00000100,	0xf09e, 0xffffffff, 0x00000100,	0xf084, 0xffffffff, 0x06000100,	0xf0a4, 0xffffffff, 0x00000100,	0xf09d, 0xffffffff, 0x00000100,	0xf0ad, 0xffffffff, 0x00000100,	0xf0ac, 0xffffffff, 0x00000100,	0xf09c, 0xffffffff, 0x00000100,	0xc200, 0xffffffff, 0xe0000000,	0xf008, 0xffffffff, 0x00010000,	0xf009, 0xffffffff, 0x00030002,	0xf00a, 0xffffffff, 0x00040007,	0xf00b, 0xffffffff, 0x00060005,	0xf00c, 0xffffffff, 0x00090008,	0xf00d, 0xffffffff, 0x00010000,	0xf00e, 0xffffffff, 0x00030002,	0xf00f, 0xffffffff, 0x00040007,	0xf010, 0xffffffff, 0x00060005,	0xf011, 0xffffffff, 0x00090008,	0xf012, 0xffffffff, 0x00010000,	0xf013, 0xffffffff, 0x00030002,	0xf014, 0xffffffff, 0x00040007,	0xf015, 0xffffffff, 0x00060005,	0xf016, 0xffffffff, 0x00090008,	0xf017, 0xffffffff, 0x00010000,	0xf018, 0xffffffff, 0x00030002,	0xf019, 0xffffffff, 0x00040007,	0xf01a, 0xffffffff, 0x00060005,	0xf01b, 0xffffffff, 0x00090008,	0xf01c, 0xffffffff, 0x00010000,	0xf01d, 0xffffffff, 0x00030002,	0xf01e, 0xffffffff, 0x00040007,	0xf01f, 0xffffffff, 0x00060005,	0xf020, 0xffffffff, 0x00090008,	0xf021, 0xffffffff, 0x00010000,	0xf022, 0xffffffff, 0x00030002,	0xf023, 0xffffffff, 0x00040007,	0xf024, 0xffffffff, 0x00060005,	0xf025, 0xffffffff, 0x00090008,	0xf026, 0xffffffff, 0x00010000,	0xf027, 0xffffffff, 0x00030002,	0xf028, 0xffffffff, 0x00040007,	0xf029, 0xffffffff, 0x00060005,	0xf02a, 0xffffffff, 0x00090008,	0xf02b, 0xffffffff, 0x00010000,	0xf02c, 0xffffffff, 0x00030002,	0xf02d, 0xffffffff, 0x00040007,

Lines 1–500 of 2333.