Home | History | Annotate | Line # | Download | only in amdgpu
      1  1.3  riastrad /*	$NetBSD: amdgpu_soc15.c,v 1.3 2021/12/19 12:21:29 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2016 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  */
     25  1.1  riastrad #include <sys/cdefs.h>
     26  1.3  riastrad __KERNEL_RCSID(0, "$NetBSD: amdgpu_soc15.c,v 1.3 2021/12/19 12:21:29 riastradh Exp $");
     27  1.1  riastrad 
     28  1.1  riastrad #include <linux/firmware.h>
     29  1.1  riastrad #include <linux/slab.h>
     30  1.1  riastrad #include <linux/module.h>
     31  1.1  riastrad #include <linux/pci.h>
     32  1.1  riastrad 
     33  1.1  riastrad #include "amdgpu.h"
     34  1.1  riastrad #include "amdgpu_atombios.h"
     35  1.1  riastrad #include "amdgpu_ih.h"
     36  1.1  riastrad #include "amdgpu_uvd.h"
     37  1.1  riastrad #include "amdgpu_vce.h"
     38  1.1  riastrad #include "amdgpu_ucode.h"
     39  1.1  riastrad #include "amdgpu_psp.h"
     40  1.1  riastrad #include "atom.h"
     41  1.1  riastrad #include "amd_pcie.h"
     42  1.1  riastrad 
     43  1.1  riastrad #include "uvd/uvd_7_0_offset.h"
     44  1.1  riastrad #include "gc/gc_9_0_offset.h"
     45  1.1  riastrad #include "gc/gc_9_0_sh_mask.h"
     46  1.1  riastrad #include "sdma0/sdma0_4_0_offset.h"
     47  1.1  riastrad #include "sdma1/sdma1_4_0_offset.h"
     48  1.1  riastrad #include "hdp/hdp_4_0_offset.h"
     49  1.1  riastrad #include "hdp/hdp_4_0_sh_mask.h"
     50  1.1  riastrad #include "smuio/smuio_9_0_offset.h"
     51  1.1  riastrad #include "smuio/smuio_9_0_sh_mask.h"
     52  1.1  riastrad #include "nbio/nbio_7_0_default.h"
     53  1.1  riastrad #include "nbio/nbio_7_0_offset.h"
     54  1.1  riastrad #include "nbio/nbio_7_0_sh_mask.h"
     55  1.1  riastrad #include "nbio/nbio_7_0_smn.h"
     56  1.1  riastrad #include "mp/mp_9_0_offset.h"
     57  1.1  riastrad 
     58  1.1  riastrad #include "soc15.h"
     59  1.1  riastrad #include "soc15_common.h"
     60  1.1  riastrad #include "gfx_v9_0.h"
     61  1.1  riastrad #include "gmc_v9_0.h"
     62  1.1  riastrad #include "gfxhub_v1_0.h"
     63  1.1  riastrad #include "mmhub_v1_0.h"
     64  1.1  riastrad #include "df_v1_7.h"
     65  1.1  riastrad #include "df_v3_6.h"
     66  1.1  riastrad #include "nbio_v6_1.h"
     67  1.1  riastrad #include "nbio_v7_0.h"
     68  1.1  riastrad #include "nbio_v7_4.h"
     69  1.1  riastrad #include "vega10_ih.h"
     70  1.1  riastrad #include "sdma_v4_0.h"
     71  1.1  riastrad #include "uvd_v7_0.h"
     72  1.1  riastrad #include "vce_v4_0.h"
     73  1.1  riastrad #include "vcn_v1_0.h"
     74  1.1  riastrad #include "vcn_v2_0.h"
     75  1.1  riastrad #include "jpeg_v2_0.h"
     76  1.1  riastrad #include "vcn_v2_5.h"
     77  1.1  riastrad #include "jpeg_v2_5.h"
     78  1.1  riastrad #include "dce_virtual.h"
     79  1.1  riastrad #include "mxgpu_ai.h"
     80  1.1  riastrad #include "amdgpu_smu.h"
     81  1.1  riastrad #include "amdgpu_ras.h"
     82  1.1  riastrad #include "amdgpu_xgmi.h"
     83  1.1  riastrad #include <uapi/linux/kfd_ioctl.h>
     84  1.1  riastrad 
     85  1.3  riastrad #include <linux/nbsd-namespace.h>
     86  1.3  riastrad 
     87  1.1  riastrad #define mmMP0_MISC_CGTT_CTRL0                                                                   0x01b9
     88  1.1  riastrad #define mmMP0_MISC_CGTT_CTRL0_BASE_IDX                                                          0
     89  1.1  riastrad #define mmMP0_MISC_LIGHT_SLEEP_CTRL                                                             0x01ba
     90  1.1  riastrad #define mmMP0_MISC_LIGHT_SLEEP_CTRL_BASE_IDX                                                    0
     91  1.1  riastrad 
     92  1.1  riastrad /* for Vega20 register name change */
     93  1.1  riastrad #define mmHDP_MEM_POWER_CTRL	0x00d4
     94  1.1  riastrad #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK	0x00000001L
     95  1.1  riastrad #define HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK	0x00000002L
     96  1.1  riastrad #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK	0x00010000L
     97  1.1  riastrad #define HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK		0x00020000L
     98  1.1  riastrad #define mmHDP_MEM_POWER_CTRL_BASE_IDX	0
     99  1.1  riastrad /*
    100  1.1  riastrad  * Indirect registers accessor
    101  1.1  riastrad  */
    102  1.1  riastrad static u32 soc15_pcie_rreg(struct amdgpu_device *adev, u32 reg)
    103  1.1  riastrad {
    104  1.1  riastrad 	unsigned long flags, address, data;
    105  1.1  riastrad 	u32 r;
    106  1.1  riastrad 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
    107  1.1  riastrad 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
    108  1.1  riastrad 
    109  1.1  riastrad 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
    110  1.1  riastrad 	WREG32(address, reg);
    111  1.1  riastrad 	(void)RREG32(address);
    112  1.1  riastrad 	r = RREG32(data);
    113  1.1  riastrad 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
    114  1.1  riastrad 	return r;
    115  1.1  riastrad }
    116  1.1  riastrad 
    117  1.1  riastrad static void soc15_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
    118  1.1  riastrad {
    119  1.1  riastrad 	unsigned long flags, address, data;
    120  1.1  riastrad 
    121  1.1  riastrad 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
    122  1.1  riastrad 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
    123  1.1  riastrad 
    124  1.1  riastrad 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
    125  1.1  riastrad 	WREG32(address, reg);
    126  1.1  riastrad 	(void)RREG32(address);
    127  1.1  riastrad 	WREG32(data, v);
    128  1.1  riastrad 	(void)RREG32(data);
    129  1.1  riastrad 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
    130  1.1  riastrad }
    131  1.1  riastrad 
    132  1.1  riastrad static u64 soc15_pcie_rreg64(struct amdgpu_device *adev, u32 reg)
    133  1.1  riastrad {
    134  1.1  riastrad 	unsigned long flags, address, data;
    135  1.1  riastrad 	u64 r;
    136  1.1  riastrad 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
    137  1.1  riastrad 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
    138  1.1  riastrad 
    139  1.1  riastrad 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
    140  1.1  riastrad 	/* read low 32 bit */
    141  1.1  riastrad 	WREG32(address, reg);
    142  1.1  riastrad 	(void)RREG32(address);
    143  1.1  riastrad 	r = RREG32(data);
    144  1.1  riastrad 
    145  1.1  riastrad 	/* read high 32 bit*/
    146  1.1  riastrad 	WREG32(address, reg + 4);
    147  1.1  riastrad 	(void)RREG32(address);
    148  1.1  riastrad 	r |= ((u64)RREG32(data) << 32);
    149  1.1  riastrad 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
    150  1.1  riastrad 	return r;
    151  1.1  riastrad }
    152  1.1  riastrad 
    153  1.1  riastrad static void soc15_pcie_wreg64(struct amdgpu_device *adev, u32 reg, u64 v)
    154  1.1  riastrad {
    155  1.1  riastrad 	unsigned long flags, address, data;
    156  1.1  riastrad 
    157  1.1  riastrad 	address = adev->nbio.funcs->get_pcie_index_offset(adev);
    158  1.1  riastrad 	data = adev->nbio.funcs->get_pcie_data_offset(adev);
    159  1.1  riastrad 
    160  1.1  riastrad 	spin_lock_irqsave(&adev->pcie_idx_lock, flags);
    161  1.1  riastrad 	/* write low 32 bit */
    162  1.1  riastrad 	WREG32(address, reg);
    163  1.1  riastrad 	(void)RREG32(address);
    164  1.1  riastrad 	WREG32(data, (u32)(v & 0xffffffffULL));
    165  1.1  riastrad 	(void)RREG32(data);
    166  1.1  riastrad 
    167  1.1  riastrad 	/* write high 32 bit */
    168  1.1  riastrad 	WREG32(address, reg + 4);
    169  1.1  riastrad 	(void)RREG32(address);
    170  1.1  riastrad 	WREG32(data, (u32)(v >> 32));
    171  1.1  riastrad 	(void)RREG32(data);
    172  1.1  riastrad 	spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
    173  1.1  riastrad }
    174  1.1  riastrad 
    175  1.1  riastrad static u32 soc15_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
    176  1.1  riastrad {
    177  1.1  riastrad 	unsigned long flags, address, data;
    178  1.1  riastrad 	u32 r;
    179  1.1  riastrad 
    180  1.1  riastrad 	address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
    181  1.1  riastrad 	data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
    182  1.1  riastrad 
    183  1.1  riastrad 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
    184  1.1  riastrad 	WREG32(address, ((reg) & 0x1ff));
    185  1.1  riastrad 	r = RREG32(data);
    186  1.1  riastrad 	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
    187  1.1  riastrad 	return r;
    188  1.1  riastrad }
    189  1.1  riastrad 
    190  1.1  riastrad static void soc15_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
    191  1.1  riastrad {
    192  1.1  riastrad 	unsigned long flags, address, data;
    193  1.1  riastrad 
    194  1.1  riastrad 	address = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_INDEX);
    195  1.1  riastrad 	data = SOC15_REG_OFFSET(UVD, 0, mmUVD_CTX_DATA);
    196  1.1  riastrad 
    197  1.1  riastrad 	spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
    198  1.1  riastrad 	WREG32(address, ((reg) & 0x1ff));
    199  1.1  riastrad 	WREG32(data, (v));
    200  1.1  riastrad 	spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
    201  1.1  riastrad }
    202  1.1  riastrad 
    203  1.1  riastrad static u32 soc15_didt_rreg(struct amdgpu_device *adev, u32 reg)
    204  1.1  riastrad {
    205  1.1  riastrad 	unsigned long flags, address, data;
    206  1.1  riastrad 	u32 r;
    207  1.1  riastrad 
    208  1.1  riastrad 	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
    209  1.1  riastrad 	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
    210  1.1  riastrad 
    211  1.1  riastrad 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
    212  1.1  riastrad 	WREG32(address, (reg));
    213  1.1  riastrad 	r = RREG32(data);
    214  1.1  riastrad 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
    215  1.1  riastrad 	return r;
    216  1.1  riastrad }
    217  1.1  riastrad 
    218  1.1  riastrad static void soc15_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
    219  1.1  riastrad {
    220  1.1  riastrad 	unsigned long flags, address, data;
    221  1.1  riastrad 
    222  1.1  riastrad 	address = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_INDEX);
    223  1.1  riastrad 	data = SOC15_REG_OFFSET(GC, 0, mmDIDT_IND_DATA);
    224  1.1  riastrad 
    225  1.1  riastrad 	spin_lock_irqsave(&adev->didt_idx_lock, flags);
    226  1.1  riastrad 	WREG32(address, (reg));
    227  1.1  riastrad 	WREG32(data, (v));
    228  1.1  riastrad 	spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
    229  1.1  riastrad }
    230  1.1  riastrad 
    231  1.1  riastrad static u32 soc15_gc_cac_rreg(struct amdgpu_device *adev, u32 reg)
    232  1.1  riastrad {
    233  1.1  riastrad 	unsigned long flags;
    234  1.1  riastrad 	u32 r;
    235  1.1  riastrad 
    236  1.1  riastrad 	spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
    237  1.1  riastrad 	WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
    238  1.1  riastrad 	r = RREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA);
    239  1.1  riastrad 	spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
    240  1.1  riastrad 	return r;
    241  1.1  riastrad }
    242  1.1  riastrad 
    243  1.1  riastrad static void soc15_gc_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
    244  1.1  riastrad {
    245  1.1  riastrad 	unsigned long flags;
    246  1.1  riastrad 
    247  1.1  riastrad 	spin_lock_irqsave(&adev->gc_cac_idx_lock, flags);
    248  1.1  riastrad 	WREG32_SOC15(GC, 0, mmGC_CAC_IND_INDEX, (reg));
    249  1.1  riastrad 	WREG32_SOC15(GC, 0, mmGC_CAC_IND_DATA, (v));
    250  1.1  riastrad 	spin_unlock_irqrestore(&adev->gc_cac_idx_lock, flags);
    251  1.1  riastrad }
    252  1.1  riastrad 
    253  1.1  riastrad static u32 soc15_se_cac_rreg(struct amdgpu_device *adev, u32 reg)
    254  1.1  riastrad {
    255  1.1  riastrad 	unsigned long flags;
    256  1.1  riastrad 	u32 r;
    257  1.1  riastrad 
    258  1.1  riastrad 	spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
    259  1.1  riastrad 	WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
    260  1.1  riastrad 	r = RREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA);
    261  1.1  riastrad 	spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
    262  1.1  riastrad 	return r;
    263  1.1  riastrad }
    264  1.1  riastrad 
    265  1.1  riastrad static void soc15_se_cac_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
    266  1.1  riastrad {
    267  1.1  riastrad 	unsigned long flags;
    268  1.1  riastrad 
    269  1.1  riastrad 	spin_lock_irqsave(&adev->se_cac_idx_lock, flags);
    270  1.1  riastrad 	WREG32_SOC15(GC, 0, mmSE_CAC_IND_INDEX, (reg));
    271  1.1  riastrad 	WREG32_SOC15(GC, 0, mmSE_CAC_IND_DATA, (v));
    272  1.1  riastrad 	spin_unlock_irqrestore(&adev->se_cac_idx_lock, flags);
    273  1.1  riastrad }
    274  1.1  riastrad 
    275  1.1  riastrad static u32 soc15_get_config_memsize(struct amdgpu_device *adev)
    276  1.1  riastrad {
    277  1.1  riastrad 	return adev->nbio.funcs->get_memsize(adev);
    278  1.1  riastrad }
    279  1.1  riastrad 
    280  1.1  riastrad static u32 soc15_get_xclk(struct amdgpu_device *adev)
    281  1.1  riastrad {
    282  1.1  riastrad 	u32 reference_clock = adev->clock.spll.reference_freq;
    283  1.1  riastrad 
    284  1.1  riastrad 	if (adev->asic_type == CHIP_RAVEN)
    285  1.1  riastrad 		return reference_clock / 4;
    286  1.1  riastrad 
    287  1.1  riastrad 	return reference_clock;
    288  1.1  riastrad }
    289  1.1  riastrad 
    290  1.1  riastrad 
    291  1.1  riastrad void soc15_grbm_select(struct amdgpu_device *adev,
    292  1.1  riastrad 		     u32 me, u32 pipe, u32 queue, u32 vmid)
    293  1.1  riastrad {
    294  1.1  riastrad 	u32 grbm_gfx_cntl = 0;
    295  1.1  riastrad 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, PIPEID, pipe);
    296  1.1  riastrad 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, MEID, me);
    297  1.1  riastrad 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, VMID, vmid);
    298  1.1  riastrad 	grbm_gfx_cntl = REG_SET_FIELD(grbm_gfx_cntl, GRBM_GFX_CNTL, QUEUEID, queue);
    299  1.1  riastrad 
    300  1.1  riastrad 	WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_CNTL, grbm_gfx_cntl);
    301  1.1  riastrad }
    302  1.1  riastrad 
    303  1.1  riastrad static void soc15_vga_set_state(struct amdgpu_device *adev, bool state)
    304  1.1  riastrad {
    305  1.1  riastrad 	/* todo */
    306  1.1  riastrad }
    307  1.1  riastrad 
    308  1.1  riastrad static bool soc15_read_disabled_bios(struct amdgpu_device *adev)
    309  1.1  riastrad {
    310  1.1  riastrad 	/* todo */
    311  1.1  riastrad 	return false;
    312  1.1  riastrad }
    313  1.1  riastrad 
    314  1.1  riastrad static bool soc15_read_bios_from_rom(struct amdgpu_device *adev,
    315  1.1  riastrad 				     u8 *bios, u32 length_bytes)
    316  1.1  riastrad {
    317  1.1  riastrad 	u32 *dw_ptr;
    318  1.1  riastrad 	u32 i, length_dw;
    319  1.1  riastrad 
    320  1.1  riastrad 	if (bios == NULL)
    321  1.1  riastrad 		return false;
    322  1.1  riastrad 	if (length_bytes == 0)
    323  1.1  riastrad 		return false;
    324  1.1  riastrad 	/* APU vbios image is part of sbios image */
    325  1.1  riastrad 	if (adev->flags & AMD_IS_APU)
    326  1.1  riastrad 		return false;
    327  1.1  riastrad 
    328  1.1  riastrad 	dw_ptr = (u32 *)bios;
    329  1.1  riastrad 	length_dw = ALIGN(length_bytes, 4) / 4;
    330  1.1  riastrad 
    331  1.1  riastrad 	/* set rom index to 0 */
    332  1.1  riastrad 	WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_INDEX), 0);
    333  1.1  riastrad 	/* read out the rom data */
    334  1.1  riastrad 	for (i = 0; i < length_dw; i++)
    335  1.1  riastrad 		dw_ptr[i] = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmROM_DATA));
    336  1.1  riastrad 
    337  1.1  riastrad 	return true;
    338  1.1  riastrad }
    339  1.1  riastrad 
    340  1.1  riastrad static struct soc15_allowed_register_entry soc15_allowed_read_registers[] = {
    341  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS)},
    342  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS2)},
    343  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE0)},
    344  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE1)},
    345  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE2)},
    346  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGRBM_STATUS_SE3)},
    347  1.1  riastrad 	{ SOC15_REG_ENTRY(SDMA0, 0, mmSDMA0_STATUS_REG)},
    348  1.1  riastrad 	{ SOC15_REG_ENTRY(SDMA1, 0, mmSDMA1_STATUS_REG)},
    349  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STAT)},
    350  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT1)},
    351  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT2)},
    352  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_STALLED_STAT3)},
    353  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_BUSY_STAT)},
    354  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STALLED_STAT1)},
    355  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPF_STATUS)},
    356  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_BUSY_STAT)},
    357  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STALLED_STAT1)},
    358  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmCP_CPC_STATUS)},
    359  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmGB_ADDR_CONFIG)},
    360  1.1  riastrad 	{ SOC15_REG_ENTRY(GC, 0, mmDB_DEBUG2)},
    361  1.1  riastrad };
    362  1.1  riastrad 
    363  1.1  riastrad static uint32_t soc15_read_indexed_register(struct amdgpu_device *adev, u32 se_num,
    364  1.1  riastrad 					 u32 sh_num, u32 reg_offset)
    365  1.1  riastrad {
    366  1.1  riastrad 	uint32_t val;
    367  1.1  riastrad 
    368  1.1  riastrad 	mutex_lock(&adev->grbm_idx_mutex);
    369  1.1  riastrad 	if (se_num != 0xffffffff || sh_num != 0xffffffff)
    370  1.1  riastrad 		amdgpu_gfx_select_se_sh(adev, se_num, sh_num, 0xffffffff);
    371  1.1  riastrad 
    372  1.1  riastrad 	val = RREG32(reg_offset);
    373  1.1  riastrad 
    374  1.1  riastrad 	if (se_num != 0xffffffff || sh_num != 0xffffffff)
    375  1.1  riastrad 		amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
    376  1.1  riastrad 	mutex_unlock(&adev->grbm_idx_mutex);
    377  1.1  riastrad 	return val;
    378  1.1  riastrad }
    379  1.1  riastrad 
    380  1.1  riastrad static uint32_t soc15_get_register_value(struct amdgpu_device *adev,
    381  1.1  riastrad 					 bool indexed, u32 se_num,
    382  1.1  riastrad 					 u32 sh_num, u32 reg_offset)
    383  1.1  riastrad {
    384  1.1  riastrad 	if (indexed) {
    385  1.1  riastrad 		return soc15_read_indexed_register(adev, se_num, sh_num, reg_offset);
    386  1.1  riastrad 	} else {
    387  1.1  riastrad 		if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmGB_ADDR_CONFIG))
    388  1.1  riastrad 			return adev->gfx.config.gb_addr_config;
    389  1.1  riastrad 		else if (reg_offset == SOC15_REG_OFFSET(GC, 0, mmDB_DEBUG2))
    390  1.1  riastrad 			return adev->gfx.config.db_debug2;
    391  1.1  riastrad 		return RREG32(reg_offset);
    392  1.1  riastrad 	}
    393  1.1  riastrad }
    394  1.1  riastrad 
    395  1.1  riastrad static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,
    396  1.1  riastrad 			    u32 sh_num, u32 reg_offset, u32 *value)
    397  1.1  riastrad {
    398  1.1  riastrad 	uint32_t i;
    399  1.1  riastrad 	struct soc15_allowed_register_entry  *en;
    400  1.1  riastrad 
    401  1.1  riastrad 	*value = 0;
    402  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(soc15_allowed_read_registers); i++) {
    403  1.1  riastrad 		en = &soc15_allowed_read_registers[i];
    404  1.1  riastrad 		if (reg_offset != (adev->reg_offset[en->hwip][en->inst][en->seg]
    405  1.1  riastrad 					+ en->reg_offset))
    406  1.1  riastrad 			continue;
    407  1.1  riastrad 
    408  1.1  riastrad 		*value = soc15_get_register_value(adev,
    409  1.1  riastrad 						  soc15_allowed_read_registers[i].grbm_indexed,
    410  1.1  riastrad 						  se_num, sh_num, reg_offset);
    411  1.1  riastrad 		return 0;
    412  1.1  riastrad 	}
    413  1.1  riastrad 	return -EINVAL;
    414  1.1  riastrad }
    415  1.1  riastrad 
    416  1.1  riastrad 
    417  1.1  riastrad /**
    418  1.1  riastrad  * soc15_program_register_sequence - program an array of registers.
    419  1.1  riastrad  *
    420  1.1  riastrad  * @adev: amdgpu_device pointer
    421  1.1  riastrad  * @regs: pointer to the register array
    422  1.1  riastrad  * @array_size: size of the register array
    423  1.1  riastrad  *
    424  1.1  riastrad  * Programs an array or registers with and and or masks.
    425  1.1  riastrad  * This is a helper for setting golden registers.
    426  1.1  riastrad  */
    427  1.1  riastrad 
    428  1.1  riastrad void soc15_program_register_sequence(struct amdgpu_device *adev,
    429  1.1  riastrad 					     const struct soc15_reg_golden *regs,
    430  1.1  riastrad 					     const u32 array_size)
    431  1.1  riastrad {
    432  1.1  riastrad 	const struct soc15_reg_golden *entry;
    433  1.1  riastrad 	u32 tmp, reg;
    434  1.1  riastrad 	int i;
    435  1.1  riastrad 
    436  1.1  riastrad 	for (i = 0; i < array_size; ++i) {
    437  1.1  riastrad 		entry = &regs[i];
    438  1.1  riastrad 		reg =  adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
    439  1.1  riastrad 
    440  1.1  riastrad 		if (entry->and_mask == 0xffffffff) {
    441  1.1  riastrad 			tmp = entry->or_mask;
    442  1.1  riastrad 		} else {
    443  1.1  riastrad 			tmp = RREG32(reg);
    444  1.1  riastrad 			tmp &= ~(entry->and_mask);
    445  1.1  riastrad 			tmp |= (entry->or_mask & entry->and_mask);
    446  1.1  riastrad 		}
    447  1.1  riastrad 
    448  1.1  riastrad 		if (reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_BINNER_EVENT_CNTL_3) ||
    449  1.1  riastrad 			reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE) ||
    450  1.1  riastrad 			reg == SOC15_REG_OFFSET(GC, 0, mmPA_SC_ENHANCE_1) ||
    451  1.1  riastrad 			reg == SOC15_REG_OFFSET(GC, 0, mmSH_MEM_CONFIG))
    452  1.1  riastrad 			WREG32_RLC(reg, tmp);
    453  1.1  riastrad 		else
    454  1.1  riastrad 			WREG32(reg, tmp);
    455  1.1  riastrad 
    456  1.1  riastrad 	}
    457  1.1  riastrad 
    458  1.1  riastrad }
    459  1.1  riastrad 
    460  1.1  riastrad static int soc15_asic_mode1_reset(struct amdgpu_device *adev)
    461  1.1  riastrad {
    462  1.1  riastrad 	u32 i;
    463  1.1  riastrad 	int ret = 0;
    464  1.1  riastrad 
    465  1.1  riastrad 	amdgpu_atombios_scratch_regs_engine_hung(adev, true);
    466  1.1  riastrad 
    467  1.1  riastrad 	dev_info(adev->dev, "GPU mode1 reset\n");
    468  1.1  riastrad 
    469  1.1  riastrad 	/* disable BM */
    470  1.1  riastrad 	pci_clear_master(adev->pdev);
    471  1.1  riastrad 
    472  1.1  riastrad 	pci_save_state(adev->pdev);
    473  1.1  riastrad 
    474  1.1  riastrad 	ret = psp_gpu_reset(adev);
    475  1.1  riastrad 	if (ret)
    476  1.1  riastrad 		dev_err(adev->dev, "GPU mode1 reset failed\n");
    477  1.1  riastrad 
    478  1.1  riastrad 	pci_restore_state(adev->pdev);
    479  1.1  riastrad 
    480  1.1  riastrad 	/* wait for asic to come out of reset */
    481  1.1  riastrad 	for (i = 0; i < adev->usec_timeout; i++) {
    482  1.1  riastrad 		u32 memsize = adev->nbio.funcs->get_memsize(adev);
    483  1.1  riastrad 
    484  1.1  riastrad 		if (memsize != 0xffffffff)
    485  1.1  riastrad 			break;
    486  1.1  riastrad 		udelay(1);
    487  1.1  riastrad 	}
    488  1.1  riastrad 
    489  1.1  riastrad 	amdgpu_atombios_scratch_regs_engine_hung(adev, false);
    490  1.1  riastrad 
    491  1.1  riastrad 	return ret;
    492  1.1  riastrad }
    493  1.1  riastrad 
    494  1.1  riastrad static int soc15_asic_baco_reset(struct amdgpu_device *adev)
    495  1.1  riastrad {
    496  1.1  riastrad 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
    497  1.1  riastrad 	int ret = 0;
    498  1.1  riastrad 
    499  1.1  riastrad 	/* avoid NBIF got stuck when do RAS recovery in BACO reset */
    500  1.1  riastrad 	if (ras && ras->supported)
    501  1.1  riastrad 		adev->nbio.funcs->enable_doorbell_interrupt(adev, false);
    502  1.1  riastrad 
    503  1.1  riastrad 	ret = amdgpu_dpm_baco_reset(adev);
    504  1.1  riastrad 	if (ret)
    505  1.1  riastrad 		return ret;
    506  1.1  riastrad 
    507  1.1  riastrad 	/* re-enable doorbell interrupt after BACO exit */
    508  1.1  riastrad 	if (ras && ras->supported)
    509  1.1  riastrad 		adev->nbio.funcs->enable_doorbell_interrupt(adev, true);
    510  1.1  riastrad 
    511  1.1  riastrad 	return 0;
    512  1.1  riastrad }
    513  1.1  riastrad 
    514  1.1  riastrad static enum amd_reset_method
    515  1.1  riastrad soc15_asic_reset_method(struct amdgpu_device *adev)
    516  1.1  riastrad {
    517  1.1  riastrad 	bool baco_reset = false;
    518  1.1  riastrad 	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
    519  1.1  riastrad 
    520  1.1  riastrad 	switch (adev->asic_type) {
    521  1.1  riastrad 	case CHIP_RAVEN:
    522  1.1  riastrad 	case CHIP_RENOIR:
    523  1.1  riastrad 		return AMD_RESET_METHOD_MODE2;
    524  1.1  riastrad 	case CHIP_VEGA10:
    525  1.1  riastrad 	case CHIP_VEGA12:
    526  1.1  riastrad 	case CHIP_ARCTURUS:
    527  1.1  riastrad 		baco_reset = amdgpu_dpm_is_baco_supported(adev);
    528  1.1  riastrad 		break;
    529  1.1  riastrad 	case CHIP_VEGA20:
    530  1.1  riastrad 		if (adev->psp.sos_fw_version >= 0x80067)
    531  1.1  riastrad 			baco_reset = amdgpu_dpm_is_baco_supported(adev);
    532  1.1  riastrad 
    533  1.1  riastrad 		/*
    534  1.1  riastrad 		 * 1. PMFW version > 0x284300: all cases use baco
    535  1.1  riastrad 		 * 2. PMFW version <= 0x284300: only sGPU w/o RAS use baco
    536  1.1  riastrad 		 */
    537  1.1  riastrad 		if ((ras && ras->supported) && adev->pm.fw_version <= 0x283400)
    538  1.1  riastrad 			baco_reset = false;
    539  1.1  riastrad 		break;
    540  1.1  riastrad 	default:
    541  1.1  riastrad 		break;
    542  1.1  riastrad 	}
    543  1.1  riastrad 
    544  1.1  riastrad 	if (baco_reset)
    545  1.1  riastrad 		return AMD_RESET_METHOD_BACO;
    546  1.1  riastrad 	else
    547  1.1  riastrad 		return AMD_RESET_METHOD_MODE1;
    548  1.1  riastrad }
    549  1.1  riastrad 
    550  1.1  riastrad static int soc15_asic_reset(struct amdgpu_device *adev)
    551  1.1  riastrad {
    552  1.1  riastrad 	/* original raven doesn't have full asic reset */
    553  1.1  riastrad 	if (adev->pdev->device == 0x15dd && adev->rev_id < 0x8)
    554  1.1  riastrad 		return 0;
    555  1.1  riastrad 
    556  1.1  riastrad 	switch (soc15_asic_reset_method(adev)) {
    557  1.1  riastrad 		case AMD_RESET_METHOD_BACO:
    558  1.1  riastrad 			if (!adev->in_suspend)
    559  1.1  riastrad 				amdgpu_inc_vram_lost(adev);
    560  1.1  riastrad 			return soc15_asic_baco_reset(adev);
    561  1.1  riastrad 		case AMD_RESET_METHOD_MODE2:
    562  1.1  riastrad 			return amdgpu_dpm_mode2_reset(adev);
    563  1.1  riastrad 		default:
    564  1.1  riastrad 			if (!adev->in_suspend)
    565  1.1  riastrad 				amdgpu_inc_vram_lost(adev);
    566  1.1  riastrad 			return soc15_asic_mode1_reset(adev);
    567  1.1  riastrad 	}
    568  1.1  riastrad }
    569  1.1  riastrad 
    570  1.1  riastrad static bool soc15_supports_baco(struct amdgpu_device *adev)
    571  1.1  riastrad {
    572  1.1  riastrad 	switch (adev->asic_type) {
    573  1.1  riastrad 	case CHIP_VEGA10:
    574  1.1  riastrad 	case CHIP_VEGA12:
    575  1.1  riastrad 	case CHIP_ARCTURUS:
    576  1.1  riastrad 		return amdgpu_dpm_is_baco_supported(adev);
    577  1.1  riastrad 	case CHIP_VEGA20:
    578  1.1  riastrad 		if (adev->psp.sos_fw_version >= 0x80067)
    579  1.1  riastrad 			return amdgpu_dpm_is_baco_supported(adev);
    580  1.1  riastrad 		return false;
    581  1.1  riastrad 	default:
    582  1.1  riastrad 		return false;
    583  1.1  riastrad 	}
    584  1.1  riastrad }
    585  1.1  riastrad 
    586  1.1  riastrad /*static int soc15_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
    587  1.1  riastrad 			u32 cntl_reg, u32 status_reg)
    588  1.1  riastrad {
    589  1.1  riastrad 	return 0;
    590  1.1  riastrad }*/
    591  1.1  riastrad 
    592  1.1  riastrad static int soc15_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
    593  1.1  riastrad {
    594  1.1  riastrad 	/*int r;
    595  1.1  riastrad 
    596  1.1  riastrad 	r = soc15_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
    597  1.1  riastrad 	if (r)
    598  1.1  riastrad 		return r;
    599  1.1  riastrad 
    600  1.1  riastrad 	r = soc15_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
    601  1.1  riastrad 	*/
    602  1.1  riastrad 	return 0;
    603  1.1  riastrad }
    604  1.1  riastrad 
    605  1.1  riastrad static int soc15_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
    606  1.1  riastrad {
    607  1.1  riastrad 	/* todo */
    608  1.1  riastrad 
    609  1.1  riastrad 	return 0;
    610  1.1  riastrad }
    611  1.1  riastrad 
    612  1.1  riastrad static void soc15_pcie_gen3_enable(struct amdgpu_device *adev)
    613  1.1  riastrad {
    614  1.1  riastrad 	if (pci_is_root_bus(adev->pdev->bus))
    615  1.1  riastrad 		return;
    616  1.1  riastrad 
    617  1.1  riastrad 	if (amdgpu_pcie_gen2 == 0)
    618  1.1  riastrad 		return;
    619  1.1  riastrad 
    620  1.1  riastrad 	if (adev->flags & AMD_IS_APU)
    621  1.1  riastrad 		return;
    622  1.1  riastrad 
    623  1.1  riastrad 	if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
    624  1.1  riastrad 					CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
    625  1.1  riastrad 		return;
    626  1.1  riastrad 
    627  1.1  riastrad 	/* todo */
    628  1.1  riastrad }
    629  1.1  riastrad 
    630  1.1  riastrad static void soc15_program_aspm(struct amdgpu_device *adev)
    631  1.1  riastrad {
    632  1.1  riastrad 
    633  1.1  riastrad 	if (amdgpu_aspm == 0)
    634  1.1  riastrad 		return;
    635  1.1  riastrad 
    636  1.1  riastrad 	/* todo */
    637  1.1  riastrad }
    638  1.1  riastrad 
    639  1.1  riastrad static void soc15_enable_doorbell_aperture(struct amdgpu_device *adev,
    640  1.1  riastrad 					   bool enable)
    641  1.1  riastrad {
    642  1.1  riastrad 	adev->nbio.funcs->enable_doorbell_aperture(adev, enable);
    643  1.1  riastrad 	adev->nbio.funcs->enable_doorbell_selfring_aperture(adev, enable);
    644  1.1  riastrad }
    645  1.1  riastrad 
    646  1.1  riastrad static const struct amdgpu_ip_block_version vega10_common_ip_block =
    647  1.1  riastrad {
    648  1.1  riastrad 	.type = AMD_IP_BLOCK_TYPE_COMMON,
    649  1.1  riastrad 	.major = 2,
    650  1.1  riastrad 	.minor = 0,
    651  1.1  riastrad 	.rev = 0,
    652  1.1  riastrad 	.funcs = &soc15_common_ip_funcs,
    653  1.1  riastrad };
    654  1.1  riastrad 
    655  1.1  riastrad static uint32_t soc15_get_rev_id(struct amdgpu_device *adev)
    656  1.1  riastrad {
    657  1.1  riastrad 	return adev->nbio.funcs->get_rev_id(adev);
    658  1.1  riastrad }
    659  1.1  riastrad 
    660  1.1  riastrad int soc15_set_ip_blocks(struct amdgpu_device *adev)
    661  1.1  riastrad {
    662  1.1  riastrad 	/* Set IP register base before any HW register access */
    663  1.1  riastrad 	switch (adev->asic_type) {
    664  1.1  riastrad 	case CHIP_VEGA10:
    665  1.1  riastrad 	case CHIP_VEGA12:
    666  1.1  riastrad 	case CHIP_RAVEN:
    667  1.1  riastrad 	case CHIP_RENOIR:
    668  1.1  riastrad 		vega10_reg_base_init(adev);
    669  1.1  riastrad 		break;
    670  1.1  riastrad 	case CHIP_VEGA20:
    671  1.1  riastrad 		vega20_reg_base_init(adev);
    672  1.1  riastrad 		break;
    673  1.1  riastrad 	case CHIP_ARCTURUS:
    674  1.1  riastrad 		arct_reg_base_init(adev);
    675  1.1  riastrad 		break;
    676  1.1  riastrad 	default:
    677  1.1  riastrad 		return -EINVAL;
    678  1.1  riastrad 	}
    679  1.1  riastrad 
    680  1.1  riastrad 	if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
    681  1.1  riastrad 		adev->gmc.xgmi.supported = true;
    682  1.1  riastrad 
    683  1.1  riastrad 	if (adev->flags & AMD_IS_APU) {
    684  1.1  riastrad 		adev->nbio.funcs = &nbio_v7_0_funcs;
    685  1.1  riastrad 		adev->nbio.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg;
    686  1.1  riastrad 	} else if (adev->asic_type == CHIP_VEGA20 ||
    687  1.1  riastrad 		   adev->asic_type == CHIP_ARCTURUS) {
    688  1.1  riastrad 		adev->nbio.funcs = &nbio_v7_4_funcs;
    689  1.1  riastrad 		adev->nbio.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg;
    690  1.1  riastrad 	} else {
    691  1.1  riastrad 		adev->nbio.funcs = &nbio_v6_1_funcs;
    692  1.1  riastrad 		adev->nbio.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg;
    693  1.1  riastrad 	}
    694  1.1  riastrad 
    695  1.1  riastrad 	if (adev->asic_type == CHIP_VEGA20 || adev->asic_type == CHIP_ARCTURUS)
    696  1.1  riastrad 		adev->df.funcs = &df_v3_6_funcs;
    697  1.1  riastrad 	else
    698  1.1  riastrad 		adev->df.funcs = &df_v1_7_funcs;
    699  1.1  riastrad 
    700  1.1  riastrad 	adev->rev_id = soc15_get_rev_id(adev);
    701  1.1  riastrad 	adev->nbio.funcs->detect_hw_virt(adev);
    702  1.1  riastrad 
    703  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
    704  1.1  riastrad 		adev->virt.ops = &xgpu_ai_virt_ops;
    705  1.1  riastrad 
    706  1.1  riastrad 	switch (adev->asic_type) {
    707  1.1  riastrad 	case CHIP_VEGA10:
    708  1.1  riastrad 	case CHIP_VEGA12:
    709  1.1  riastrad 	case CHIP_VEGA20:
    710  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
    711  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
    712  1.1  riastrad 
    713  1.1  riastrad 		/* For Vega10 SR-IOV, PSP need to be initialized before IH */
    714  1.1  riastrad 		if (amdgpu_sriov_vf(adev)) {
    715  1.1  riastrad 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
    716  1.1  riastrad 				if (adev->asic_type == CHIP_VEGA20)
    717  1.1  riastrad 					amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
    718  1.1  riastrad 				else
    719  1.1  riastrad 					amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
    720  1.1  riastrad 			}
    721  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    722  1.1  riastrad 		} else {
    723  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    724  1.1  riastrad 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
    725  1.1  riastrad 				if (adev->asic_type == CHIP_VEGA20)
    726  1.1  riastrad 					amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
    727  1.1  riastrad 				else
    728  1.1  riastrad 					amdgpu_device_ip_block_add(adev, &psp_v3_1_ip_block);
    729  1.1  riastrad 			}
    730  1.1  riastrad 		}
    731  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
    732  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
    733  1.1  riastrad 		if (is_support_sw_smu(adev)) {
    734  1.1  riastrad 			if (!amdgpu_sriov_vf(adev))
    735  1.1  riastrad 				amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
    736  1.1  riastrad 		} else {
    737  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
    738  1.1  riastrad 		}
    739  1.1  riastrad 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
    740  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
    741  1.1  riastrad #if defined(CONFIG_DRM_AMD_DC)
    742  1.1  riastrad 		else if (amdgpu_device_has_dc_support(adev))
    743  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
    744  1.1  riastrad #endif
    745  1.1  riastrad 		if (!(adev->asic_type == CHIP_VEGA20 && amdgpu_sriov_vf(adev))) {
    746  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &uvd_v7_0_ip_block);
    747  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vce_v4_0_ip_block);
    748  1.1  riastrad 		}
    749  1.1  riastrad 		break;
    750  1.1  riastrad 	case CHIP_RAVEN:
    751  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
    752  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
    753  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    754  1.1  riastrad 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
    755  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &psp_v10_0_ip_block);
    756  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
    757  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
    758  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &pp_smu_ip_block);
    759  1.1  riastrad 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
    760  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
    761  1.1  riastrad #if defined(CONFIG_DRM_AMD_DC)
    762  1.1  riastrad 		else if (amdgpu_device_has_dc_support(adev))
    763  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dm_ip_block);
    764  1.1  riastrad #endif
    765  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vcn_v1_0_ip_block);
    766  1.1  riastrad 		break;
    767  1.1  riastrad 	case CHIP_ARCTURUS:
    768  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
    769  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
    770  1.1  riastrad 
    771  1.1  riastrad 		if (amdgpu_sriov_vf(adev)) {
    772  1.1  riastrad 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
    773  1.1  riastrad 				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
    774  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    775  1.1  riastrad 		} else {
    776  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    777  1.1  riastrad 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
    778  1.1  riastrad 				amdgpu_device_ip_block_add(adev, &psp_v11_0_ip_block);
    779  1.1  riastrad 		}
    780  1.1  riastrad 
    781  1.1  riastrad 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
    782  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
    783  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
    784  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
    785  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &smu_v11_0_ip_block);
    786  1.1  riastrad 
    787  1.1  riastrad 		if (amdgpu_sriov_vf(adev)) {
    788  1.1  riastrad 			if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
    789  1.1  riastrad 				amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
    790  1.1  riastrad 		} else {
    791  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &vcn_v2_5_ip_block);
    792  1.1  riastrad 		}
    793  1.1  riastrad 		if (!amdgpu_sriov_vf(adev))
    794  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &jpeg_v2_5_ip_block);
    795  1.1  riastrad 		break;
    796  1.1  riastrad 	case CHIP_RENOIR:
    797  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_common_ip_block);
    798  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gmc_v9_0_ip_block);
    799  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vega10_ih_ip_block);
    800  1.1  riastrad 		if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP))
    801  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &psp_v12_0_ip_block);
    802  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &smu_v12_0_ip_block);
    803  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
    804  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &sdma_v4_0_ip_block);
    805  1.1  riastrad 		if (adev->enable_virtual_display || amdgpu_sriov_vf(adev))
    806  1.1  riastrad 			amdgpu_device_ip_block_add(adev, &dce_virtual_ip_block);
    807  1.1  riastrad #if defined(CONFIG_DRM_AMD_DC)
    808  1.1  riastrad                 else if (amdgpu_device_has_dc_support(adev))
    809  1.1  riastrad                         amdgpu_device_ip_block_add(adev, &dm_ip_block);
    810  1.1  riastrad #endif
    811  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &vcn_v2_0_ip_block);
    812  1.1  riastrad 		amdgpu_device_ip_block_add(adev, &jpeg_v2_0_ip_block);
    813  1.1  riastrad 		break;
    814  1.1  riastrad 	default:
    815  1.1  riastrad 		return -EINVAL;
    816  1.1  riastrad 	}
    817  1.1  riastrad 
    818  1.1  riastrad 	return 0;
    819  1.1  riastrad }
    820  1.1  riastrad 
    821  1.1  riastrad static void soc15_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring)
    822  1.1  riastrad {
    823  1.1  riastrad 	adev->nbio.funcs->hdp_flush(adev, ring);
    824  1.1  riastrad }
    825  1.1  riastrad 
    826  1.1  riastrad static void soc15_invalidate_hdp(struct amdgpu_device *adev,
    827  1.1  riastrad 				 struct amdgpu_ring *ring)
    828  1.1  riastrad {
    829  1.1  riastrad 	if (!ring || !ring->funcs->emit_wreg)
    830  1.1  riastrad 		WREG32_SOC15_NO_KIQ(HDP, 0, mmHDP_READ_CACHE_INVALIDATE, 1);
    831  1.1  riastrad 	else
    832  1.1  riastrad 		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
    833  1.1  riastrad 			HDP, 0, mmHDP_READ_CACHE_INVALIDATE), 1);
    834  1.1  riastrad }
    835  1.1  riastrad 
    836  1.1  riastrad static bool soc15_need_full_reset(struct amdgpu_device *adev)
    837  1.1  riastrad {
    838  1.1  riastrad 	/* change this when we implement soft reset */
    839  1.1  riastrad 	return true;
    840  1.1  riastrad }
    841  1.1  riastrad static void soc15_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
    842  1.1  riastrad 				 uint64_t *count1)
    843  1.1  riastrad {
    844  1.1  riastrad 	uint32_t perfctr = 0;
    845  1.1  riastrad 	uint64_t cnt0_of, cnt1_of;
    846  1.1  riastrad 	int tmp;
    847  1.1  riastrad 
    848  1.1  riastrad 	/* This reports 0 on APUs, so return to avoid writing/reading registers
    849  1.1  riastrad 	 * that may or may not be different from their GPU counterparts
    850  1.1  riastrad 	 */
    851  1.1  riastrad 	if (adev->flags & AMD_IS_APU)
    852  1.1  riastrad 		return;
    853  1.1  riastrad 
    854  1.1  riastrad 	/* Set the 2 events that we wish to watch, defined above */
    855  1.1  riastrad 	/* Reg 40 is # received msgs */
    856  1.1  riastrad 	/* Reg 104 is # of posted requests sent */
    857  1.1  riastrad 	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT0_SEL, 40);
    858  1.1  riastrad 	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK, EVENT1_SEL, 104);
    859  1.1  riastrad 
    860  1.1  riastrad 	/* Write to enable desired perf counters */
    861  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK, perfctr);
    862  1.1  riastrad 	/* Zero out and enable the perf counters
    863  1.1  riastrad 	 * Write 0x5:
    864  1.1  riastrad 	 * Bit 0 = Start all counters(1)
    865  1.1  riastrad 	 * Bit 2 = Global counter reset enable(1)
    866  1.1  riastrad 	 */
    867  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
    868  1.1  riastrad 
    869  1.1  riastrad 	msleep(1000);
    870  1.1  riastrad 
    871  1.1  riastrad 	/* Load the shadow and disable the perf counters
    872  1.1  riastrad 	 * Write 0x2:
    873  1.1  riastrad 	 * Bit 0 = Stop counters(0)
    874  1.1  riastrad 	 * Bit 1 = Load the shadow counters(1)
    875  1.1  riastrad 	 */
    876  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
    877  1.1  riastrad 
    878  1.1  riastrad 	/* Read register values to get any >32bit overflow */
    879  1.1  riastrad 	tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK);
    880  1.1  riastrad 	cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER0_UPPER);
    881  1.1  riastrad 	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK, COUNTER1_UPPER);
    882  1.1  riastrad 
    883  1.1  riastrad 	/* Get the values and add the overflow */
    884  1.1  riastrad 	*count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK) | (cnt0_of << 32);
    885  1.1  riastrad 	*count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK) | (cnt1_of << 32);
    886  1.1  riastrad }
    887  1.1  riastrad 
    888  1.1  riastrad static void vega20_get_pcie_usage(struct amdgpu_device *adev, uint64_t *count0,
    889  1.1  riastrad 				 uint64_t *count1)
    890  1.1  riastrad {
    891  1.1  riastrad 	uint32_t perfctr = 0;
    892  1.1  riastrad 	uint64_t cnt0_of, cnt1_of;
    893  1.1  riastrad 	int tmp;
    894  1.1  riastrad 
    895  1.1  riastrad 	/* This reports 0 on APUs, so return to avoid writing/reading registers
    896  1.1  riastrad 	 * that may or may not be different from their GPU counterparts
    897  1.1  riastrad 	 */
    898  1.1  riastrad 	if (adev->flags & AMD_IS_APU)
    899  1.1  riastrad 		return;
    900  1.1  riastrad 
    901  1.1  riastrad 	/* Set the 2 events that we wish to watch, defined above */
    902  1.1  riastrad 	/* Reg 40 is # received msgs */
    903  1.1  riastrad 	/* Reg 108 is # of posted requests sent on VG20 */
    904  1.1  riastrad 	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
    905  1.1  riastrad 				EVENT0_SEL, 40);
    906  1.1  riastrad 	perfctr = REG_SET_FIELD(perfctr, PCIE_PERF_CNTL_TXCLK3,
    907  1.1  riastrad 				EVENT1_SEL, 108);
    908  1.1  riastrad 
    909  1.1  riastrad 	/* Write to enable desired perf counters */
    910  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3, perfctr);
    911  1.1  riastrad 	/* Zero out and enable the perf counters
    912  1.1  riastrad 	 * Write 0x5:
    913  1.1  riastrad 	 * Bit 0 = Start all counters(1)
    914  1.1  riastrad 	 * Bit 2 = Global counter reset enable(1)
    915  1.1  riastrad 	 */
    916  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000005);
    917  1.1  riastrad 
    918  1.1  riastrad 	msleep(1000);
    919  1.1  riastrad 
    920  1.1  riastrad 	/* Load the shadow and disable the perf counters
    921  1.1  riastrad 	 * Write 0x2:
    922  1.1  riastrad 	 * Bit 0 = Stop counters(0)
    923  1.1  riastrad 	 * Bit 1 = Load the shadow counters(1)
    924  1.1  riastrad 	 */
    925  1.1  riastrad 	WREG32_PCIE(smnPCIE_PERF_COUNT_CNTL, 0x00000002);
    926  1.1  riastrad 
    927  1.1  riastrad 	/* Read register values to get any >32bit overflow */
    928  1.1  riastrad 	tmp = RREG32_PCIE(smnPCIE_PERF_CNTL_TXCLK3);
    929  1.1  riastrad 	cnt0_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER0_UPPER);
    930  1.1  riastrad 	cnt1_of = REG_GET_FIELD(tmp, PCIE_PERF_CNTL_TXCLK3, COUNTER1_UPPER);
    931  1.1  riastrad 
    932  1.1  riastrad 	/* Get the values and add the overflow */
    933  1.1  riastrad 	*count0 = RREG32_PCIE(smnPCIE_PERF_COUNT0_TXCLK3) | (cnt0_of << 32);
    934  1.1  riastrad 	*count1 = RREG32_PCIE(smnPCIE_PERF_COUNT1_TXCLK3) | (cnt1_of << 32);
    935  1.1  riastrad }
    936  1.1  riastrad 
    937  1.1  riastrad static bool soc15_need_reset_on_init(struct amdgpu_device *adev)
    938  1.1  riastrad {
    939  1.1  riastrad 	u32 sol_reg;
    940  1.1  riastrad 
    941  1.1  riastrad 	/* Just return false for soc15 GPUs.  Reset does not seem to
    942  1.1  riastrad 	 * be necessary.
    943  1.1  riastrad 	 */
    944  1.1  riastrad 	if (!amdgpu_passthrough(adev))
    945  1.1  riastrad 		return false;
    946  1.1  riastrad 
    947  1.1  riastrad 	if (adev->flags & AMD_IS_APU)
    948  1.1  riastrad 		return false;
    949  1.1  riastrad 
    950  1.1  riastrad 	/* Check sOS sign of life register to confirm sys driver and sOS
    951  1.1  riastrad 	 * are already been loaded.
    952  1.1  riastrad 	 */
    953  1.1  riastrad 	sol_reg = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_81);
    954  1.1  riastrad 	if (sol_reg)
    955  1.1  riastrad 		return true;
    956  1.1  riastrad 
    957  1.1  riastrad 	return false;
    958  1.1  riastrad }
    959  1.1  riastrad 
    960  1.1  riastrad static uint64_t soc15_get_pcie_replay_count(struct amdgpu_device *adev)
    961  1.1  riastrad {
    962  1.1  riastrad 	uint64_t nak_r, nak_g;
    963  1.1  riastrad 
    964  1.1  riastrad 	/* Get the number of NAKs received and generated */
    965  1.1  riastrad 	nak_r = RREG32_PCIE(smnPCIE_RX_NUM_NAK);
    966  1.1  riastrad 	nak_g = RREG32_PCIE(smnPCIE_RX_NUM_NAK_GENERATED);
    967  1.1  riastrad 
    968  1.1  riastrad 	/* Add the total number of NAKs, i.e the number of replays */
    969  1.1  riastrad 	return (nak_r + nak_g);
    970  1.1  riastrad }
    971  1.1  riastrad 
    972  1.1  riastrad static const struct amdgpu_asic_funcs soc15_asic_funcs =
    973  1.1  riastrad {
    974  1.1  riastrad 	.read_disabled_bios = &soc15_read_disabled_bios,
    975  1.1  riastrad 	.read_bios_from_rom = &soc15_read_bios_from_rom,
    976  1.1  riastrad 	.read_register = &soc15_read_register,
    977  1.1  riastrad 	.reset = &soc15_asic_reset,
    978  1.1  riastrad 	.reset_method = &soc15_asic_reset_method,
    979  1.1  riastrad 	.set_vga_state = &soc15_vga_set_state,
    980  1.1  riastrad 	.get_xclk = &soc15_get_xclk,
    981  1.1  riastrad 	.set_uvd_clocks = &soc15_set_uvd_clocks,
    982  1.1  riastrad 	.set_vce_clocks = &soc15_set_vce_clocks,
    983  1.1  riastrad 	.get_config_memsize = &soc15_get_config_memsize,
    984  1.1  riastrad 	.flush_hdp = &soc15_flush_hdp,
    985  1.1  riastrad 	.invalidate_hdp = &soc15_invalidate_hdp,
    986  1.1  riastrad 	.need_full_reset = &soc15_need_full_reset,
    987  1.1  riastrad 	.init_doorbell_index = &vega10_doorbell_index_init,
    988  1.1  riastrad 	.get_pcie_usage = &soc15_get_pcie_usage,
    989  1.1  riastrad 	.need_reset_on_init = &soc15_need_reset_on_init,
    990  1.1  riastrad 	.get_pcie_replay_count = &soc15_get_pcie_replay_count,
    991  1.1  riastrad 	.supports_baco = &soc15_supports_baco,
    992  1.1  riastrad };
    993  1.1  riastrad 
    994  1.1  riastrad static const struct amdgpu_asic_funcs vega20_asic_funcs =
    995  1.1  riastrad {
    996  1.1  riastrad 	.read_disabled_bios = &soc15_read_disabled_bios,
    997  1.1  riastrad 	.read_bios_from_rom = &soc15_read_bios_from_rom,
    998  1.1  riastrad 	.read_register = &soc15_read_register,
    999  1.1  riastrad 	.reset = &soc15_asic_reset,
   1000  1.1  riastrad 	.reset_method = &soc15_asic_reset_method,
   1001  1.1  riastrad 	.set_vga_state = &soc15_vga_set_state,
   1002  1.1  riastrad 	.get_xclk = &soc15_get_xclk,
   1003  1.1  riastrad 	.set_uvd_clocks = &soc15_set_uvd_clocks,
   1004  1.1  riastrad 	.set_vce_clocks = &soc15_set_vce_clocks,
   1005  1.1  riastrad 	.get_config_memsize = &soc15_get_config_memsize,
   1006  1.1  riastrad 	.flush_hdp = &soc15_flush_hdp,
   1007  1.1  riastrad 	.invalidate_hdp = &soc15_invalidate_hdp,
   1008  1.1  riastrad 	.need_full_reset = &soc15_need_full_reset,
   1009  1.1  riastrad 	.init_doorbell_index = &vega20_doorbell_index_init,
   1010  1.1  riastrad 	.get_pcie_usage = &vega20_get_pcie_usage,
   1011  1.1  riastrad 	.need_reset_on_init = &soc15_need_reset_on_init,
   1012  1.1  riastrad 	.get_pcie_replay_count = &soc15_get_pcie_replay_count,
   1013  1.1  riastrad 	.supports_baco = &soc15_supports_baco,
   1014  1.1  riastrad };
   1015  1.1  riastrad 
   1016  1.1  riastrad static int soc15_common_early_init(void *handle)
   1017  1.1  riastrad {
   1018  1.1  riastrad #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
   1019  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1020  1.1  riastrad 
   1021  1.1  riastrad 	adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
   1022  1.1  riastrad 	adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
   1023  1.1  riastrad 	adev->smc_rreg = NULL;
   1024  1.1  riastrad 	adev->smc_wreg = NULL;
   1025  1.1  riastrad 	adev->pcie_rreg = &soc15_pcie_rreg;
   1026  1.1  riastrad 	adev->pcie_wreg = &soc15_pcie_wreg;
   1027  1.1  riastrad 	adev->pcie_rreg64 = &soc15_pcie_rreg64;
   1028  1.1  riastrad 	adev->pcie_wreg64 = &soc15_pcie_wreg64;
   1029  1.1  riastrad 	adev->uvd_ctx_rreg = &soc15_uvd_ctx_rreg;
   1030  1.1  riastrad 	adev->uvd_ctx_wreg = &soc15_uvd_ctx_wreg;
   1031  1.1  riastrad 	adev->didt_rreg = &soc15_didt_rreg;
   1032  1.1  riastrad 	adev->didt_wreg = &soc15_didt_wreg;
   1033  1.1  riastrad 	adev->gc_cac_rreg = &soc15_gc_cac_rreg;
   1034  1.1  riastrad 	adev->gc_cac_wreg = &soc15_gc_cac_wreg;
   1035  1.1  riastrad 	adev->se_cac_rreg = &soc15_se_cac_rreg;
   1036  1.1  riastrad 	adev->se_cac_wreg = &soc15_se_cac_wreg;
   1037  1.1  riastrad 
   1038  1.1  riastrad 
   1039  1.1  riastrad 	adev->external_rev_id = 0xFF;
   1040  1.1  riastrad 	switch (adev->asic_type) {
   1041  1.1  riastrad 	case CHIP_VEGA10:
   1042  1.1  riastrad 		adev->asic_funcs = &soc15_asic_funcs;
   1043  1.1  riastrad 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1044  1.1  riastrad 			AMD_CG_SUPPORT_GFX_MGLS |
   1045  1.1  riastrad 			AMD_CG_SUPPORT_GFX_RLC_LS |
   1046  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CP_LS |
   1047  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGCG |
   1048  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGLS |
   1049  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGCG |
   1050  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGLS |
   1051  1.1  riastrad 			AMD_CG_SUPPORT_BIF_MGCG |
   1052  1.1  riastrad 			AMD_CG_SUPPORT_BIF_LS |
   1053  1.1  riastrad 			AMD_CG_SUPPORT_HDP_LS |
   1054  1.1  riastrad 			AMD_CG_SUPPORT_DRM_MGCG |
   1055  1.1  riastrad 			AMD_CG_SUPPORT_DRM_LS |
   1056  1.1  riastrad 			AMD_CG_SUPPORT_ROM_MGCG |
   1057  1.1  riastrad 			AMD_CG_SUPPORT_DF_MGCG |
   1058  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_MGCG |
   1059  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_LS |
   1060  1.1  riastrad 			AMD_CG_SUPPORT_MC_MGCG |
   1061  1.1  riastrad 			AMD_CG_SUPPORT_MC_LS;
   1062  1.1  riastrad 		adev->pg_flags = 0;
   1063  1.1  riastrad 		adev->external_rev_id = 0x1;
   1064  1.1  riastrad 		break;
   1065  1.1  riastrad 	case CHIP_VEGA12:
   1066  1.1  riastrad 		adev->asic_funcs = &soc15_asic_funcs;
   1067  1.1  riastrad 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1068  1.1  riastrad 			AMD_CG_SUPPORT_GFX_MGLS |
   1069  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGCG |
   1070  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGLS |
   1071  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGCG |
   1072  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGLS |
   1073  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CP_LS |
   1074  1.1  riastrad 			AMD_CG_SUPPORT_MC_LS |
   1075  1.1  riastrad 			AMD_CG_SUPPORT_MC_MGCG |
   1076  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_MGCG |
   1077  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_LS |
   1078  1.1  riastrad 			AMD_CG_SUPPORT_BIF_MGCG |
   1079  1.1  riastrad 			AMD_CG_SUPPORT_BIF_LS |
   1080  1.1  riastrad 			AMD_CG_SUPPORT_HDP_MGCG |
   1081  1.1  riastrad 			AMD_CG_SUPPORT_HDP_LS |
   1082  1.1  riastrad 			AMD_CG_SUPPORT_ROM_MGCG |
   1083  1.1  riastrad 			AMD_CG_SUPPORT_VCE_MGCG |
   1084  1.1  riastrad 			AMD_CG_SUPPORT_UVD_MGCG;
   1085  1.1  riastrad 		adev->pg_flags = 0;
   1086  1.1  riastrad 		adev->external_rev_id = adev->rev_id + 0x14;
   1087  1.1  riastrad 		break;
   1088  1.1  riastrad 	case CHIP_VEGA20:
   1089  1.1  riastrad 		adev->asic_funcs = &vega20_asic_funcs;
   1090  1.1  riastrad 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1091  1.1  riastrad 			AMD_CG_SUPPORT_GFX_MGLS |
   1092  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGCG |
   1093  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGLS |
   1094  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGCG |
   1095  1.1  riastrad 			AMD_CG_SUPPORT_GFX_3D_CGLS |
   1096  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CP_LS |
   1097  1.1  riastrad 			AMD_CG_SUPPORT_MC_LS |
   1098  1.1  riastrad 			AMD_CG_SUPPORT_MC_MGCG |
   1099  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_MGCG |
   1100  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_LS |
   1101  1.1  riastrad 			AMD_CG_SUPPORT_BIF_MGCG |
   1102  1.1  riastrad 			AMD_CG_SUPPORT_BIF_LS |
   1103  1.1  riastrad 			AMD_CG_SUPPORT_HDP_MGCG |
   1104  1.1  riastrad 			AMD_CG_SUPPORT_HDP_LS |
   1105  1.1  riastrad 			AMD_CG_SUPPORT_ROM_MGCG |
   1106  1.1  riastrad 			AMD_CG_SUPPORT_VCE_MGCG |
   1107  1.1  riastrad 			AMD_CG_SUPPORT_UVD_MGCG;
   1108  1.1  riastrad 		adev->pg_flags = 0;
   1109  1.1  riastrad 		adev->external_rev_id = adev->rev_id + 0x28;
   1110  1.1  riastrad 		break;
   1111  1.1  riastrad 	case CHIP_RAVEN:
   1112  1.1  riastrad 		adev->asic_funcs = &soc15_asic_funcs;
   1113  1.1  riastrad 		if (adev->rev_id >= 0x8)
   1114  1.1  riastrad 			adev->external_rev_id = adev->rev_id + 0x79;
   1115  1.1  riastrad 		else if (adev->pdev->device == 0x15d8)
   1116  1.1  riastrad 			adev->external_rev_id = adev->rev_id + 0x41;
   1117  1.1  riastrad 		else if (adev->rev_id == 1)
   1118  1.1  riastrad 			adev->external_rev_id = adev->rev_id + 0x20;
   1119  1.1  riastrad 		else
   1120  1.1  riastrad 			adev->external_rev_id = adev->rev_id + 0x01;
   1121  1.1  riastrad 
   1122  1.1  riastrad 		if (adev->rev_id >= 0x8) {
   1123  1.1  riastrad 			adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1124  1.1  riastrad 				AMD_CG_SUPPORT_GFX_MGLS |
   1125  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CP_LS |
   1126  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGCG |
   1127  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGLS |
   1128  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGCG |
   1129  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGLS |
   1130  1.1  riastrad 				AMD_CG_SUPPORT_BIF_LS |
   1131  1.1  riastrad 				AMD_CG_SUPPORT_HDP_LS |
   1132  1.1  riastrad 				AMD_CG_SUPPORT_ROM_MGCG |
   1133  1.1  riastrad 				AMD_CG_SUPPORT_MC_MGCG |
   1134  1.1  riastrad 				AMD_CG_SUPPORT_MC_LS |
   1135  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_MGCG |
   1136  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_LS |
   1137  1.1  riastrad 				AMD_CG_SUPPORT_VCN_MGCG;
   1138  1.1  riastrad 
   1139  1.1  riastrad 			adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
   1140  1.1  riastrad 		} else if (adev->pdev->device == 0x15d8) {
   1141  1.1  riastrad 			adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1142  1.1  riastrad 				AMD_CG_SUPPORT_GFX_MGLS |
   1143  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CP_LS |
   1144  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGCG |
   1145  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGLS |
   1146  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGCG |
   1147  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGLS |
   1148  1.1  riastrad 				AMD_CG_SUPPORT_BIF_LS |
   1149  1.1  riastrad 				AMD_CG_SUPPORT_HDP_LS |
   1150  1.1  riastrad 				AMD_CG_SUPPORT_ROM_MGCG |
   1151  1.1  riastrad 				AMD_CG_SUPPORT_MC_MGCG |
   1152  1.1  riastrad 				AMD_CG_SUPPORT_MC_LS |
   1153  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_MGCG |
   1154  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_LS;
   1155  1.1  riastrad 
   1156  1.1  riastrad 			adev->pg_flags = AMD_PG_SUPPORT_SDMA |
   1157  1.1  riastrad 				AMD_PG_SUPPORT_MMHUB |
   1158  1.1  riastrad 				AMD_PG_SUPPORT_VCN |
   1159  1.1  riastrad 				AMD_PG_SUPPORT_VCN_DPG;
   1160  1.1  riastrad 		} else {
   1161  1.1  riastrad 			adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1162  1.1  riastrad 				AMD_CG_SUPPORT_GFX_MGLS |
   1163  1.1  riastrad 				AMD_CG_SUPPORT_GFX_RLC_LS |
   1164  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CP_LS |
   1165  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGCG |
   1166  1.1  riastrad 				AMD_CG_SUPPORT_GFX_3D_CGLS |
   1167  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGCG |
   1168  1.1  riastrad 				AMD_CG_SUPPORT_GFX_CGLS |
   1169  1.1  riastrad 				AMD_CG_SUPPORT_BIF_MGCG |
   1170  1.1  riastrad 				AMD_CG_SUPPORT_BIF_LS |
   1171  1.1  riastrad 				AMD_CG_SUPPORT_HDP_MGCG |
   1172  1.1  riastrad 				AMD_CG_SUPPORT_HDP_LS |
   1173  1.1  riastrad 				AMD_CG_SUPPORT_DRM_MGCG |
   1174  1.1  riastrad 				AMD_CG_SUPPORT_DRM_LS |
   1175  1.1  riastrad 				AMD_CG_SUPPORT_ROM_MGCG |
   1176  1.1  riastrad 				AMD_CG_SUPPORT_MC_MGCG |
   1177  1.1  riastrad 				AMD_CG_SUPPORT_MC_LS |
   1178  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_MGCG |
   1179  1.1  riastrad 				AMD_CG_SUPPORT_SDMA_LS |
   1180  1.1  riastrad 				AMD_CG_SUPPORT_VCN_MGCG;
   1181  1.1  riastrad 
   1182  1.1  riastrad 			adev->pg_flags = AMD_PG_SUPPORT_SDMA | AMD_PG_SUPPORT_VCN;
   1183  1.1  riastrad 		}
   1184  1.1  riastrad 		break;
   1185  1.1  riastrad 	case CHIP_ARCTURUS:
   1186  1.1  riastrad 		adev->asic_funcs = &vega20_asic_funcs;
   1187  1.1  riastrad 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1188  1.1  riastrad 			AMD_CG_SUPPORT_GFX_MGLS |
   1189  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGCG |
   1190  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CGLS |
   1191  1.1  riastrad 			AMD_CG_SUPPORT_GFX_CP_LS |
   1192  1.1  riastrad 			AMD_CG_SUPPORT_HDP_MGCG |
   1193  1.1  riastrad 			AMD_CG_SUPPORT_HDP_LS |
   1194  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_MGCG |
   1195  1.1  riastrad 			AMD_CG_SUPPORT_SDMA_LS |
   1196  1.1  riastrad 			AMD_CG_SUPPORT_MC_MGCG |
   1197  1.1  riastrad 			AMD_CG_SUPPORT_MC_LS |
   1198  1.1  riastrad 			AMD_CG_SUPPORT_IH_CG |
   1199  1.1  riastrad 			AMD_CG_SUPPORT_VCN_MGCG |
   1200  1.1  riastrad 			AMD_CG_SUPPORT_JPEG_MGCG;
   1201  1.1  riastrad 		adev->pg_flags = 0;
   1202  1.1  riastrad 		adev->external_rev_id = adev->rev_id + 0x32;
   1203  1.1  riastrad 		break;
   1204  1.1  riastrad 	case CHIP_RENOIR:
   1205  1.1  riastrad 		adev->asic_funcs = &soc15_asic_funcs;
   1206  1.1  riastrad 		adev->cg_flags = AMD_CG_SUPPORT_GFX_MGCG |
   1207  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_MGLS |
   1208  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_3D_CGCG |
   1209  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_3D_CGLS |
   1210  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_CGCG |
   1211  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_CGLS |
   1212  1.1  riastrad 				 AMD_CG_SUPPORT_GFX_CP_LS |
   1213  1.1  riastrad 				 AMD_CG_SUPPORT_MC_MGCG |
   1214  1.1  riastrad 				 AMD_CG_SUPPORT_MC_LS |
   1215  1.1  riastrad 				 AMD_CG_SUPPORT_SDMA_MGCG |
   1216  1.1  riastrad 				 AMD_CG_SUPPORT_SDMA_LS |
   1217  1.1  riastrad 				 AMD_CG_SUPPORT_BIF_LS |
   1218  1.1  riastrad 				 AMD_CG_SUPPORT_HDP_LS |
   1219  1.1  riastrad 				 AMD_CG_SUPPORT_ROM_MGCG |
   1220  1.1  riastrad 				 AMD_CG_SUPPORT_VCN_MGCG |
   1221  1.1  riastrad 				 AMD_CG_SUPPORT_JPEG_MGCG |
   1222  1.1  riastrad 				 AMD_CG_SUPPORT_IH_CG |
   1223  1.1  riastrad 				 AMD_CG_SUPPORT_ATHUB_LS |
   1224  1.1  riastrad 				 AMD_CG_SUPPORT_ATHUB_MGCG |
   1225  1.1  riastrad 				 AMD_CG_SUPPORT_DF_MGCG;
   1226  1.1  riastrad 		adev->pg_flags = AMD_PG_SUPPORT_SDMA |
   1227  1.1  riastrad 				 AMD_PG_SUPPORT_VCN |
   1228  1.1  riastrad 				 AMD_PG_SUPPORT_JPEG |
   1229  1.1  riastrad 				 AMD_PG_SUPPORT_VCN_DPG;
   1230  1.1  riastrad 		adev->external_rev_id = adev->rev_id + 0x91;
   1231  1.1  riastrad 		break;
   1232  1.1  riastrad 	default:
   1233  1.1  riastrad 		/* FIXME: not supported yet */
   1234  1.1  riastrad 		return -EINVAL;
   1235  1.1  riastrad 	}
   1236  1.1  riastrad 
   1237  1.1  riastrad 	if (amdgpu_sriov_vf(adev)) {
   1238  1.1  riastrad 		amdgpu_virt_init_setting(adev);
   1239  1.1  riastrad 		xgpu_ai_mailbox_set_irq_funcs(adev);
   1240  1.1  riastrad 	}
   1241  1.1  riastrad 
   1242  1.1  riastrad 	return 0;
   1243  1.1  riastrad }
   1244  1.1  riastrad 
   1245  1.1  riastrad static int soc15_common_late_init(void *handle)
   1246  1.1  riastrad {
   1247  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1248  1.1  riastrad 	int r = 0;
   1249  1.1  riastrad 
   1250  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
   1251  1.1  riastrad 		xgpu_ai_mailbox_get_irq(adev);
   1252  1.1  riastrad 
   1253  1.1  riastrad 	if (adev->nbio.funcs->ras_late_init)
   1254  1.1  riastrad 		r = adev->nbio.funcs->ras_late_init(adev);
   1255  1.1  riastrad 
   1256  1.1  riastrad 	return r;
   1257  1.1  riastrad }
   1258  1.1  riastrad 
   1259  1.1  riastrad static int soc15_common_sw_init(void *handle)
   1260  1.1  riastrad {
   1261  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1262  1.1  riastrad 
   1263  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
   1264  1.1  riastrad 		xgpu_ai_mailbox_add_irq_id(adev);
   1265  1.1  riastrad 
   1266  1.1  riastrad 	adev->df.funcs->sw_init(adev);
   1267  1.1  riastrad 
   1268  1.1  riastrad 	return 0;
   1269  1.1  riastrad }
   1270  1.1  riastrad 
   1271  1.1  riastrad static int soc15_common_sw_fini(void *handle)
   1272  1.1  riastrad {
   1273  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1274  1.1  riastrad 
   1275  1.1  riastrad 	amdgpu_nbio_ras_fini(adev);
   1276  1.1  riastrad 	adev->df.funcs->sw_fini(adev);
   1277  1.1  riastrad 	return 0;
   1278  1.1  riastrad }
   1279  1.1  riastrad 
   1280  1.1  riastrad static void soc15_doorbell_range_init(struct amdgpu_device *adev)
   1281  1.1  riastrad {
   1282  1.1  riastrad 	int i;
   1283  1.1  riastrad 	struct amdgpu_ring *ring;
   1284  1.1  riastrad 
   1285  1.1  riastrad 	/* sdma/ih doorbell range are programed by hypervisor */
   1286  1.1  riastrad 	if (!amdgpu_sriov_vf(adev)) {
   1287  1.1  riastrad 		for (i = 0; i < adev->sdma.num_instances; i++) {
   1288  1.1  riastrad 			ring = &adev->sdma.instance[i].ring;
   1289  1.1  riastrad 			adev->nbio.funcs->sdma_doorbell_range(adev, i,
   1290  1.1  riastrad 				ring->use_doorbell, ring->doorbell_index,
   1291  1.1  riastrad 				adev->doorbell_index.sdma_doorbell_range);
   1292  1.1  riastrad 		}
   1293  1.1  riastrad 
   1294  1.1  riastrad 		adev->nbio.funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
   1295  1.1  riastrad 						adev->irq.ih.doorbell_index);
   1296  1.1  riastrad 	}
   1297  1.1  riastrad }
   1298  1.1  riastrad 
   1299  1.1  riastrad static int soc15_common_hw_init(void *handle)
   1300  1.1  riastrad {
   1301  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1302  1.1  riastrad 
   1303  1.1  riastrad 	/* enable pcie gen2/3 link */
   1304  1.1  riastrad 	soc15_pcie_gen3_enable(adev);
   1305  1.1  riastrad 	/* enable aspm */
   1306  1.1  riastrad 	soc15_program_aspm(adev);
   1307  1.1  riastrad 	/* setup nbio registers */
   1308  1.1  riastrad 	adev->nbio.funcs->init_registers(adev);
   1309  1.1  riastrad 	/* remap HDP registers to a hole in mmio space,
   1310  1.1  riastrad 	 * for the purpose of expose those registers
   1311  1.1  riastrad 	 * to process space
   1312  1.1  riastrad 	 */
   1313  1.1  riastrad 	if (adev->nbio.funcs->remap_hdp_registers)
   1314  1.1  riastrad 		adev->nbio.funcs->remap_hdp_registers(adev);
   1315  1.1  riastrad 
   1316  1.1  riastrad 	/* enable the doorbell aperture */
   1317  1.1  riastrad 	soc15_enable_doorbell_aperture(adev, true);
   1318  1.1  riastrad 	/* HW doorbell routing policy: doorbell writing not
   1319  1.1  riastrad 	 * in SDMA/IH/MM/ACV range will be routed to CP. So
   1320  1.1  riastrad 	 * we need to init SDMA/IH/MM/ACV doorbell range prior
   1321  1.1  riastrad 	 * to CP ip block init and ring test.
   1322  1.1  riastrad 	 */
   1323  1.1  riastrad 	soc15_doorbell_range_init(adev);
   1324  1.1  riastrad 
   1325  1.1  riastrad 	return 0;
   1326  1.1  riastrad }
   1327  1.1  riastrad 
   1328  1.1  riastrad static int soc15_common_hw_fini(void *handle)
   1329  1.1  riastrad {
   1330  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1331  1.1  riastrad 
   1332  1.1  riastrad 	/* disable the doorbell aperture */
   1333  1.1  riastrad 	soc15_enable_doorbell_aperture(adev, false);
   1334  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
   1335  1.1  riastrad 		xgpu_ai_mailbox_put_irq(adev);
   1336  1.1  riastrad 
   1337  1.1  riastrad 	if (adev->nbio.ras_if &&
   1338  1.1  riastrad 	    amdgpu_ras_is_supported(adev, adev->nbio.ras_if->block)) {
   1339  1.1  riastrad 		if (adev->nbio.funcs->init_ras_controller_interrupt)
   1340  1.1  riastrad 			amdgpu_irq_put(adev, &adev->nbio.ras_controller_irq, 0);
   1341  1.1  riastrad 		if (adev->nbio.funcs->init_ras_err_event_athub_interrupt)
   1342  1.1  riastrad 			amdgpu_irq_put(adev, &adev->nbio.ras_err_event_athub_irq, 0);
   1343  1.1  riastrad 	}
   1344  1.1  riastrad 
   1345  1.1  riastrad 	return 0;
   1346  1.1  riastrad }
   1347  1.1  riastrad 
   1348  1.1  riastrad static int soc15_common_suspend(void *handle)
   1349  1.1  riastrad {
   1350  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1351  1.1  riastrad 
   1352  1.1  riastrad 	return soc15_common_hw_fini(adev);
   1353  1.1  riastrad }
   1354  1.1  riastrad 
   1355  1.1  riastrad static int soc15_common_resume(void *handle)
   1356  1.1  riastrad {
   1357  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1358  1.1  riastrad 
   1359  1.1  riastrad 	return soc15_common_hw_init(adev);
   1360  1.1  riastrad }
   1361  1.1  riastrad 
   1362  1.1  riastrad static bool soc15_common_is_idle(void *handle)
   1363  1.1  riastrad {
   1364  1.1  riastrad 	return true;
   1365  1.1  riastrad }
   1366  1.1  riastrad 
   1367  1.1  riastrad static int soc15_common_wait_for_idle(void *handle)
   1368  1.1  riastrad {
   1369  1.1  riastrad 	return 0;
   1370  1.1  riastrad }
   1371  1.1  riastrad 
   1372  1.1  riastrad static int soc15_common_soft_reset(void *handle)
   1373  1.1  riastrad {
   1374  1.1  riastrad 	return 0;
   1375  1.1  riastrad }
   1376  1.1  riastrad 
   1377  1.1  riastrad static void soc15_update_hdp_light_sleep(struct amdgpu_device *adev, bool enable)
   1378  1.1  riastrad {
   1379  1.1  riastrad 	uint32_t def, data;
   1380  1.1  riastrad 
   1381  1.1  riastrad 	if (adev->asic_type == CHIP_VEGA20 ||
   1382  1.1  riastrad 		adev->asic_type == CHIP_ARCTURUS) {
   1383  1.1  riastrad 		def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL));
   1384  1.1  riastrad 
   1385  1.1  riastrad 		if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
   1386  1.1  riastrad 			data |= HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
   1387  1.1  riastrad 				HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
   1388  1.1  riastrad 				HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
   1389  1.1  riastrad 				HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK;
   1390  1.1  riastrad 		else
   1391  1.1  riastrad 			data &= ~(HDP_MEM_POWER_CTRL__IPH_MEM_POWER_CTRL_EN_MASK |
   1392  1.1  riastrad 				HDP_MEM_POWER_CTRL__IPH_MEM_POWER_LS_EN_MASK |
   1393  1.1  riastrad 				HDP_MEM_POWER_CTRL__RC_MEM_POWER_CTRL_EN_MASK |
   1394  1.1  riastrad 				HDP_MEM_POWER_CTRL__RC_MEM_POWER_LS_EN_MASK);
   1395  1.1  riastrad 
   1396  1.1  riastrad 		if (def != data)
   1397  1.1  riastrad 			WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_CTRL), data);
   1398  1.1  riastrad 	} else {
   1399  1.1  riastrad 		def = data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
   1400  1.1  riastrad 
   1401  1.1  riastrad 		if (enable && (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS))
   1402  1.1  riastrad 			data |= HDP_MEM_POWER_LS__LS_ENABLE_MASK;
   1403  1.1  riastrad 		else
   1404  1.1  riastrad 			data &= ~HDP_MEM_POWER_LS__LS_ENABLE_MASK;
   1405  1.1  riastrad 
   1406  1.1  riastrad 		if (def != data)
   1407  1.1  riastrad 			WREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS), data);
   1408  1.1  riastrad 	}
   1409  1.1  riastrad }
   1410  1.1  riastrad 
   1411  1.1  riastrad static void soc15_update_drm_clock_gating(struct amdgpu_device *adev, bool enable)
   1412  1.1  riastrad {
   1413  1.1  riastrad 	uint32_t def, data;
   1414  1.1  riastrad 
   1415  1.1  riastrad 	def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
   1416  1.1  riastrad 
   1417  1.1  riastrad 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_MGCG))
   1418  1.1  riastrad 		data &= ~(0x01000000 |
   1419  1.1  riastrad 			  0x02000000 |
   1420  1.1  riastrad 			  0x04000000 |
   1421  1.1  riastrad 			  0x08000000 |
   1422  1.1  riastrad 			  0x10000000 |
   1423  1.1  riastrad 			  0x20000000 |
   1424  1.1  riastrad 			  0x40000000 |
   1425  1.1  riastrad 			  0x80000000);
   1426  1.1  riastrad 	else
   1427  1.1  riastrad 		data |= (0x01000000 |
   1428  1.1  riastrad 			 0x02000000 |
   1429  1.1  riastrad 			 0x04000000 |
   1430  1.1  riastrad 			 0x08000000 |
   1431  1.1  riastrad 			 0x10000000 |
   1432  1.1  riastrad 			 0x20000000 |
   1433  1.1  riastrad 			 0x40000000 |
   1434  1.1  riastrad 			 0x80000000);
   1435  1.1  riastrad 
   1436  1.1  riastrad 	if (def != data)
   1437  1.1  riastrad 		WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0), data);
   1438  1.1  riastrad }
   1439  1.1  riastrad 
   1440  1.1  riastrad static void soc15_update_drm_light_sleep(struct amdgpu_device *adev, bool enable)
   1441  1.1  riastrad {
   1442  1.1  riastrad 	uint32_t def, data;
   1443  1.1  riastrad 
   1444  1.1  riastrad 	def = data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
   1445  1.1  riastrad 
   1446  1.1  riastrad 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_DRM_LS))
   1447  1.1  riastrad 		data |= 1;
   1448  1.1  riastrad 	else
   1449  1.1  riastrad 		data &= ~1;
   1450  1.1  riastrad 
   1451  1.1  riastrad 	if (def != data)
   1452  1.1  riastrad 		WREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL), data);
   1453  1.1  riastrad }
   1454  1.1  riastrad 
   1455  1.1  riastrad static void soc15_update_rom_medium_grain_clock_gating(struct amdgpu_device *adev,
   1456  1.1  riastrad 						       bool enable)
   1457  1.1  riastrad {
   1458  1.1  riastrad 	uint32_t def, data;
   1459  1.1  riastrad 
   1460  1.1  riastrad 	def = data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
   1461  1.1  riastrad 
   1462  1.1  riastrad 	if (enable && (adev->cg_flags & AMD_CG_SUPPORT_ROM_MGCG))
   1463  1.1  riastrad 		data &= ~(CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
   1464  1.1  riastrad 			CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK);
   1465  1.1  riastrad 	else
   1466  1.1  riastrad 		data |= CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK |
   1467  1.1  riastrad 			CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE1_MASK;
   1468  1.1  riastrad 
   1469  1.1  riastrad 	if (def != data)
   1470  1.1  riastrad 		WREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0), data);
   1471  1.1  riastrad }
   1472  1.1  riastrad 
   1473  1.1  riastrad static int soc15_common_set_clockgating_state(void *handle,
   1474  1.1  riastrad 					    enum amd_clockgating_state state)
   1475  1.1  riastrad {
   1476  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1477  1.1  riastrad 
   1478  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
   1479  1.1  riastrad 		return 0;
   1480  1.1  riastrad 
   1481  1.1  riastrad 	switch (adev->asic_type) {
   1482  1.1  riastrad 	case CHIP_VEGA10:
   1483  1.1  riastrad 	case CHIP_VEGA12:
   1484  1.1  riastrad 	case CHIP_VEGA20:
   1485  1.1  riastrad 		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
   1486  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1487  1.1  riastrad 		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
   1488  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1489  1.1  riastrad 		soc15_update_hdp_light_sleep(adev,
   1490  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1491  1.1  riastrad 		soc15_update_drm_clock_gating(adev,
   1492  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1493  1.1  riastrad 		soc15_update_drm_light_sleep(adev,
   1494  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1495  1.1  riastrad 		soc15_update_rom_medium_grain_clock_gating(adev,
   1496  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1497  1.1  riastrad 		adev->df.funcs->update_medium_grain_clock_gating(adev,
   1498  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1499  1.1  riastrad 		break;
   1500  1.1  riastrad 	case CHIP_RAVEN:
   1501  1.1  riastrad 	case CHIP_RENOIR:
   1502  1.1  riastrad 		adev->nbio.funcs->update_medium_grain_clock_gating(adev,
   1503  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1504  1.1  riastrad 		adev->nbio.funcs->update_medium_grain_light_sleep(adev,
   1505  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1506  1.1  riastrad 		soc15_update_hdp_light_sleep(adev,
   1507  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1508  1.1  riastrad 		soc15_update_drm_clock_gating(adev,
   1509  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1510  1.1  riastrad 		soc15_update_drm_light_sleep(adev,
   1511  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1512  1.1  riastrad 		soc15_update_rom_medium_grain_clock_gating(adev,
   1513  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1514  1.1  riastrad 		break;
   1515  1.1  riastrad 	case CHIP_ARCTURUS:
   1516  1.1  riastrad 		soc15_update_hdp_light_sleep(adev,
   1517  1.1  riastrad 				state == AMD_CG_STATE_GATE);
   1518  1.1  riastrad 		break;
   1519  1.1  riastrad 	default:
   1520  1.1  riastrad 		break;
   1521  1.1  riastrad 	}
   1522  1.1  riastrad 	return 0;
   1523  1.1  riastrad }
   1524  1.1  riastrad 
   1525  1.1  riastrad static void soc15_common_get_clockgating_state(void *handle, u32 *flags)
   1526  1.1  riastrad {
   1527  1.1  riastrad 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   1528  1.1  riastrad 	int data;
   1529  1.1  riastrad 
   1530  1.1  riastrad 	if (amdgpu_sriov_vf(adev))
   1531  1.1  riastrad 		*flags = 0;
   1532  1.1  riastrad 
   1533  1.1  riastrad 	adev->nbio.funcs->get_clockgating_state(adev, flags);
   1534  1.1  riastrad 
   1535  1.1  riastrad 	/* AMD_CG_SUPPORT_HDP_LS */
   1536  1.1  riastrad 	data = RREG32(SOC15_REG_OFFSET(HDP, 0, mmHDP_MEM_POWER_LS));
   1537  1.1  riastrad 	if (data & HDP_MEM_POWER_LS__LS_ENABLE_MASK)
   1538  1.1  riastrad 		*flags |= AMD_CG_SUPPORT_HDP_LS;
   1539  1.1  riastrad 
   1540  1.1  riastrad 	/* AMD_CG_SUPPORT_DRM_MGCG */
   1541  1.1  riastrad 	data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_CGTT_CTRL0));
   1542  1.1  riastrad 	if (!(data & 0x01000000))
   1543  1.1  riastrad 		*flags |= AMD_CG_SUPPORT_DRM_MGCG;
   1544  1.1  riastrad 
   1545  1.1  riastrad 	/* AMD_CG_SUPPORT_DRM_LS */
   1546  1.1  riastrad 	data = RREG32(SOC15_REG_OFFSET(MP0, 0, mmMP0_MISC_LIGHT_SLEEP_CTRL));
   1547  1.1  riastrad 	if (data & 0x1)
   1548  1.1  riastrad 		*flags |= AMD_CG_SUPPORT_DRM_LS;
   1549  1.1  riastrad 
   1550  1.1  riastrad 	/* AMD_CG_SUPPORT_ROM_MGCG */
   1551  1.1  riastrad 	data = RREG32(SOC15_REG_OFFSET(SMUIO, 0, mmCGTT_ROM_CLK_CTRL0));
   1552  1.1  riastrad 	if (!(data & CGTT_ROM_CLK_CTRL0__SOFT_OVERRIDE0_MASK))
   1553  1.1  riastrad 		*flags |= AMD_CG_SUPPORT_ROM_MGCG;
   1554  1.1  riastrad 
   1555  1.1  riastrad 	adev->df.funcs->get_clockgating_state(adev, flags);
   1556  1.1  riastrad }
   1557  1.1  riastrad 
   1558  1.1  riastrad static int soc15_common_set_powergating_state(void *handle,
   1559  1.1  riastrad 					    enum amd_powergating_state state)
   1560  1.1  riastrad {
   1561  1.1  riastrad 	/* todo */
   1562  1.1  riastrad 	return 0;
   1563  1.1  riastrad }
   1564  1.1  riastrad 
   1565  1.1  riastrad const struct amd_ip_funcs soc15_common_ip_funcs = {
   1566  1.1  riastrad 	.name = "soc15_common",
   1567  1.1  riastrad 	.early_init = soc15_common_early_init,
   1568  1.1  riastrad 	.late_init = soc15_common_late_init,
   1569  1.1  riastrad 	.sw_init = soc15_common_sw_init,
   1570  1.1  riastrad 	.sw_fini = soc15_common_sw_fini,
   1571  1.1  riastrad 	.hw_init = soc15_common_hw_init,
   1572  1.1  riastrad 	.hw_fini = soc15_common_hw_fini,
   1573  1.1  riastrad 	.suspend = soc15_common_suspend,
   1574  1.1  riastrad 	.resume = soc15_common_resume,
   1575  1.1  riastrad 	.is_idle = soc15_common_is_idle,
   1576  1.1  riastrad 	.wait_for_idle = soc15_common_wait_for_idle,
   1577  1.1  riastrad 	.soft_reset = soc15_common_soft_reset,
   1578  1.1  riastrad 	.set_clockgating_state = soc15_common_set_clockgating_state,
   1579  1.1  riastrad 	.set_powergating_state = soc15_common_set_powergating_state,
   1580  1.1  riastrad 	.get_clockgating_state= soc15_common_get_clockgating_state,
   1581  1.1  riastrad };
   1582