2 * Copyright 2019 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "amdgpu_atombios.h"
25 #include "nbio_v2_3.h"
27 #include "nbio/nbio_2_3_default.h"
28 #include "nbio/nbio_2_3_offset.h"
29 #include "nbio/nbio_2_3_sh_mask.h"
30 #include <uapi/linux/kfd_ioctl.h>
32 #define smnPCIE_CONFIG_CNTL 0x11180044
33 #define smnCPM_CONTROL 0x11180460
34 #define smnPCIE_CNTL2 0x11180070
37 static void nbio_v2_3_remap_hdp_registers(struct amdgpu_device
*adev
)
39 WREG32_SOC15(NBIO
, 0, mmREMAP_HDP_MEM_FLUSH_CNTL
,
40 adev
->rmmio_remap
.reg_offset
+ KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL
);
41 WREG32_SOC15(NBIO
, 0, mmREMAP_HDP_REG_FLUSH_CNTL
,
42 adev
->rmmio_remap
.reg_offset
+ KFD_MMIO_REMAP_HDP_REG_FLUSH_CNTL
);
45 static u32
nbio_v2_3_get_rev_id(struct amdgpu_device
*adev
)
47 u32 tmp
= RREG32_SOC15(NBIO
, 0, mmRCC_DEV0_EPF0_STRAP0
);
49 tmp
&= RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0_MASK
;
50 tmp
>>= RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0__SHIFT
;
55 static void nbio_v2_3_mc_access_enable(struct amdgpu_device
*adev
, bool enable
)
58 WREG32_SOC15(NBIO
, 0, mmBIF_FB_EN
,
59 BIF_FB_EN__FB_READ_EN_MASK
|
60 BIF_FB_EN__FB_WRITE_EN_MASK
);
62 WREG32_SOC15(NBIO
, 0, mmBIF_FB_EN
, 0);
65 static void nbio_v2_3_hdp_flush(struct amdgpu_device
*adev
,
66 struct amdgpu_ring
*ring
)
68 if (!ring
|| !ring
->funcs
->emit_wreg
)
69 WREG32_NO_KIQ((adev
->rmmio_remap
.reg_offset
+ KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL
) >> 2, 0);
71 amdgpu_ring_emit_wreg(ring
, (adev
->rmmio_remap
.reg_offset
+ KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL
) >> 2, 0);
74 static u32
nbio_v2_3_get_memsize(struct amdgpu_device
*adev
)
76 return RREG32_SOC15(NBIO
, 0, mmRCC_DEV0_EPF0_RCC_CONFIG_MEMSIZE
);
79 static void nbio_v2_3_sdma_doorbell_range(struct amdgpu_device
*adev
, int instance
,
80 bool use_doorbell
, int doorbell_index
,
83 u32 reg
= instance
== 0 ? SOC15_REG_OFFSET(NBIO
, 0, mmBIF_SDMA0_DOORBELL_RANGE
) :
84 SOC15_REG_OFFSET(NBIO
, 0, mmBIF_SDMA1_DOORBELL_RANGE
);
86 u32 doorbell_range
= RREG32(reg
);
89 doorbell_range
= REG_SET_FIELD(doorbell_range
,
90 BIF_SDMA0_DOORBELL_RANGE
, OFFSET
,
92 doorbell_range
= REG_SET_FIELD(doorbell_range
,
93 BIF_SDMA0_DOORBELL_RANGE
, SIZE
,
96 doorbell_range
= REG_SET_FIELD(doorbell_range
,
97 BIF_SDMA0_DOORBELL_RANGE
, SIZE
,
100 WREG32(reg
, doorbell_range
);
103 static void nbio_v2_3_vcn_doorbell_range(struct amdgpu_device
*adev
, bool use_doorbell
,
104 int doorbell_index
, int instance
)
106 u32 reg
= SOC15_REG_OFFSET(NBIO
, 0, mmBIF_MMSCH0_DOORBELL_RANGE
);
108 u32 doorbell_range
= RREG32(reg
);
111 doorbell_range
= REG_SET_FIELD(doorbell_range
,
112 BIF_MMSCH0_DOORBELL_RANGE
, OFFSET
,
114 doorbell_range
= REG_SET_FIELD(doorbell_range
,
115 BIF_MMSCH0_DOORBELL_RANGE
, SIZE
, 8);
117 doorbell_range
= REG_SET_FIELD(doorbell_range
,
118 BIF_MMSCH0_DOORBELL_RANGE
, SIZE
, 0);
120 WREG32(reg
, doorbell_range
);
123 static void nbio_v2_3_enable_doorbell_aperture(struct amdgpu_device
*adev
,
126 WREG32_FIELD15(NBIO
, 0, RCC_DEV0_EPF0_RCC_DOORBELL_APER_EN
, BIF_DOORBELL_APER_EN
,
130 static void nbio_v2_3_enable_doorbell_selfring_aperture(struct amdgpu_device
*adev
,
136 tmp
= REG_SET_FIELD(tmp
, BIF_BX_PF_DOORBELL_SELFRING_GPA_APER_CNTL
,
137 DOORBELL_SELFRING_GPA_APER_EN
, 1) |
138 REG_SET_FIELD(tmp
, BIF_BX_PF_DOORBELL_SELFRING_GPA_APER_CNTL
,
139 DOORBELL_SELFRING_GPA_APER_MODE
, 1) |
140 REG_SET_FIELD(tmp
, BIF_BX_PF_DOORBELL_SELFRING_GPA_APER_CNTL
,
141 DOORBELL_SELFRING_GPA_APER_SIZE
, 0);
143 WREG32_SOC15(NBIO
, 0, mmBIF_BX_PF_DOORBELL_SELFRING_GPA_APER_BASE_LOW
,
144 lower_32_bits(adev
->doorbell
.base
));
145 WREG32_SOC15(NBIO
, 0, mmBIF_BX_PF_DOORBELL_SELFRING_GPA_APER_BASE_HIGH
,
146 upper_32_bits(adev
->doorbell
.base
));
149 WREG32_SOC15(NBIO
, 0, mmBIF_BX_PF_DOORBELL_SELFRING_GPA_APER_CNTL
,
154 static void nbio_v2_3_ih_doorbell_range(struct amdgpu_device
*adev
,
155 bool use_doorbell
, int doorbell_index
)
157 u32 ih_doorbell_range
= RREG32_SOC15(NBIO
, 0, mmBIF_IH_DOORBELL_RANGE
);
160 ih_doorbell_range
= REG_SET_FIELD(ih_doorbell_range
,
161 BIF_IH_DOORBELL_RANGE
, OFFSET
,
163 ih_doorbell_range
= REG_SET_FIELD(ih_doorbell_range
,
164 BIF_IH_DOORBELL_RANGE
, SIZE
,
167 ih_doorbell_range
= REG_SET_FIELD(ih_doorbell_range
,
168 BIF_IH_DOORBELL_RANGE
, SIZE
,
171 WREG32_SOC15(NBIO
, 0, mmBIF_IH_DOORBELL_RANGE
, ih_doorbell_range
);
174 static void nbio_v2_3_ih_control(struct amdgpu_device
*adev
)
178 /* setup interrupt control */
179 WREG32_SOC15(NBIO
, 0, mmINTERRUPT_CNTL2
, adev
->dummy_page_addr
>> 8);
181 interrupt_cntl
= RREG32_SOC15(NBIO
, 0, mmINTERRUPT_CNTL
);
183 * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=0 - dummy read disabled with msi, enabled without msi
184 * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=1 - dummy read controlled by IH_DUMMY_RD_EN
186 interrupt_cntl
= REG_SET_FIELD(interrupt_cntl
, INTERRUPT_CNTL
,
187 IH_DUMMY_RD_OVERRIDE
, 0);
189 /* INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */
190 interrupt_cntl
= REG_SET_FIELD(interrupt_cntl
, INTERRUPT_CNTL
,
191 IH_REQ_NONSNOOP_EN
, 0);
193 WREG32_SOC15(NBIO
, 0, mmINTERRUPT_CNTL
, interrupt_cntl
);
196 static void nbio_v2_3_update_medium_grain_clock_gating(struct amdgpu_device
*adev
,
201 def
= data
= RREG32_PCIE(smnCPM_CONTROL
);
202 if (enable
&& (adev
->cg_flags
& AMD_CG_SUPPORT_BIF_MGCG
)) {
203 data
|= (CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK
|
204 CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK
|
205 CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK
|
206 CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK
|
207 CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK
|
208 CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK
);
210 data
&= ~(CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK
|
211 CPM_CONTROL__TXCLK_DYN_GATE_ENABLE_MASK
|
212 CPM_CONTROL__TXCLK_LCNT_GATE_ENABLE_MASK
|
213 CPM_CONTROL__TXCLK_REGS_GATE_ENABLE_MASK
|
214 CPM_CONTROL__TXCLK_PRBS_GATE_ENABLE_MASK
|
215 CPM_CONTROL__REFCLK_REGS_GATE_ENABLE_MASK
);
219 WREG32_PCIE(smnCPM_CONTROL
, data
);
222 static void nbio_v2_3_update_medium_grain_light_sleep(struct amdgpu_device
*adev
,
227 def
= data
= RREG32_PCIE(smnPCIE_CNTL2
);
228 if (enable
&& (adev
->cg_flags
& AMD_CG_SUPPORT_BIF_LS
)) {
229 data
|= (PCIE_CNTL2__SLV_MEM_LS_EN_MASK
|
230 PCIE_CNTL2__MST_MEM_LS_EN_MASK
|
231 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK
);
233 data
&= ~(PCIE_CNTL2__SLV_MEM_LS_EN_MASK
|
234 PCIE_CNTL2__MST_MEM_LS_EN_MASK
|
235 PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK
);
239 WREG32_PCIE(smnPCIE_CNTL2
, data
);
242 static void nbio_v2_3_get_clockgating_state(struct amdgpu_device
*adev
,
247 /* AMD_CG_SUPPORT_BIF_MGCG */
248 data
= RREG32_PCIE(smnCPM_CONTROL
);
249 if (data
& CPM_CONTROL__LCLK_DYN_GATE_ENABLE_MASK
)
250 *flags
|= AMD_CG_SUPPORT_BIF_MGCG
;
252 /* AMD_CG_SUPPORT_BIF_LS */
253 data
= RREG32_PCIE(smnPCIE_CNTL2
);
254 if (data
& PCIE_CNTL2__SLV_MEM_LS_EN_MASK
)
255 *flags
|= AMD_CG_SUPPORT_BIF_LS
;
258 static u32
nbio_v2_3_get_hdp_flush_req_offset(struct amdgpu_device
*adev
)
260 return SOC15_REG_OFFSET(NBIO
, 0, mmBIF_BX_PF_GPU_HDP_FLUSH_REQ
);
263 static u32
nbio_v2_3_get_hdp_flush_done_offset(struct amdgpu_device
*adev
)
265 return SOC15_REG_OFFSET(NBIO
, 0, mmBIF_BX_PF_GPU_HDP_FLUSH_DONE
);
268 static u32
nbio_v2_3_get_pcie_index_offset(struct amdgpu_device
*adev
)
270 return SOC15_REG_OFFSET(NBIO
, 0, mmPCIE_INDEX2
);
273 static u32
nbio_v2_3_get_pcie_data_offset(struct amdgpu_device
*adev
)
275 return SOC15_REG_OFFSET(NBIO
, 0, mmPCIE_DATA2
);
278 const struct nbio_hdp_flush_reg nbio_v2_3_hdp_flush_reg
= {
279 .ref_and_mask_cp0
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP0_MASK
,
280 .ref_and_mask_cp1
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP1_MASK
,
281 .ref_and_mask_cp2
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP2_MASK
,
282 .ref_and_mask_cp3
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP3_MASK
,
283 .ref_and_mask_cp4
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP4_MASK
,
284 .ref_and_mask_cp5
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP5_MASK
,
285 .ref_and_mask_cp6
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP6_MASK
,
286 .ref_and_mask_cp7
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP7_MASK
,
287 .ref_and_mask_cp8
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP8_MASK
,
288 .ref_and_mask_cp9
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__CP9_MASK
,
289 .ref_and_mask_sdma0
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__SDMA0_MASK
,
290 .ref_and_mask_sdma1
= BIF_BX_PF_GPU_HDP_FLUSH_DONE__SDMA1_MASK
,
293 static void nbio_v2_3_detect_hw_virt(struct amdgpu_device
*adev
)
297 reg
= RREG32_SOC15(NBIO
, 0, mmRCC_DEV0_EPF0_RCC_IOV_FUNC_IDENTIFIER
);
299 adev
->virt
.caps
|= AMDGPU_SRIOV_CAPS_IS_VF
;
301 if (reg
& 0x80000000)
302 adev
->virt
.caps
|= AMDGPU_SRIOV_CAPS_ENABLE_IOV
;
305 if (is_virtual_machine()) /* passthrough mode exclus sriov mod */
306 adev
->virt
.caps
|= AMDGPU_PASSTHROUGH_MODE
;
310 static void nbio_v2_3_init_registers(struct amdgpu_device
*adev
)
314 def
= data
= RREG32_PCIE(smnPCIE_CONFIG_CNTL
);
315 data
= REG_SET_FIELD(data
, PCIE_CONFIG_CNTL
, CI_SWUS_MAX_READ_REQUEST_SIZE_MODE
, 1);
316 data
= REG_SET_FIELD(data
, PCIE_CONFIG_CNTL
, CI_SWUS_MAX_READ_REQUEST_SIZE_PRIV
, 1);
319 WREG32_PCIE(smnPCIE_CONFIG_CNTL
, data
);
322 const struct amdgpu_nbio_funcs nbio_v2_3_funcs
= {
323 .get_hdp_flush_req_offset
= nbio_v2_3_get_hdp_flush_req_offset
,
324 .get_hdp_flush_done_offset
= nbio_v2_3_get_hdp_flush_done_offset
,
325 .get_pcie_index_offset
= nbio_v2_3_get_pcie_index_offset
,
326 .get_pcie_data_offset
= nbio_v2_3_get_pcie_data_offset
,
327 .get_rev_id
= nbio_v2_3_get_rev_id
,
328 .mc_access_enable
= nbio_v2_3_mc_access_enable
,
329 .hdp_flush
= nbio_v2_3_hdp_flush
,
330 .get_memsize
= nbio_v2_3_get_memsize
,
331 .sdma_doorbell_range
= nbio_v2_3_sdma_doorbell_range
,
332 .vcn_doorbell_range
= nbio_v2_3_vcn_doorbell_range
,
333 .enable_doorbell_aperture
= nbio_v2_3_enable_doorbell_aperture
,
334 .enable_doorbell_selfring_aperture
= nbio_v2_3_enable_doorbell_selfring_aperture
,
335 .ih_doorbell_range
= nbio_v2_3_ih_doorbell_range
,
336 .update_medium_grain_clock_gating
= nbio_v2_3_update_medium_grain_clock_gating
,
337 .update_medium_grain_light_sleep
= nbio_v2_3_update_medium_grain_light_sleep
,
338 .get_clockgating_state
= nbio_v2_3_get_clockgating_state
,
339 .ih_control
= nbio_v2_3_ih_control
,
340 .init_registers
= nbio_v2_3_init_registers
,
341 .detect_hw_virt
= nbio_v2_3_detect_hw_virt
,
342 .remap_hdp_registers
= nbio_v2_3_remap_hdp_registers
,