1e44d856eSbenl /*
2e44d856eSbenl * Copyright 2021 Advanced Micro Devices, Inc.
3e44d856eSbenl *
4e44d856eSbenl * Permission is hereby granted, free of charge, to any person obtaining a
5e44d856eSbenl * copy of this software and associated documentation files (the "Software"),
6e44d856eSbenl * to deal in the Software without restriction, including without limitation
7e44d856eSbenl * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e44d856eSbenl * and/or sell copies of the Software, and to permit persons to whom the
9e44d856eSbenl * Software is furnished to do so, subject to the following conditions:
10e44d856eSbenl *
11e44d856eSbenl * The above copyright notice and this permission notice shall be included in
12e44d856eSbenl * all copies or substantial portions of the Software.
13e44d856eSbenl *
14e44d856eSbenl * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15e44d856eSbenl * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16e44d856eSbenl * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17e44d856eSbenl * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18e44d856eSbenl * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19e44d856eSbenl * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20e44d856eSbenl * OTHER DEALINGS IN THE SOFTWARE.
21e44d856eSbenl *
22e44d856eSbenl */
23e44d856eSbenl #include "amdgpu.h"
24e44d856eSbenl #include "amdgpu_atombios.h"
25e44d856eSbenl #include "nbio_v7_11.h"
26e44d856eSbenl
27e44d856eSbenl #include "nbio/nbio_7_11_0_offset.h"
28e44d856eSbenl #include "nbio/nbio_7_11_0_sh_mask.h"
29e44d856eSbenl #include <uapi/linux/kfd_ioctl.h>
30e44d856eSbenl
nbio_v7_11_remap_hdp_registers(struct amdgpu_device * adev)31addd7aefSAlex Deucher static void nbio_v7_11_remap_hdp_registers(struct amdgpu_device *adev)
32addd7aefSAlex Deucher {
33addd7aefSAlex Deucher WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_MEM_FLUSH_CNTL,
34addd7aefSAlex Deucher adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL);
35addd7aefSAlex Deucher WREG32_SOC15(NBIO, 0, regBIF_BX0_REMAP_HDP_REG_FLUSH_CNTL,
36addd7aefSAlex Deucher adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_REG_FLUSH_CNTL);
37addd7aefSAlex Deucher }
38addd7aefSAlex Deucher
nbio_v7_11_get_rev_id(struct amdgpu_device * adev)39e44d856eSbenl static u32 nbio_v7_11_get_rev_id(struct amdgpu_device *adev)
40e44d856eSbenl {
41e44d856eSbenl u32 tmp;
42e44d856eSbenl
43e44d856eSbenl tmp = RREG32_SOC15(NBIO, 0, regRCC_STRAP1_RCC_DEV0_EPF0_STRAP0);
44e44d856eSbenl tmp &= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0_MASK;
45e44d856eSbenl tmp >>= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0__SHIFT;
46e44d856eSbenl
47e44d856eSbenl return tmp;
48e44d856eSbenl }
49e44d856eSbenl
nbio_v7_11_mc_access_enable(struct amdgpu_device * adev,bool enable)50e44d856eSbenl static void nbio_v7_11_mc_access_enable(struct amdgpu_device *adev, bool enable)
51e44d856eSbenl {
52e44d856eSbenl if (enable)
53e44d856eSbenl WREG32_SOC15(NBIO, 0, regBIF_BX1_BIF_FB_EN,
54e44d856eSbenl BIF_BX1_BIF_FB_EN__FB_READ_EN_MASK |
55e44d856eSbenl BIF_BX1_BIF_FB_EN__FB_WRITE_EN_MASK);
56e44d856eSbenl else
57e44d856eSbenl WREG32_SOC15(NBIO, 0, regBIF_BX1_BIF_FB_EN, 0);
58e44d856eSbenl }
59e44d856eSbenl
nbio_v7_11_get_memsize(struct amdgpu_device * adev)60e44d856eSbenl static u32 nbio_v7_11_get_memsize(struct amdgpu_device *adev)
61e44d856eSbenl {
62e44d856eSbenl return RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_CONFIG_MEMSIZE);
63e44d856eSbenl }
64e44d856eSbenl
nbio_v7_11_sdma_doorbell_range(struct amdgpu_device * adev,int instance,bool use_doorbell,int doorbell_index,int doorbell_size)65e44d856eSbenl static void nbio_v7_11_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
66e44d856eSbenl bool use_doorbell, int doorbell_index,
67e44d856eSbenl int doorbell_size)
68e44d856eSbenl {
694661482bSLang Yu u32 reg = SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_CSDMA_DOORBELL_RANGE);
70e44d856eSbenl u32 doorbell_range = RREG32_PCIE_PORT(reg);
71e44d856eSbenl
72e44d856eSbenl if (use_doorbell) {
73e44d856eSbenl doorbell_range = REG_SET_FIELD(doorbell_range,
744661482bSLang Yu GDC0_BIF_CSDMA_DOORBELL_RANGE,
75e44d856eSbenl OFFSET, doorbell_index);
76e44d856eSbenl doorbell_range = REG_SET_FIELD(doorbell_range,
774661482bSLang Yu GDC0_BIF_CSDMA_DOORBELL_RANGE,
78e44d856eSbenl SIZE, doorbell_size);
79e44d856eSbenl } else {
80e44d856eSbenl doorbell_range = REG_SET_FIELD(doorbell_range,
814661482bSLang Yu GDC0_BIF_CSDMA_DOORBELL_RANGE,
82e44d856eSbenl SIZE, 0);
83e44d856eSbenl }
84e44d856eSbenl
85e44d856eSbenl WREG32_PCIE_PORT(reg, doorbell_range);
86e44d856eSbenl }
87e44d856eSbenl
nbio_v7_11_vpe_doorbell_range(struct amdgpu_device * adev,int instance,bool use_doorbell,int doorbell_index,int doorbell_size)885861e477SLang Yu static void nbio_v7_11_vpe_doorbell_range(struct amdgpu_device *adev, int instance,
895861e477SLang Yu bool use_doorbell, int doorbell_index,
905861e477SLang Yu int doorbell_size)
915861e477SLang Yu {
92dc84f52eSYifan Zhang u32 reg = instance == 0 ?
93dc84f52eSYifan Zhang SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_VPE_DOORBELL_RANGE) :
94dc84f52eSYifan Zhang SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_VPE1_DOORBELL_RANGE);
955861e477SLang Yu u32 doorbell_range = RREG32_PCIE_PORT(reg);
965861e477SLang Yu
975861e477SLang Yu if (use_doorbell) {
985861e477SLang Yu doorbell_range = REG_SET_FIELD(doorbell_range,
995861e477SLang Yu GDC0_BIF_VPE_DOORBELL_RANGE,
1005861e477SLang Yu OFFSET, doorbell_index);
1015861e477SLang Yu doorbell_range = REG_SET_FIELD(doorbell_range,
1025861e477SLang Yu GDC0_BIF_VPE_DOORBELL_RANGE,
1035861e477SLang Yu SIZE, doorbell_size);
1045861e477SLang Yu } else {
1055861e477SLang Yu doorbell_range = REG_SET_FIELD(doorbell_range,
1065861e477SLang Yu GDC0_BIF_VPE_DOORBELL_RANGE,
1075861e477SLang Yu SIZE, 0);
1085861e477SLang Yu }
1095861e477SLang Yu
1105861e477SLang Yu WREG32_PCIE_PORT(reg, doorbell_range);
1115861e477SLang Yu }
1125861e477SLang Yu
nbio_v7_11_vcn_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index,int instance)113b85a17d3SAlex Deucher static void nbio_v7_11_vcn_doorbell_range(struct amdgpu_device *adev,
114b85a17d3SAlex Deucher bool use_doorbell,
115b85a17d3SAlex Deucher int doorbell_index, int instance)
116b85a17d3SAlex Deucher {
117dc84f52eSYifan Zhang u32 reg = instance == 0 ?
118dc84f52eSYifan Zhang SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_VCN0_DOORBELL_RANGE):
119dc84f52eSYifan Zhang SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_VCN1_DOORBELL_RANGE);
120dc84f52eSYifan Zhang
121b85a17d3SAlex Deucher u32 doorbell_range = RREG32_PCIE_PORT(reg);
122b85a17d3SAlex Deucher
123b85a17d3SAlex Deucher if (use_doorbell) {
124b85a17d3SAlex Deucher doorbell_range = REG_SET_FIELD(doorbell_range,
125b85a17d3SAlex Deucher GDC0_BIF_VCN0_DOORBELL_RANGE, OFFSET,
126b85a17d3SAlex Deucher doorbell_index);
127b85a17d3SAlex Deucher doorbell_range = REG_SET_FIELD(doorbell_range,
128b85a17d3SAlex Deucher GDC0_BIF_VCN0_DOORBELL_RANGE, SIZE, 8);
129b85a17d3SAlex Deucher } else {
130b85a17d3SAlex Deucher doorbell_range = REG_SET_FIELD(doorbell_range,
131b85a17d3SAlex Deucher GDC0_BIF_VCN0_DOORBELL_RANGE, SIZE, 0);
132b85a17d3SAlex Deucher }
133b85a17d3SAlex Deucher
134b85a17d3SAlex Deucher WREG32_PCIE_PORT(reg, doorbell_range);
135b85a17d3SAlex Deucher }
136b85a17d3SAlex Deucher
nbio_v7_11_enable_doorbell_aperture(struct amdgpu_device * adev,bool enable)137e44d856eSbenl static void nbio_v7_11_enable_doorbell_aperture(struct amdgpu_device *adev,
138e44d856eSbenl bool enable)
139e44d856eSbenl {
140e44d856eSbenl u32 reg;
141e44d856eSbenl
142e44d856eSbenl
143e44d856eSbenl reg = RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN);
144e44d856eSbenl reg = REG_SET_FIELD(reg, RCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN,
145e44d856eSbenl BIF_DOORBELL_APER_EN, enable ? 1 : 0);
146e44d856eSbenl
147e44d856eSbenl WREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN, reg);
148e44d856eSbenl }
149e44d856eSbenl
nbio_v7_11_enable_doorbell_selfring_aperture(struct amdgpu_device * adev,bool enable)150e44d856eSbenl static void nbio_v7_11_enable_doorbell_selfring_aperture(struct amdgpu_device *adev,
151e44d856eSbenl bool enable)
152e44d856eSbenl {
1534661482bSLang Yu u32 tmp = 0;
154e44d856eSbenl
155e44d856eSbenl if (enable) {
1564661482bSLang Yu tmp = REG_SET_FIELD(tmp, BIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_CNTL,
157e44d856eSbenl DOORBELL_SELFRING_GPA_APER_EN, 1) |
1584661482bSLang Yu REG_SET_FIELD(tmp, BIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_CNTL,
159e44d856eSbenl DOORBELL_SELFRING_GPA_APER_MODE, 1) |
1604661482bSLang Yu REG_SET_FIELD(tmp, BIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_CNTL,
161e44d856eSbenl DOORBELL_SELFRING_GPA_APER_SIZE, 0);
162e44d856eSbenl
163e44d856eSbenl WREG32_SOC15(NBIO, 0,
1644661482bSLang Yu regBIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_BASE_LOW,
165e44d856eSbenl lower_32_bits(adev->doorbell.base));
166e44d856eSbenl WREG32_SOC15(NBIO, 0,
1674661482bSLang Yu regBIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_BASE_HIGH,
168e44d856eSbenl upper_32_bits(adev->doorbell.base));
169e44d856eSbenl }
170e44d856eSbenl
1714661482bSLang Yu WREG32_SOC15(NBIO, 0, regBIF_BX_PF1_DOORBELL_SELFRING_GPA_APER_CNTL, tmp);
172e44d856eSbenl }
173e44d856eSbenl
174e44d856eSbenl
nbio_v7_11_ih_doorbell_range(struct amdgpu_device * adev,bool use_doorbell,int doorbell_index)175e44d856eSbenl static void nbio_v7_11_ih_doorbell_range(struct amdgpu_device *adev,
176e44d856eSbenl bool use_doorbell, int doorbell_index)
177e44d856eSbenl {
178e44d856eSbenl u32 ih_doorbell_range = RREG32_SOC15(NBIO, 0,regGDC0_BIF_IH_DOORBELL_RANGE);
179e44d856eSbenl
180e44d856eSbenl if (use_doorbell) {
181e44d856eSbenl ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
182e44d856eSbenl GDC0_BIF_IH_DOORBELL_RANGE, OFFSET,
183e44d856eSbenl doorbell_index);
184e44d856eSbenl ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
185e44d856eSbenl GDC0_BIF_IH_DOORBELL_RANGE, SIZE,
186e44d856eSbenl 2);
187e44d856eSbenl } else {
188e44d856eSbenl ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,
189e44d856eSbenl GDC0_BIF_IH_DOORBELL_RANGE, SIZE,
190e44d856eSbenl 0);
191e44d856eSbenl }
192e44d856eSbenl
193e44d856eSbenl WREG32_SOC15(NBIO, 0, regGDC0_BIF_IH_DOORBELL_RANGE,
194e44d856eSbenl ih_doorbell_range);
195e44d856eSbenl }
196e44d856eSbenl
nbio_v7_11_ih_control(struct amdgpu_device * adev)197e44d856eSbenl static void nbio_v7_11_ih_control(struct amdgpu_device *adev)
198e44d856eSbenl {
199e44d856eSbenl u32 interrupt_cntl;
200e44d856eSbenl
201e44d856eSbenl /* setup interrupt control */
202e44d856eSbenl WREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL2,
203e44d856eSbenl adev->dummy_page_addr >> 8);
204e44d856eSbenl
205e44d856eSbenl interrupt_cntl = RREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL);
206e44d856eSbenl /*
207e44d856eSbenl * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=0 - dummy read disabled with msi, enabled without msi
208e44d856eSbenl * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=1 - dummy read controlled by IH_DUMMY_RD_EN
209e44d856eSbenl */
210e44d856eSbenl interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX1_INTERRUPT_CNTL,
211e44d856eSbenl IH_DUMMY_RD_OVERRIDE, 0);
212e44d856eSbenl
213e44d856eSbenl /* INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */
214e44d856eSbenl interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX1_INTERRUPT_CNTL,
215e44d856eSbenl IH_REQ_NONSNOOP_EN, 0);
216e44d856eSbenl
217e44d856eSbenl WREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL, interrupt_cntl);
218e44d856eSbenl }
219e44d856eSbenl
nbio_v7_11_get_hdp_flush_req_offset(struct amdgpu_device * adev)220e44d856eSbenl static u32 nbio_v7_11_get_hdp_flush_req_offset(struct amdgpu_device *adev)
221e44d856eSbenl {
2224661482bSLang Yu return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF1_GPU_HDP_FLUSH_REQ);
223e44d856eSbenl }
224e44d856eSbenl
nbio_v7_11_get_hdp_flush_done_offset(struct amdgpu_device * adev)225e44d856eSbenl static u32 nbio_v7_11_get_hdp_flush_done_offset(struct amdgpu_device *adev)
226e44d856eSbenl {
2274661482bSLang Yu return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF1_GPU_HDP_FLUSH_DONE);
228e44d856eSbenl }
229e44d856eSbenl
nbio_v7_11_get_pcie_index_offset(struct amdgpu_device * adev)230e44d856eSbenl static u32 nbio_v7_11_get_pcie_index_offset(struct amdgpu_device *adev)
231e44d856eSbenl {
232e44d856eSbenl return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX1_PCIE_INDEX2);
233e44d856eSbenl }
234e44d856eSbenl
nbio_v7_11_get_pcie_data_offset(struct amdgpu_device * adev)235e44d856eSbenl static u32 nbio_v7_11_get_pcie_data_offset(struct amdgpu_device *adev)
236e44d856eSbenl {
237e44d856eSbenl return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX1_PCIE_DATA2);
238e44d856eSbenl }
239e44d856eSbenl
nbio_v7_11_get_pcie_port_index_offset(struct amdgpu_device * adev)240e44d856eSbenl static u32 nbio_v7_11_get_pcie_port_index_offset(struct amdgpu_device *adev)
241e44d856eSbenl {
2424661482bSLang Yu return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF1_RSMU_INDEX);
243e44d856eSbenl }
244e44d856eSbenl
nbio_v7_11_get_pcie_port_data_offset(struct amdgpu_device * adev)245e44d856eSbenl static u32 nbio_v7_11_get_pcie_port_data_offset(struct amdgpu_device *adev)
246e44d856eSbenl {
2474661482bSLang Yu return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF1_RSMU_DATA);
248e44d856eSbenl }
249e44d856eSbenl
250e44d856eSbenl const struct nbio_hdp_flush_reg nbio_v7_11_hdp_flush_reg = {
2514661482bSLang Yu .ref_and_mask_cp0 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP0_MASK,
2524661482bSLang Yu .ref_and_mask_cp1 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP1_MASK,
2534661482bSLang Yu .ref_and_mask_cp2 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP2_MASK,
2544661482bSLang Yu .ref_and_mask_cp3 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP3_MASK,
2554661482bSLang Yu .ref_and_mask_cp4 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP4_MASK,
2564661482bSLang Yu .ref_and_mask_cp5 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP5_MASK,
2574661482bSLang Yu .ref_and_mask_cp6 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP6_MASK,
2584661482bSLang Yu .ref_and_mask_cp7 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP7_MASK,
2594661482bSLang Yu .ref_and_mask_cp8 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP8_MASK,
2604661482bSLang Yu .ref_and_mask_cp9 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__CP9_MASK,
2614661482bSLang Yu .ref_and_mask_sdma0 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__SDMA0_MASK,
2624661482bSLang Yu .ref_and_mask_sdma1 = BIF_BX_PF1_GPU_HDP_FLUSH_DONE__SDMA1_MASK,
263e44d856eSbenl };
264e44d856eSbenl
nbio_v7_11_init_registers(struct amdgpu_device * adev)265e44d856eSbenl static void nbio_v7_11_init_registers(struct amdgpu_device *adev)
266e44d856eSbenl {
267ee95135bSLi Ma uint32_t def, data;
268e44d856eSbenl
269e44d856eSbenl def = data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3);
270e44d856eSbenl data = REG_SET_FIELD(data, BIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3,
271e44d856eSbenl CI_SWUS_MAX_READ_REQUEST_SIZE_MODE, 1);
272e44d856eSbenl data = REG_SET_FIELD(data, BIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3,
273e44d856eSbenl CI_SWUS_MAX_READ_REQUEST_SIZE_PRIV, 1);
274e44d856eSbenl
275e44d856eSbenl if (def != data)
276e44d856eSbenl WREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3, data);
277ee95135bSLi Ma
278e44d856eSbenl }
279e44d856eSbenl
nbio_v7_11_update_medium_grain_clock_gating(struct amdgpu_device * adev,bool enable)280fa9dd7a2SLi Ma static void nbio_v7_11_update_medium_grain_clock_gating(struct amdgpu_device *adev,
281fa9dd7a2SLi Ma bool enable)
282fa9dd7a2SLi Ma {
283fa9dd7a2SLi Ma uint32_t def, data;
284fa9dd7a2SLi Ma
285fa9dd7a2SLi Ma if (!(adev->cg_flags & AMD_CG_SUPPORT_BIF_MGCG))
286fa9dd7a2SLi Ma return;
287fa9dd7a2SLi Ma
288fa9dd7a2SLi Ma def = data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL);
289fa9dd7a2SLi Ma if (enable) {
290fa9dd7a2SLi Ma data |= (BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
291fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
292fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
293fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
294fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
295fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
296fa9dd7a2SLi Ma } else {
297fa9dd7a2SLi Ma data &= ~(BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK |
298fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK |
299fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK |
300fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK |
301fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK |
302fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK);
303fa9dd7a2SLi Ma }
304fa9dd7a2SLi Ma
305fa9dd7a2SLi Ma if (def != data)
306fa9dd7a2SLi Ma WREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL, data);
307fa9dd7a2SLi Ma }
308fa9dd7a2SLi Ma
nbio_v7_11_update_medium_grain_light_sleep(struct amdgpu_device * adev,bool enable)309fa9dd7a2SLi Ma static void nbio_v7_11_update_medium_grain_light_sleep(struct amdgpu_device *adev,
310fa9dd7a2SLi Ma bool enable)
311fa9dd7a2SLi Ma {
312fa9dd7a2SLi Ma uint32_t def, data;
313fa9dd7a2SLi Ma
314fa9dd7a2SLi Ma if (!(adev->cg_flags & AMD_CG_SUPPORT_BIF_LS))
315fa9dd7a2SLi Ma return;
316fa9dd7a2SLi Ma
317fa9dd7a2SLi Ma def = data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2);
318fa9dd7a2SLi Ma if (enable)
319fa9dd7a2SLi Ma data |= BIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
320fa9dd7a2SLi Ma else
321fa9dd7a2SLi Ma data &= ~BIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2__SLV_MEM_LS_EN_MASK;
322fa9dd7a2SLi Ma
323fa9dd7a2SLi Ma if (def != data)
324fa9dd7a2SLi Ma WREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2, data);
325fa9dd7a2SLi Ma
326fa9dd7a2SLi Ma def = data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1);
327fa9dd7a2SLi Ma if (enable) {
328fa9dd7a2SLi Ma data |= (BIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1__MST_MEM_LS_EN_MASK |
329fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1__REPLAY_MEM_LS_EN_MASK);
330fa9dd7a2SLi Ma } else {
331fa9dd7a2SLi Ma data &= ~(BIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1__MST_MEM_LS_EN_MASK |
332fa9dd7a2SLi Ma BIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1__REPLAY_MEM_LS_EN_MASK);
333fa9dd7a2SLi Ma }
334fa9dd7a2SLi Ma
335fa9dd7a2SLi Ma if (def != data)
336fa9dd7a2SLi Ma WREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_TX_POWER_CTRL_1, data);
337fa9dd7a2SLi Ma }
338fa9dd7a2SLi Ma
nbio_v7_11_get_clockgating_state(struct amdgpu_device * adev,u64 * flags)339fa9dd7a2SLi Ma static void nbio_v7_11_get_clockgating_state(struct amdgpu_device *adev,
340fa9dd7a2SLi Ma u64 *flags)
341fa9dd7a2SLi Ma {
342fa9dd7a2SLi Ma uint32_t data;
343fa9dd7a2SLi Ma
344fa9dd7a2SLi Ma /* AMD_CG_SUPPORT_BIF_MGCG */
345fa9dd7a2SLi Ma data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL);
346fa9dd7a2SLi Ma if (data & BIF_BIF256_CI256_RC3X4_USB4_CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK)
347fa9dd7a2SLi Ma *flags |= AMD_CG_SUPPORT_BIF_MGCG;
348fa9dd7a2SLi Ma
349fa9dd7a2SLi Ma /* AMD_CG_SUPPORT_BIF_LS */
350fa9dd7a2SLi Ma data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2);
351fa9dd7a2SLi Ma if (data & BIF_BIF256_CI256_RC3X4_USB4_PCIE_CNTL2__SLV_MEM_LS_EN_MASK)
352fa9dd7a2SLi Ma *flags |= AMD_CG_SUPPORT_BIF_LS;
353fa9dd7a2SLi Ma }
354fa9dd7a2SLi Ma
355*42ad8ac6SAlex Deucher #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
356*42ad8ac6SAlex Deucher
nbio_v7_11_set_reg_remap(struct amdgpu_device * adev)357*42ad8ac6SAlex Deucher static void nbio_v7_11_set_reg_remap(struct amdgpu_device *adev)
358*42ad8ac6SAlex Deucher {
359*42ad8ac6SAlex Deucher if (!amdgpu_sriov_vf(adev) && (PAGE_SIZE <= 4096)) {
360*42ad8ac6SAlex Deucher adev->rmmio_remap.reg_offset = MMIO_REG_HOLE_OFFSET;
361*42ad8ac6SAlex Deucher adev->rmmio_remap.bus_addr = adev->rmmio_base + MMIO_REG_HOLE_OFFSET;
362*42ad8ac6SAlex Deucher } else {
363*42ad8ac6SAlex Deucher adev->rmmio_remap.reg_offset =
364*42ad8ac6SAlex Deucher SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF1_HDP_MEM_COHERENCY_FLUSH_CNTL) << 2;
365*42ad8ac6SAlex Deucher adev->rmmio_remap.bus_addr = 0;
366*42ad8ac6SAlex Deucher }
367*42ad8ac6SAlex Deucher }
368*42ad8ac6SAlex Deucher
369e44d856eSbenl const struct amdgpu_nbio_funcs nbio_v7_11_funcs = {
370e44d856eSbenl .get_hdp_flush_req_offset = nbio_v7_11_get_hdp_flush_req_offset,
371e44d856eSbenl .get_hdp_flush_done_offset = nbio_v7_11_get_hdp_flush_done_offset,
372e44d856eSbenl .get_pcie_index_offset = nbio_v7_11_get_pcie_index_offset,
373e44d856eSbenl .get_pcie_data_offset = nbio_v7_11_get_pcie_data_offset,
374e44d856eSbenl .get_pcie_port_index_offset = nbio_v7_11_get_pcie_port_index_offset,
375e44d856eSbenl .get_pcie_port_data_offset = nbio_v7_11_get_pcie_port_data_offset,
376e44d856eSbenl .get_rev_id = nbio_v7_11_get_rev_id,
377e44d856eSbenl .mc_access_enable = nbio_v7_11_mc_access_enable,
378e44d856eSbenl .get_memsize = nbio_v7_11_get_memsize,
379e44d856eSbenl .sdma_doorbell_range = nbio_v7_11_sdma_doorbell_range,
380b85a17d3SAlex Deucher .vcn_doorbell_range = nbio_v7_11_vcn_doorbell_range,
3815861e477SLang Yu .vpe_doorbell_range = nbio_v7_11_vpe_doorbell_range,
382e44d856eSbenl .enable_doorbell_aperture = nbio_v7_11_enable_doorbell_aperture,
383e44d856eSbenl .enable_doorbell_selfring_aperture = nbio_v7_11_enable_doorbell_selfring_aperture,
384e44d856eSbenl .ih_doorbell_range = nbio_v7_11_ih_doorbell_range,
385fa9dd7a2SLi Ma .update_medium_grain_clock_gating = nbio_v7_11_update_medium_grain_clock_gating,
386fa9dd7a2SLi Ma .update_medium_grain_light_sleep = nbio_v7_11_update_medium_grain_light_sleep,
387fa9dd7a2SLi Ma .get_clockgating_state = nbio_v7_11_get_clockgating_state,
388e44d856eSbenl .ih_control = nbio_v7_11_ih_control,
389e44d856eSbenl .init_registers = nbio_v7_11_init_registers,
390addd7aefSAlex Deucher .remap_hdp_registers = nbio_v7_11_remap_hdp_registers,
391*42ad8ac6SAlex Deucher .set_reg_remap = nbio_v7_11_set_reg_remap,
392e44d856eSbenl };
393