xref: /linux/drivers/gpu/drm/amd/amdgpu/nbio_v4_3.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
10d09a60eSStanley.Yang /*
20d09a60eSStanley.Yang  * Copyright 2021 Advanced Micro Devices, Inc.
30d09a60eSStanley.Yang  *
40d09a60eSStanley.Yang  * Permission is hereby granted, free of charge, to any person obtaining a
50d09a60eSStanley.Yang  * copy of this software and associated documentation files (the "Software"),
60d09a60eSStanley.Yang  * to deal in the Software without restriction, including without limitation
70d09a60eSStanley.Yang  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80d09a60eSStanley.Yang  * and/or sell copies of the Software, and to permit persons to whom the
90d09a60eSStanley.Yang  * Software is furnished to do so, subject to the following conditions:
100d09a60eSStanley.Yang  *
110d09a60eSStanley.Yang  * The above copyright notice and this permission notice shall be included in
120d09a60eSStanley.Yang  * all copies or substantial portions of the Software.
130d09a60eSStanley.Yang  *
140d09a60eSStanley.Yang  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150d09a60eSStanley.Yang  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160d09a60eSStanley.Yang  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
170d09a60eSStanley.Yang  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
180d09a60eSStanley.Yang  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
190d09a60eSStanley.Yang  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
200d09a60eSStanley.Yang  * OTHER DEALINGS IN THE SOFTWARE.
210d09a60eSStanley.Yang  *
220d09a60eSStanley.Yang  */
230d09a60eSStanley.Yang #include "amdgpu.h"
240d09a60eSStanley.Yang #include "amdgpu_atombios.h"
250d09a60eSStanley.Yang #include "nbio_v4_3.h"
260d09a60eSStanley.Yang 
270d09a60eSStanley.Yang #include "nbio/nbio_4_3_0_offset.h"
280d09a60eSStanley.Yang #include "nbio/nbio_4_3_0_sh_mask.h"
299af357bcSHawking Zhang #include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
300d09a60eSStanley.Yang #include <uapi/linux/kfd_ioctl.h>
310d09a60eSStanley.Yang 
nbio_v4_3_remap_hdp_registers(struct amdgpu_device * adev)320d09a60eSStanley.Yang static void nbio_v4_3_remap_hdp_registers(struct amdgpu_device *adev)
330d09a60eSStanley.Yang {
340d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_MEM_FLUSH_CNTL,
350d09a60eSStanley.Yang 		adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL);
360d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_REG_FLUSH_CNTL,
370d09a60eSStanley.Yang 		adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_REG_FLUSH_CNTL);
380d09a60eSStanley.Yang }
390d09a60eSStanley.Yang 
nbio_v4_3_get_rev_id(struct amdgpu_device * adev)400d09a60eSStanley.Yang static u32 nbio_v4_3_get_rev_id(struct amdgpu_device *adev)
410d09a60eSStanley.Yang {
420d09a60eSStanley.Yang 	u32 tmp = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_DEV0_EPF0_STRAP0);
430d09a60eSStanley.Yang 
440d09a60eSStanley.Yang 	tmp &= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0_MASK;
450d09a60eSStanley.Yang 	tmp >>= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0__SHIFT;
460d09a60eSStanley.Yang 
470d09a60eSStanley.Yang 	return tmp;
480d09a60eSStanley.Yang }
490d09a60eSStanley.Yang 
nbio_v4_3_mc_access_enable(struct amdgpu_device * adev,bool enable)500d09a60eSStanley.Yang static void nbio_v4_3_mc_access_enable(struct amdgpu_device *adev, bool enable)
510d09a60eSStanley.Yang {
520d09a60eSStanley.Yang 	if (enable)
530d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_FB_EN,
540d09a60eSStanley.Yang 			     BIF_BX0_BIF_FB_EN__FB_READ_EN_MASK |
550d09a60eSStanley.Yang 			     BIF_BX0_BIF_FB_EN__FB_WRITE_EN_MASK);
560d09a60eSStanley.Yang 	else
570d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_FB_EN, 0);
580d09a60eSStanley.Yang }
590d09a60eSStanley.Yang 
nbio_v4_3_get_memsize(struct amdgpu_device * adev)600d09a60eSStanley.Yang static u32 nbio_v4_3_get_memsize(struct amdgpu_device *adev)
610d09a60eSStanley.Yang {
620d09a60eSStanley.Yang 	return RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_RCC_CONFIG_MEMSIZE);
630d09a60eSStanley.Yang }
640d09a60eSStanley.Yang 
nbio_v4_3_sdma_doorbell_range(struct amdgpu_device * adev,int instance,bool use_doorbell,int doorbell_index,int doorbell_size)650d09a60eSStanley.Yang static void nbio_v4_3_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
660d09a60eSStanley.Yang 					  bool use_doorbell, int doorbell_index,
670d09a60eSStanley.Yang 					  int doorbell_size)
680d09a60eSStanley.Yang {
690d09a60eSStanley.Yang 	if (instance == 0) {
700d09a60eSStanley.Yang 		u32 doorbell_range = RREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_2_CTRL);
710d09a60eSStanley.Yang 
720d09a60eSStanley.Yang 		if (use_doorbell) {
730d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
740d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
750d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_ENABLE,
760d09a60eSStanley.Yang 						       0x1);
770d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
780d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
790d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_AWID,
800d09a60eSStanley.Yang 						       0xe);
810d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
820d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
830d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_RANGE_OFFSET,
840d09a60eSStanley.Yang 						       doorbell_index);
850d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
860d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
870d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_RANGE_SIZE,
880d09a60eSStanley.Yang 						       doorbell_size);
890d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
900d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
910d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_AWADDR_31_28_VALUE,
920d09a60eSStanley.Yang 						       0x3);
930d09a60eSStanley.Yang 		} else
940d09a60eSStanley.Yang 			doorbell_range = REG_SET_FIELD(doorbell_range,
950d09a60eSStanley.Yang 						       S2A_DOORBELL_ENTRY_2_CTRL,
960d09a60eSStanley.Yang 						       S2A_DOORBELL_PORT2_RANGE_SIZE,
970d09a60eSStanley.Yang 						       0);
980d09a60eSStanley.Yang 
990d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_2_CTRL, doorbell_range);
1000d09a60eSStanley.Yang 	}
1010d09a60eSStanley.Yang }
1020d09a60eSStanley.Yang 
nbio_v4_3_vcn_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index,int instance)1030d09a60eSStanley.Yang static void nbio_v4_3_vcn_doorbell_range(struct amdgpu_device *adev, bool use_doorbell,
1040d09a60eSStanley.Yang 					 int doorbell_index, int instance)
1050d09a60eSStanley.Yang {
1060d09a60eSStanley.Yang 	u32 doorbell_range;
1070d09a60eSStanley.Yang 
1080d09a60eSStanley.Yang 	if (instance)
1090d09a60eSStanley.Yang 		doorbell_range = RREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_5_CTRL);
1100d09a60eSStanley.Yang 	else
1110d09a60eSStanley.Yang 		doorbell_range = RREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_4_CTRL);
1120d09a60eSStanley.Yang 
1130d09a60eSStanley.Yang 	if (use_doorbell) {
1140d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1150d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1160d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_ENABLE,
1170d09a60eSStanley.Yang 					       0x1);
1180d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1190d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1200d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_AWID,
1210d09a60eSStanley.Yang 					       instance ? 0x7 : 0x4);
1220d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1230d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1240d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_RANGE_OFFSET,
1250d09a60eSStanley.Yang 					       doorbell_index);
1260d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1270d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1280d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_RANGE_SIZE,
1290d09a60eSStanley.Yang 					       8);
1300d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1310d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1320d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_AWADDR_31_28_VALUE,
1330d09a60eSStanley.Yang 					       instance ? 0x7 : 0x4);
1340d09a60eSStanley.Yang 	} else
1350d09a60eSStanley.Yang 		doorbell_range = REG_SET_FIELD(doorbell_range,
1360d09a60eSStanley.Yang 					       S2A_DOORBELL_ENTRY_4_CTRL,
1370d09a60eSStanley.Yang 					       S2A_DOORBELL_PORT4_RANGE_SIZE,
1380d09a60eSStanley.Yang 					       0);
1390d09a60eSStanley.Yang 
1400d09a60eSStanley.Yang 	if (instance)
1410d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_5_CTRL, doorbell_range);
1420d09a60eSStanley.Yang 	else
1430d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_4_CTRL, doorbell_range);
1440d09a60eSStanley.Yang }
1450d09a60eSStanley.Yang 
nbio_v4_3_gc_doorbell_init(struct amdgpu_device * adev)1460d09a60eSStanley.Yang static void nbio_v4_3_gc_doorbell_init(struct amdgpu_device *adev)
1470d09a60eSStanley.Yang {
1480d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_0_CTRL, 0x30000007);
1490d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_3_CTRL, 0x3000000d);
1500d09a60eSStanley.Yang }
1510d09a60eSStanley.Yang 
nbio_v4_3_enable_doorbell_aperture(struct amdgpu_device * adev,bool enable)1520d09a60eSStanley.Yang static void nbio_v4_3_enable_doorbell_aperture(struct amdgpu_device *adev,
1530d09a60eSStanley.Yang 					       bool enable)
1540d09a60eSStanley.Yang {
1550d09a60eSStanley.Yang 	WREG32_FIELD15_PREREG(NBIO, 0, RCC_DEV0_EPF0_RCC_DOORBELL_APER_EN,
1560d09a60eSStanley.Yang 			BIF_DOORBELL_APER_EN, enable ? 1 : 0);
1570d09a60eSStanley.Yang }
1580d09a60eSStanley.Yang 
nbio_v4_3_enable_doorbell_selfring_aperture(struct amdgpu_device * adev,bool enable)1590d09a60eSStanley.Yang static void nbio_v4_3_enable_doorbell_selfring_aperture(struct amdgpu_device *adev,
1600d09a60eSStanley.Yang 							bool enable)
1610d09a60eSStanley.Yang {
1620d09a60eSStanley.Yang 	u32 tmp = 0;
1630d09a60eSStanley.Yang 
1640d09a60eSStanley.Yang 	if (enable) {
1650d09a60eSStanley.Yang 		tmp = REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,
1660d09a60eSStanley.Yang 				    DOORBELL_SELFRING_GPA_APER_EN, 1) |
1670d09a60eSStanley.Yang 		      REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,
1680d09a60eSStanley.Yang 				    DOORBELL_SELFRING_GPA_APER_MODE, 1) |
1690d09a60eSStanley.Yang 		      REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,
1700d09a60eSStanley.Yang 				    DOORBELL_SELFRING_GPA_APER_SIZE, 0);
1710d09a60eSStanley.Yang 
1720d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_BASE_LOW,
1730d09a60eSStanley.Yang 			     lower_32_bits(adev->doorbell.base));
1740d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_BASE_HIGH,
1750d09a60eSStanley.Yang 			     upper_32_bits(adev->doorbell.base));
1760d09a60eSStanley.Yang 	}
1770d09a60eSStanley.Yang 
1780d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,
1790d09a60eSStanley.Yang 		     tmp);
1800d09a60eSStanley.Yang }
1810d09a60eSStanley.Yang 
nbio_v4_3_ih_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index)1820d09a60eSStanley.Yang static void nbio_v4_3_ih_doorbell_range(struct amdgpu_device *adev,
1830d09a60eSStanley.Yang 					bool use_doorbell, int doorbell_index)
1840d09a60eSStanley.Yang {
1850d09a60eSStanley.Yang 	u32 ih_doorbell_range = RREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_1_CTRL);
1860d09a60eSStanley.Yang 
1870d09a60eSStanley.Yang 	if (use_doorbell) {
1880d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
1890d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
1900d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_ENABLE,
1910d09a60eSStanley.Yang 						  0x1);
1920d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
1930d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
1940d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_AWID,
1950d09a60eSStanley.Yang 						  0x0);
1960d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
1970d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
1980d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_RANGE_OFFSET,
1990d09a60eSStanley.Yang 						  doorbell_index);
2000d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
2010d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
2020d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_RANGE_SIZE,
2030d09a60eSStanley.Yang 						  2);
2040d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
2050d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
2060d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_AWADDR_31_28_VALUE,
2070d09a60eSStanley.Yang 						  0x0);
2080d09a60eSStanley.Yang 	} else
2090d09a60eSStanley.Yang 		ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
2100d09a60eSStanley.Yang 						  S2A_DOORBELL_ENTRY_1_CTRL,
2110d09a60eSStanley.Yang 						  S2A_DOORBELL_PORT1_RANGE_SIZE,
2120d09a60eSStanley.Yang 						  0);
2130d09a60eSStanley.Yang 
2140d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regS2A_DOORBELL_ENTRY_1_CTRL, ih_doorbell_range);
2150d09a60eSStanley.Yang }
2160d09a60eSStanley.Yang 
nbio_v4_3_ih_control(struct amdgpu_device * adev)2170d09a60eSStanley.Yang static void nbio_v4_3_ih_control(struct amdgpu_device *adev)
2180d09a60eSStanley.Yang {
2190d09a60eSStanley.Yang 	u32 interrupt_cntl;
2200d09a60eSStanley.Yang 
2210d09a60eSStanley.Yang 	/* setup interrupt control */
2220d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regBIF_BX0_INTERRUPT_CNTL2, adev->dummy_page_addr >> 8);
2230d09a60eSStanley.Yang 
2240d09a60eSStanley.Yang 	interrupt_cntl = RREG32_SOC15(NBIO, 0, regBIF_BX0_INTERRUPT_CNTL);
2250d09a60eSStanley.Yang 	/*
2260d09a60eSStanley.Yang 	 * BIF_BX0_INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=0 - dummy read disabled with msi, enabled without msi
2270d09a60eSStanley.Yang 	 * BIF_BX0_INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=1 - dummy read controlled by IH_DUMMY_RD_EN
2280d09a60eSStanley.Yang 	 */
2290d09a60eSStanley.Yang 	interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX0_INTERRUPT_CNTL,
2300d09a60eSStanley.Yang 				       IH_DUMMY_RD_OVERRIDE, 0);
2310d09a60eSStanley.Yang 
2320d09a60eSStanley.Yang 	/* BIF_BX0_INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */
2330d09a60eSStanley.Yang 	interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX0_INTERRUPT_CNTL,
2340d09a60eSStanley.Yang 				       IH_REQ_NONSNOOP_EN, 0);
2350d09a60eSStanley.Yang 
2360d09a60eSStanley.Yang 	WREG32_SOC15(NBIO, 0, regBIF_BX0_INTERRUPT_CNTL, interrupt_cntl);
2370d09a60eSStanley.Yang }
2380d09a60eSStanley.Yang 
nbio_v4_3_update_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)2390d09a60eSStanley.Yang static void nbio_v4_3_update_medium_grain_clock_gating(struct amdgpu_device *adev,
2400d09a60eSStanley.Yang 						       bool enable)
2410d09a60eSStanley.Yang {
2420d09a60eSStanley.Yang 	uint32_t def, data;
2430d09a60eSStanley.Yang 
2441b3aa895SEvan Quan 	if (enable && !(adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG))
2451b3aa895SEvan Quan 		return;
2461b3aa895SEvan Quan 
2470d09a60eSStanley.Yang 	def = data = RREG32_SOC15(NBIO, 0, regCPM_CONTROL);
2481b3aa895SEvan Quan 	if (enable) {
2490d09a60eSStanley.Yang 		data |= (CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
2500d09a60eSStanley.Yang 			 CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
2510d09a60eSStanley.Yang 			 CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
2520d09a60eSStanley.Yang 			 CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
2530d09a60eSStanley.Yang 			 CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
2540d09a60eSStanley.Yang 			 CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
2550d09a60eSStanley.Yang 	} else {
2560d09a60eSStanley.Yang 		data &= ~(CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
2570d09a60eSStanley.Yang 			  CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
2580d09a60eSStanley.Yang 			  CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
2590d09a60eSStanley.Yang 			  CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
2600d09a60eSStanley.Yang 			  CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
2610d09a60eSStanley.Yang 			  CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
2620d09a60eSStanley.Yang 	}
2630d09a60eSStanley.Yang 
2640d09a60eSStanley.Yang 	if (def != data)
2650d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regCPM_CONTROL, data);
2660d09a60eSStanley.Yang }
2670d09a60eSStanley.Yang 
nbio_v4_3_update_medium_grain_light_sleep(struct amdgpu_device * adev,bool enable)2680d09a60eSStanley.Yang static void nbio_v4_3_update_medium_grain_light_sleep(struct amdgpu_device *adev,
2690d09a60eSStanley.Yang 						      bool enable)
2700d09a60eSStanley.Yang {
2710d09a60eSStanley.Yang 	uint32_t def, data;
2720d09a60eSStanley.Yang 
2731b3aa895SEvan Quan 	if (enable && !(adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
2741b3aa895SEvan Quan 		return;
2751b3aa895SEvan Quan 
2760d09a60eSStanley.Yang 	/* TODO: need update in future */
2770d09a60eSStanley.Yang 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_CNTL2);
2781b3aa895SEvan Quan 	if (enable) {
2790d09a60eSStanley.Yang 		data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
2800d09a60eSStanley.Yang 	} else {
2810d09a60eSStanley.Yang 		data &= ~PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
2820d09a60eSStanley.Yang 	}
2830d09a60eSStanley.Yang 
2840d09a60eSStanley.Yang 	if (def != data)
2850d09a60eSStanley.Yang 		WREG32_SOC15(NBIO, 0, regPCIE_CNTL2, data);
2860d09a60eSStanley.Yang }
2870d09a60eSStanley.Yang 
nbio_v4_3_get_clockgating_state(struct amdgpu_device * adev,u64 * flags)2880d09a60eSStanley.Yang static void nbio_v4_3_get_clockgating_state(struct amdgpu_device *adev,
2890d09a60eSStanley.Yang 					    u64 *flags)
2900d09a60eSStanley.Yang {
2910d09a60eSStanley.Yang 	int data;
2920d09a60eSStanley.Yang 
2930d09a60eSStanley.Yang 	/* AMD_CG_SUPPORT_BIF_MGCG */
2940d09a60eSStanley.Yang 	data = RREG32_SOC15(NBIO, 0, regCPM_CONTROL);
2950d09a60eSStanley.Yang 	if (data & CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK)
2960d09a60eSStanley.Yang 		*flags |= AMD_CG_SUPPORT_BIF_MGCG;
2970d09a60eSStanley.Yang 
2980d09a60eSStanley.Yang 	/* AMD_CG_SUPPORT_BIF_LS */
2990d09a60eSStanley.Yang 	data = RREG32_SOC15(NBIO, 0, regPCIE_CNTL2);
3000d09a60eSStanley.Yang 	if (data & PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
3010d09a60eSStanley.Yang 		*flags |= AMD_CG_SUPPORT_BIF_LS;
3020d09a60eSStanley.Yang }
3030d09a60eSStanley.Yang 
nbio_v4_3_get_hdp_flush_req_offset(struct amdgpu_device * adev)3040d09a60eSStanley.Yang static u32 nbio_v4_3_get_hdp_flush_req_offset(struct amdgpu_device *adev)
3050d09a60eSStanley.Yang {
3060d09a60eSStanley.Yang 	return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_GPU_HDP_FLUSH_REQ);
3070d09a60eSStanley.Yang }
3080d09a60eSStanley.Yang 
nbio_v4_3_get_hdp_flush_done_offset(struct amdgpu_device * adev)3090d09a60eSStanley.Yang static u32 nbio_v4_3_get_hdp_flush_done_offset(struct amdgpu_device *adev)
3100d09a60eSStanley.Yang {
3110d09a60eSStanley.Yang 	return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_GPU_HDP_FLUSH_DONE);
3120d09a60eSStanley.Yang }
3130d09a60eSStanley.Yang 
nbio_v4_3_get_pcie_index_offset(struct amdgpu_device * adev)3140d09a60eSStanley.Yang static u32 nbio_v4_3_get_pcie_index_offset(struct amdgpu_device *adev)
3150d09a60eSStanley.Yang {
3160d09a60eSStanley.Yang 	return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_RSMU_INDEX);
3170d09a60eSStanley.Yang }
3180d09a60eSStanley.Yang 
nbio_v4_3_get_pcie_data_offset(struct amdgpu_device * adev)3190d09a60eSStanley.Yang static u32 nbio_v4_3_get_pcie_data_offset(struct amdgpu_device *adev)
3200d09a60eSStanley.Yang {
3210d09a60eSStanley.Yang 	return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_RSMU_DATA);
3220d09a60eSStanley.Yang }
3230d09a60eSStanley.Yang 
3240d09a60eSStanley.Yang const struct nbio_hdp_flush_reg nbio_v4_3_hdp_flush_reg = {
3250d09a60eSStanley.Yang 	.ref_and_mask_cp0 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP0_MASK,
3260d09a60eSStanley.Yang 	.ref_and_mask_cp1 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP1_MASK,
3270d09a60eSStanley.Yang 	.ref_and_mask_cp2 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP2_MASK,
3280d09a60eSStanley.Yang 	.ref_and_mask_cp3 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP3_MASK,
3290d09a60eSStanley.Yang 	.ref_and_mask_cp4 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP4_MASK,
3300d09a60eSStanley.Yang 	.ref_and_mask_cp5 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP5_MASK,
3310d09a60eSStanley.Yang 	.ref_and_mask_cp6 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP6_MASK,
3320d09a60eSStanley.Yang 	.ref_and_mask_cp7 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP7_MASK,
3330d09a60eSStanley.Yang 	.ref_and_mask_cp8 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP8_MASK,
3340d09a60eSStanley.Yang 	.ref_and_mask_cp9 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP9_MASK,
3350d09a60eSStanley.Yang 	.ref_and_mask_sdma0 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__SDMA0_MASK,
3360d09a60eSStanley.Yang 	.ref_and_mask_sdma1 = BIF_BX_PF_GPU_HDP_FLUSH_DONE__SDMA1_MASK,
3370d09a60eSStanley.Yang };
3380d09a60eSStanley.Yang 
nbio_v4_3_init_registers(struct amdgpu_device * adev)3390d09a60eSStanley.Yang static void nbio_v4_3_init_registers(struct amdgpu_device *adev)
3400d09a60eSStanley.Yang {
3414e8303cfSLijo Lazar 	if (amdgpu_ip_version(adev, NBIO_HWIP, 0) == IP_VERSION(4, 3, 0)) {
3425048fa1eSMario Limonciello 		uint32_t data;
3435048fa1eSMario Limonciello 
3445048fa1eSMario Limonciello 		data = RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF2_STRAP2);
3455048fa1eSMario Limonciello 		data &= ~RCC_DEV0_EPF2_STRAP2__STRAP_NO_SOFT_RESET_DEV0_F2_MASK;
3465048fa1eSMario Limonciello 		WREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF2_STRAP2, data);
3475048fa1eSMario Limonciello 	}
3480d09a60eSStanley.Yang }
3490d09a60eSStanley.Yang 
nbio_v4_3_get_rom_offset(struct amdgpu_device * adev)3500d09a60eSStanley.Yang static u32 nbio_v4_3_get_rom_offset(struct amdgpu_device *adev)
3510d09a60eSStanley.Yang {
3520d09a60eSStanley.Yang 	u32 data, rom_offset;
3530d09a60eSStanley.Yang 
3540d09a60eSStanley.Yang 	data = RREG32_SOC15(NBIO, 0, regREGS_ROM_OFFSET_CTRL);
3550d09a60eSStanley.Yang 	rom_offset = REG_GET_FIELD(data, REGS_ROM_OFFSET_CTRL, ROM_OFFSET);
3560d09a60eSStanley.Yang 
3570d09a60eSStanley.Yang 	return rom_offset;
3580d09a60eSStanley.Yang }
3590d09a60eSStanley.Yang 
36062f8f5c3SEvan Quan #ifdef CONFIG_PCIEASPM
nbio_v4_3_program_ltr(struct amdgpu_device * adev)36162f8f5c3SEvan Quan static void nbio_v4_3_program_ltr(struct amdgpu_device *adev)
36262f8f5c3SEvan Quan {
36362f8f5c3SEvan Quan 	uint32_t def, data;
36462f8f5c3SEvan Quan 
36562f8f5c3SEvan Quan 	def = RREG32_SOC15(NBIO, 0, regRCC_EP_DEV0_0_EP_PCIE_TX_LTR_CNTL);
36662f8f5c3SEvan Quan 	data = 0x35EB;
36762f8f5c3SEvan Quan 	data &= ~EP_PCIE_TX_LTR_CNTL__LTR_PRIV_MSG_DIS_IN_PM_NON_D0_MASK;
36862f8f5c3SEvan Quan 	data &= ~EP_PCIE_TX_LTR_CNTL__LTR_PRIV_RST_LTR_IN_DL_DOWN_MASK;
36962f8f5c3SEvan Quan 	if (def != data)
37062f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_EP_DEV0_0_EP_PCIE_TX_LTR_CNTL, data);
37162f8f5c3SEvan Quan 
37262f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP2);
37362f8f5c3SEvan Quan 	data &= ~RCC_BIF_STRAP2__STRAP_LTR_IN_ASPML1_DIS_MASK;
37462f8f5c3SEvan Quan 	if (def != data)
37562f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP2, data);
37662f8f5c3SEvan Quan 
37762f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regBIF_CFG_DEV0_EPF0_DEVICE_CNTL2);
37862f8f5c3SEvan Quan 	if (adev->pdev->ltr_path)
37962f8f5c3SEvan Quan 		data |= BIF_CFG_DEV0_EPF0_DEVICE_CNTL2__LTR_EN_MASK;
38062f8f5c3SEvan Quan 	else
38162f8f5c3SEvan Quan 		data &= ~BIF_CFG_DEV0_EPF0_DEVICE_CNTL2__LTR_EN_MASK;
38262f8f5c3SEvan Quan 	if (def != data)
38362f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regBIF_CFG_DEV0_EPF0_DEVICE_CNTL2, data);
38462f8f5c3SEvan Quan }
38562f8f5c3SEvan Quan #endif
38662f8f5c3SEvan Quan 
nbio_v4_3_program_aspm(struct amdgpu_device * adev)38762f8f5c3SEvan Quan static void nbio_v4_3_program_aspm(struct amdgpu_device *adev)
38862f8f5c3SEvan Quan {
38962f8f5c3SEvan Quan #ifdef CONFIG_PCIEASPM
39062f8f5c3SEvan Quan 	uint32_t def, data;
39162f8f5c3SEvan Quan 
3924e8303cfSLijo Lazar 	if (!(amdgpu_ip_version(adev, PCIE_HWIP, 0) == IP_VERSION(7, 4, 0)) &&
3934e8303cfSLijo Lazar 	    !(amdgpu_ip_version(adev, PCIE_HWIP, 0) == IP_VERSION(7, 6, 0)))
39462f8f5c3SEvan Quan 		return;
39562f8f5c3SEvan Quan 
39662f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL);
39762f8f5c3SEvan Quan 	data &= ~PCIE_LC_CNTL__LC_L1_INACTIVITY_MASK;
39862f8f5c3SEvan Quan 	data &= ~PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK;
39962f8f5c3SEvan Quan 	data |= PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
40062f8f5c3SEvan Quan 	if (def != data)
40162f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL, data);
40262f8f5c3SEvan Quan 
40362f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL7);
40462f8f5c3SEvan Quan 	data |= PCIE_LC_CNTL7__LC_NBIF_ASPM_INPUT_EN_MASK;
40562f8f5c3SEvan Quan 	if (def != data)
40662f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL7, data);
40762f8f5c3SEvan Quan 
40862f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL3);
40962f8f5c3SEvan Quan 	data |= PCIE_LC_CNTL3__LC_DSC_DONT_ENTER_L23_AFTER_PME_ACK_MASK;
41062f8f5c3SEvan Quan 	if (def != data)
41162f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL3, data);
41262f8f5c3SEvan Quan 
41362f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP3);
41462f8f5c3SEvan Quan 	data &= ~RCC_BIF_STRAP3__STRAP_VLINK_ASPM_IDLE_TIMER_MASK;
41562f8f5c3SEvan Quan 	data &= ~RCC_BIF_STRAP3__STRAP_VLINK_PM_L1_ENTRY_TIMER_MASK;
41662f8f5c3SEvan Quan 	if (def != data)
41762f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP3, data);
41862f8f5c3SEvan Quan 
41962f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP5);
42062f8f5c3SEvan Quan 	data &= ~RCC_BIF_STRAP5__STRAP_VLINK_LDN_ENTRY_TIMER_MASK;
42162f8f5c3SEvan Quan 	if (def != data)
42262f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP5, data);
42362f8f5c3SEvan Quan 
42462f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regBIF_CFG_DEV0_EPF0_DEVICE_CNTL2);
42562f8f5c3SEvan Quan 	data &= ~BIF_CFG_DEV0_EPF0_DEVICE_CNTL2__LTR_EN_MASK;
42662f8f5c3SEvan Quan 	if (def != data)
42762f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regBIF_CFG_DEV0_EPF0_DEVICE_CNTL2, data);
42862f8f5c3SEvan Quan 
42962f8f5c3SEvan Quan 	WREG32_SOC15(NBIO, 0, regBIF_CFG_DEV0_EPF0_PCIE_LTR_CAP, 0x10011001);
43062f8f5c3SEvan Quan 
43162f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPSWUSP0_PCIE_LC_CNTL2);
43262f8f5c3SEvan Quan 	data |= PSWUSP0_PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L1_MASK |
43362f8f5c3SEvan Quan 		PSWUSP0_PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L23_MASK;
43462f8f5c3SEvan Quan 	data &= ~PSWUSP0_PCIE_LC_CNTL2__LC_RCV_L0_TO_RCV_L0S_DIS_MASK;
43562f8f5c3SEvan Quan 	if (def != data)
43662f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPSWUSP0_PCIE_LC_CNTL2, data);
43762f8f5c3SEvan Quan 
43862f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL4);
43962f8f5c3SEvan Quan 	data |= PCIE_LC_CNTL4__LC_L1_POWERDOWN_MASK;
44062f8f5c3SEvan Quan 	if (def != data)
44162f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL4, data);
44262f8f5c3SEvan Quan 
44362f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_RXRECOVER_RXSTANDBY_CNTL);
44462f8f5c3SEvan Quan 	data |= PCIE_LC_RXRECOVER_RXSTANDBY_CNTL__LC_RX_L0S_STANDBY_EN_MASK;
44562f8f5c3SEvan Quan 	if (def != data)
44662f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_RXRECOVER_RXSTANDBY_CNTL, data);
44762f8f5c3SEvan Quan 
44862f8f5c3SEvan Quan 	nbio_v4_3_program_ltr(adev);
44962f8f5c3SEvan Quan 
45062f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP3);
45162f8f5c3SEvan Quan 	data |= 0x5DE0 << RCC_BIF_STRAP3__STRAP_VLINK_ASPM_IDLE_TIMER__SHIFT;
45262f8f5c3SEvan Quan 	data |= 0x0010 << RCC_BIF_STRAP3__STRAP_VLINK_PM_L1_ENTRY_TIMER__SHIFT;
45362f8f5c3SEvan Quan 	if (def != data)
45462f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP3, data);
45562f8f5c3SEvan Quan 
45662f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP5);
45762f8f5c3SEvan Quan 	data |= 0x0010 << RCC_BIF_STRAP5__STRAP_VLINK_LDN_ENTRY_TIMER__SHIFT;
45862f8f5c3SEvan Quan 	if (def != data)
45962f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regRCC_STRAP0_RCC_BIF_STRAP5, data);
46062f8f5c3SEvan Quan 
46162f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL);
46262f8f5c3SEvan Quan 	data |= 0x0 << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT;
46362f8f5c3SEvan Quan 	data |= 0x9 << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT;
46462f8f5c3SEvan Quan 	data &= ~PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
46562f8f5c3SEvan Quan 	if (def != data)
46662f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL, data);
46762f8f5c3SEvan Quan 
46862f8f5c3SEvan Quan 	def = data = RREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL3);
46962f8f5c3SEvan Quan 	data &= ~PCIE_LC_CNTL3__LC_DSC_DONT_ENTER_L23_AFTER_PME_ACK_MASK;
47062f8f5c3SEvan Quan 	if (def != data)
47162f8f5c3SEvan Quan 		WREG32_SOC15(NBIO, 0, regPCIE_LC_CNTL3, data);
47262f8f5c3SEvan Quan #endif
47362f8f5c3SEvan Quan }
47462f8f5c3SEvan Quan 
475*ffd3d6e7SAlex Deucher #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
476*ffd3d6e7SAlex Deucher 
nbio_v4_3_set_reg_remap(struct amdgpu_device * adev)477*ffd3d6e7SAlex Deucher static void nbio_v4_3_set_reg_remap(struct amdgpu_device *adev)
478*ffd3d6e7SAlex Deucher {
479*ffd3d6e7SAlex Deucher 	if (!amdgpu_sriov_vf(adev) && (PAGE_SIZE <= 4096)) {
480*ffd3d6e7SAlex Deucher 		adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
481*ffd3d6e7SAlex Deucher 		adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
482*ffd3d6e7SAlex Deucher 	} else {
483*ffd3d6e7SAlex Deucher 		adev->rmmio_remap.reg_offset = SOC15_REG_OFFSET(NBIO, 0,
484*ffd3d6e7SAlex Deucher 			regBIF_BX_DEV0_EPF0_VF0_HDP_MEM_COHERENCY_FLUSH_CNTL) << 2;
485*ffd3d6e7SAlex Deucher 		adev->rmmio_remap.bus_addr = 0;
486*ffd3d6e7SAlex Deucher 	}
487*ffd3d6e7SAlex Deucher }
488*ffd3d6e7SAlex Deucher 
4890d09a60eSStanley.Yang const struct amdgpu_nbio_funcs nbio_v4_3_funcs = {
4900d09a60eSStanley.Yang 	.get_hdp_flush_req_offset = nbio_v4_3_get_hdp_flush_req_offset,
4910d09a60eSStanley.Yang 	.get_hdp_flush_done_offset = nbio_v4_3_get_hdp_flush_done_offset,
4920d09a60eSStanley.Yang 	.get_pcie_index_offset = nbio_v4_3_get_pcie_index_offset,
4930d09a60eSStanley.Yang 	.get_pcie_data_offset = nbio_v4_3_get_pcie_data_offset,
4940d09a60eSStanley.Yang 	.get_rev_id = nbio_v4_3_get_rev_id,
4950d09a60eSStanley.Yang 	.mc_access_enable = nbio_v4_3_mc_access_enable,
4960d09a60eSStanley.Yang 	.get_memsize = nbio_v4_3_get_memsize,
4970d09a60eSStanley.Yang 	.sdma_doorbell_range = nbio_v4_3_sdma_doorbell_range,
4980d09a60eSStanley.Yang 	.vcn_doorbell_range = nbio_v4_3_vcn_doorbell_range,
4990d09a60eSStanley.Yang 	.gc_doorbell_init = nbio_v4_3_gc_doorbell_init,
5000d09a60eSStanley.Yang 	.enable_doorbell_aperture = nbio_v4_3_enable_doorbell_aperture,
5010d09a60eSStanley.Yang 	.enable_doorbell_selfring_aperture = nbio_v4_3_enable_doorbell_selfring_aperture,
5020d09a60eSStanley.Yang 	.ih_doorbell_range = nbio_v4_3_ih_doorbell_range,
5030d09a60eSStanley.Yang 	.update_medium_grain_clock_gating = nbio_v4_3_update_medium_grain_clock_gating,
5040d09a60eSStanley.Yang 	.update_medium_grain_light_sleep = nbio_v4_3_update_medium_grain_light_sleep,
5050d09a60eSStanley.Yang 	.get_clockgating_state = nbio_v4_3_get_clockgating_state,
5060d09a60eSStanley.Yang 	.ih_control = nbio_v4_3_ih_control,
5070d09a60eSStanley.Yang 	.init_registers = nbio_v4_3_init_registers,
5080d09a60eSStanley.Yang 	.remap_hdp_registers = nbio_v4_3_remap_hdp_registers,
5090d09a60eSStanley.Yang 	.get_rom_offset = nbio_v4_3_get_rom_offset,
51062f8f5c3SEvan Quan 	.program_aspm = nbio_v4_3_program_aspm,
511*ffd3d6e7SAlex Deucher 	.set_reg_remap = nbio_v4_3_set_reg_remap,
5120d09a60eSStanley.Yang };
513119dc6c5SHorace Chen 
514119dc6c5SHorace Chen 
nbio_v4_3_sriov_ih_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index)515119dc6c5SHorace Chen static void nbio_v4_3_sriov_ih_doorbell_range(struct amdgpu_device *adev,
516119dc6c5SHorace Chen 					bool use_doorbell, int doorbell_index)
517119dc6c5SHorace Chen {
518119dc6c5SHorace Chen }
519119dc6c5SHorace Chen 
nbio_v4_3_sriov_sdma_doorbell_range(struct amdgpu_device * adev,int instance,bool use_doorbell,int doorbell_index,int doorbell_size)520119dc6c5SHorace Chen static void nbio_v4_3_sriov_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
521119dc6c5SHorace Chen 					  bool use_doorbell, int doorbell_index,
522119dc6c5SHorace Chen 					  int doorbell_size)
523119dc6c5SHorace Chen {
524119dc6c5SHorace Chen }
525119dc6c5SHorace Chen 
nbio_v4_3_sriov_vcn_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index,int instance)526119dc6c5SHorace Chen static void nbio_v4_3_sriov_vcn_doorbell_range(struct amdgpu_device *adev, bool use_doorbell,
527119dc6c5SHorace Chen 					 int doorbell_index, int instance)
528119dc6c5SHorace Chen {
529119dc6c5SHorace Chen }
530119dc6c5SHorace Chen 
nbio_v4_3_sriov_gc_doorbell_init(struct amdgpu_device * adev)531119dc6c5SHorace Chen static void nbio_v4_3_sriov_gc_doorbell_init(struct amdgpu_device *adev)
532119dc6c5SHorace Chen {
533119dc6c5SHorace Chen }
534119dc6c5SHorace Chen 
535119dc6c5SHorace Chen const struct amdgpu_nbio_funcs nbio_v4_3_sriov_funcs = {
536119dc6c5SHorace Chen 	.get_hdp_flush_req_offset = nbio_v4_3_get_hdp_flush_req_offset,
537119dc6c5SHorace Chen 	.get_hdp_flush_done_offset = nbio_v4_3_get_hdp_flush_done_offset,
538119dc6c5SHorace Chen 	.get_pcie_index_offset = nbio_v4_3_get_pcie_index_offset,
539119dc6c5SHorace Chen 	.get_pcie_data_offset = nbio_v4_3_get_pcie_data_offset,
540119dc6c5SHorace Chen 	.get_rev_id = nbio_v4_3_get_rev_id,
541119dc6c5SHorace Chen 	.mc_access_enable = nbio_v4_3_mc_access_enable,
542119dc6c5SHorace Chen 	.get_memsize = nbio_v4_3_get_memsize,
543119dc6c5SHorace Chen 	.sdma_doorbell_range = nbio_v4_3_sriov_sdma_doorbell_range,
544119dc6c5SHorace Chen 	.vcn_doorbell_range = nbio_v4_3_sriov_vcn_doorbell_range,
545119dc6c5SHorace Chen 	.gc_doorbell_init = nbio_v4_3_sriov_gc_doorbell_init,
546119dc6c5SHorace Chen 	.enable_doorbell_aperture = nbio_v4_3_enable_doorbell_aperture,
547119dc6c5SHorace Chen 	.enable_doorbell_selfring_aperture = nbio_v4_3_enable_doorbell_selfring_aperture,
548119dc6c5SHorace Chen 	.ih_doorbell_range = nbio_v4_3_sriov_ih_doorbell_range,
549119dc6c5SHorace Chen 	.update_medium_grain_clock_gating = nbio_v4_3_update_medium_grain_clock_gating,
550119dc6c5SHorace Chen 	.update_medium_grain_light_sleep = nbio_v4_3_update_medium_grain_light_sleep,
551119dc6c5SHorace Chen 	.get_clockgating_state = nbio_v4_3_get_clockgating_state,
552119dc6c5SHorace Chen 	.ih_control = nbio_v4_3_ih_control,
553119dc6c5SHorace Chen 	.init_registers = nbio_v4_3_init_registers,
554119dc6c5SHorace Chen 	.remap_hdp_registers = nbio_v4_3_remap_hdp_registers,
555119dc6c5SHorace Chen 	.get_rom_offset = nbio_v4_3_get_rom_offset,
556*ffd3d6e7SAlex Deucher 	.set_reg_remap = nbio_v4_3_set_reg_remap,
557119dc6c5SHorace Chen };
5589af357bcSHawking Zhang 
nbio_v4_3_set_ras_err_event_athub_irq_state(struct amdgpu_device * adev,struct amdgpu_irq_src * src,unsigned type,enum amdgpu_interrupt_state state)5599af357bcSHawking Zhang static int nbio_v4_3_set_ras_err_event_athub_irq_state(struct amdgpu_device *adev,
5609af357bcSHawking Zhang 						       struct amdgpu_irq_src *src,
5619af357bcSHawking Zhang 						       unsigned type,
5629af357bcSHawking Zhang 						       enum amdgpu_interrupt_state state)
5639af357bcSHawking Zhang {
5649af357bcSHawking Zhang 	/* The ras_controller_irq enablement should be done in psp bl when it
5659af357bcSHawking Zhang 	 * tries to enable ras feature. Driver only need to set the correct interrupt
5669af357bcSHawking Zhang 	 * vector for bare-metal and sriov use case respectively
5679af357bcSHawking Zhang 	 */
5689af357bcSHawking Zhang 	uint32_t bif_doorbell_int_cntl;
5699af357bcSHawking Zhang 
5709af357bcSHawking Zhang 	bif_doorbell_int_cntl = RREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_DOORBELL_INT_CNTL);
5719af357bcSHawking Zhang 	bif_doorbell_int_cntl = REG_SET_FIELD(bif_doorbell_int_cntl,
5729af357bcSHawking Zhang 					      BIF_BX0_BIF_DOORBELL_INT_CNTL,
5739af357bcSHawking Zhang 					      RAS_ATHUB_ERR_EVENT_INTERRUPT_DISABLE,
5749af357bcSHawking Zhang 					      (state == AMDGPU_IRQ_STATE_ENABLE) ? 0 : 1);
5759af357bcSHawking Zhang 	WREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_DOORBELL_INT_CNTL, bif_doorbell_int_cntl);
5769af357bcSHawking Zhang 
5779af357bcSHawking Zhang 	return 0;
5789af357bcSHawking Zhang }
5799af357bcSHawking Zhang 
nbio_v4_3_process_err_event_athub_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)5809af357bcSHawking Zhang static int nbio_v4_3_process_err_event_athub_irq(struct amdgpu_device *adev,
5819af357bcSHawking Zhang 						 struct amdgpu_irq_src *source,
5829af357bcSHawking Zhang 						 struct amdgpu_iv_entry *entry)
5839af357bcSHawking Zhang {
5849af357bcSHawking Zhang 	/* By design, the ih cookie for err_event_athub_irq should be written
5859af357bcSHawking Zhang 	 * to bif ring. since bif ring is not enabled, just leave process callback
5869af357bcSHawking Zhang 	 * as a dummy one.
5879af357bcSHawking Zhang 	 */
5889af357bcSHawking Zhang 	return 0;
5899af357bcSHawking Zhang }
5909af357bcSHawking Zhang 
5919af357bcSHawking Zhang static const struct amdgpu_irq_src_funcs nbio_v4_3_ras_err_event_athub_irq_funcs = {
5929af357bcSHawking Zhang 	.set = nbio_v4_3_set_ras_err_event_athub_irq_state,
5939af357bcSHawking Zhang 	.process = nbio_v4_3_process_err_event_athub_irq,
5949af357bcSHawking Zhang };
5959af357bcSHawking Zhang 
nbio_v4_3_handle_ras_err_event_athub_intr_no_bifring(struct amdgpu_device * adev)5969af357bcSHawking Zhang static void nbio_v4_3_handle_ras_err_event_athub_intr_no_bifring(struct amdgpu_device *adev)
5979af357bcSHawking Zhang {
5989af357bcSHawking Zhang 	uint32_t bif_doorbell_int_cntl;
5999af357bcSHawking Zhang 
6009af357bcSHawking Zhang 	bif_doorbell_int_cntl = RREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_DOORBELL_INT_CNTL);
6019af357bcSHawking Zhang 	if (REG_GET_FIELD(bif_doorbell_int_cntl,
6029af357bcSHawking Zhang 			  BIF_DOORBELL_INT_CNTL,
6039af357bcSHawking Zhang 			  RAS_ATHUB_ERR_EVENT_INTERRUPT_STATUS)) {
6049af357bcSHawking Zhang 		/* driver has to clear the interrupt status when bif ring is disabled */
6059af357bcSHawking Zhang 		bif_doorbell_int_cntl = REG_SET_FIELD(bif_doorbell_int_cntl,
6069af357bcSHawking Zhang 						BIF_DOORBELL_INT_CNTL,
6079af357bcSHawking Zhang 						RAS_ATHUB_ERR_EVENT_INTERRUPT_CLEAR, 1);
6089af357bcSHawking Zhang 		WREG32_SOC15(NBIO, 0, regBIF_BX0_BIF_DOORBELL_INT_CNTL, bif_doorbell_int_cntl);
6099af357bcSHawking Zhang 		amdgpu_ras_global_ras_isr(adev);
6109af357bcSHawking Zhang 	}
6119af357bcSHawking Zhang }
6129af357bcSHawking Zhang 
nbio_v4_3_init_ras_err_event_athub_interrupt(struct amdgpu_device * adev)6139af357bcSHawking Zhang static int nbio_v4_3_init_ras_err_event_athub_interrupt(struct amdgpu_device *adev)
6149af357bcSHawking Zhang {
6159af357bcSHawking Zhang 
6169af357bcSHawking Zhang 	int r;
6179af357bcSHawking Zhang 
6189af357bcSHawking Zhang 	/* init the irq funcs */
6199af357bcSHawking Zhang 	adev->nbio.ras_err_event_athub_irq.funcs =
6209af357bcSHawking Zhang 		&nbio_v4_3_ras_err_event_athub_irq_funcs;
6219af357bcSHawking Zhang 	adev->nbio.ras_err_event_athub_irq.num_types = 1;
6229af357bcSHawking Zhang 
6239af357bcSHawking Zhang 	/* register ras err event athub interrupt
6249af357bcSHawking Zhang 	 * nbio v4_3 uses the same irq source as nbio v7_4 */
6259af357bcSHawking Zhang 	r = amdgpu_irq_add_id(adev, SOC21_IH_CLIENTID_BIF,
6269af357bcSHawking Zhang 			      NBIF_7_4__SRCID__ERREVENT_ATHUB_INTERRUPT,
6279af357bcSHawking Zhang 			      &adev->nbio.ras_err_event_athub_irq);
6289af357bcSHawking Zhang 
6299af357bcSHawking Zhang 	return r;
6309af357bcSHawking Zhang }
6319af357bcSHawking Zhang 
6329af357bcSHawking Zhang struct amdgpu_nbio_ras nbio_v4_3_ras = {
6339af357bcSHawking Zhang 	.handle_ras_err_event_athub_intr_no_bifring = nbio_v4_3_handle_ras_err_event_athub_intr_no_bifring,
6349af357bcSHawking Zhang 	.init_ras_err_event_athub_interrupt = nbio_v4_3_init_ras_err_event_athub_interrupt,
6359af357bcSHawking Zhang };
636