Skip to content

Commit 7c0f7ee

Browse files
Hawking Zhangalexdeucher
authored andcommitted
drm/amdgpu: add gc v9_4_3 rlc_funcs implementation
all the gc v9_4_3 registers fall in gc_rlcpdec address range have different relative offsets and base_idx from the ones defined in gc v9_0 ip headers. gc_v9_0_rlc_funcs can not be reused anymore for gc v9_4_3 v2: drop unused handshake function (Alex) Signed-off-by: Hawking Zhang <Hawking.Zhang@amd.com> Reviewed-by: Le Ma <Le.Ma@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 73c4b0f commit 7c0f7ee

3 files changed

Lines changed: 364 additions & 0 deletions

File tree

drivers/gpu/drm/amd/amdgpu/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ amdgpu-y += \
136136
gfx_v9_0.o \
137137
gfx_v9_4.o \
138138
gfx_v9_4_2.o \
139+
gfx_v9_4_3.o \
139140
gfx_v10_0.o \
140141
imu_v11_0.o \
141142
gfx_v11_0.o \
Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
/*
2+
* Copyright 2022 Advanced Micro Devices, Inc.
3+
*
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:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
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.
21+
*
22+
*/
23+
#include <linux/firmware.h>
24+
25+
#include "amdgpu.h"
26+
#include "amdgpu_gfx.h"
27+
#include "soc15.h"
28+
#include "soc15_common.h"
29+
30+
#include "gc/gc_9_4_3_offset.h"
31+
#include "gc/gc_9_4_3_sh_mask.h"
32+
33+
#include "gfx_v9_4_3.h"
34+
35+
#define RLCG_UCODE_LOADING_START_ADDRESS 0x00002000L
36+
37+
static bool gfx_v9_4_3_is_rlc_enabled(struct amdgpu_device *adev)
38+
{
39+
uint32_t rlc_setting;
40+
41+
/* if RLC is not enabled, do nothing */
42+
rlc_setting = RREG32_SOC15(GC, 0, regRLC_CNTL);
43+
if (!(rlc_setting & RLC_CNTL__RLC_ENABLE_F32_MASK))
44+
return false;
45+
46+
return true;
47+
}
48+
49+
static void gfx_v9_4_3_set_safe_mode(struct amdgpu_device *adev)
50+
{
51+
uint32_t data;
52+
unsigned i;
53+
54+
data = RLC_SAFE_MODE__CMD_MASK;
55+
data |= (1 << RLC_SAFE_MODE__MESSAGE__SHIFT);
56+
WREG32_SOC15(GC, 0, regRLC_SAFE_MODE, data);
57+
58+
/* wait for RLC_SAFE_MODE */
59+
for (i = 0; i < adev->usec_timeout; i++) {
60+
if (!REG_GET_FIELD(RREG32_SOC15(GC, 0, regRLC_SAFE_MODE), RLC_SAFE_MODE, CMD))
61+
break;
62+
udelay(1);
63+
}
64+
}
65+
66+
static void gfx_v9_4_3_unset_safe_mode(struct amdgpu_device *adev)
67+
{
68+
uint32_t data;
69+
70+
data = RLC_SAFE_MODE__CMD_MASK;
71+
WREG32_SOC15(GC, 0, regRLC_SAFE_MODE, data);
72+
}
73+
74+
static int gfx_v9_4_3_rlc_init(struct amdgpu_device *adev)
75+
{
76+
/* init spm vmid with 0xf */
77+
if (adev->gfx.rlc.funcs->update_spm_vmid)
78+
adev->gfx.rlc.funcs->update_spm_vmid(adev, 0xf);
79+
80+
return 0;
81+
}
82+
83+
static void gfx_v9_4_3_select_se_sh(struct amdgpu_device *adev,
84+
u32 se_num,
85+
u32 sh_num,
86+
u32 instance)
87+
{
88+
u32 data;
89+
90+
if (instance == 0xffffffff)
91+
data = REG_SET_FIELD(0, GRBM_GFX_INDEX,
92+
INSTANCE_BROADCAST_WRITES, 1);
93+
else
94+
data = REG_SET_FIELD(0, GRBM_GFX_INDEX, INSTANCE_INDEX,
95+
instance);
96+
97+
if (se_num == 0xffffffff)
98+
data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_BROADCAST_WRITES,
99+
1);
100+
else
101+
data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SE_INDEX, se_num);
102+
103+
if (sh_num == 0xffffffff)
104+
data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_BROADCAST_WRITES,
105+
1);
106+
else
107+
data = REG_SET_FIELD(data, GRBM_GFX_INDEX, SH_INDEX, sh_num);
108+
109+
WREG32_SOC15_RLC_SHADOW_EX(reg, GC, 0, regGRBM_GFX_INDEX, data);
110+
}
111+
112+
static void gfx_v9_4_3_wait_for_rlc_serdes(struct amdgpu_device *adev)
113+
{
114+
u32 i, j, k;
115+
u32 mask;
116+
117+
mutex_lock(&adev->grbm_idx_mutex);
118+
for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
119+
for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
120+
gfx_v9_4_3_select_se_sh(adev, i, j, 0xffffffff);
121+
for (k = 0; k < adev->usec_timeout; k++) {
122+
if (RREG32_SOC15(GC, 0, regRLC_SERDES_CU_MASTER_BUSY) == 0)
123+
break;
124+
udelay(1);
125+
}
126+
if (k == adev->usec_timeout) {
127+
gfx_v9_4_3_select_se_sh(adev, 0xffffffff,
128+
0xffffffff, 0xffffffff);
129+
mutex_unlock(&adev->grbm_idx_mutex);
130+
DRM_INFO("Timeout wait for RLC serdes %u,%u\n",
131+
i, j);
132+
return;
133+
}
134+
}
135+
}
136+
gfx_v9_4_3_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
137+
mutex_unlock(&adev->grbm_idx_mutex);
138+
139+
mask = RLC_SERDES_NONCU_MASTER_BUSY__SE_MASTER_BUSY_MASK |
140+
RLC_SERDES_NONCU_MASTER_BUSY__GC_MASTER_BUSY_MASK |
141+
RLC_SERDES_NONCU_MASTER_BUSY__TC0_MASTER_BUSY_MASK |
142+
RLC_SERDES_NONCU_MASTER_BUSY__TC1_MASTER_BUSY_MASK;
143+
for (k = 0; k < adev->usec_timeout; k++) {
144+
if ((RREG32_SOC15(GC, 0, regRLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
145+
break;
146+
udelay(1);
147+
}
148+
}
149+
150+
static void gfx_v9_4_3_enable_gui_idle_interrupt(struct amdgpu_device *adev,
151+
bool enable)
152+
{
153+
u32 tmp;
154+
155+
/* These interrupts should be enabled to drive DS clock */
156+
157+
tmp = RREG32_SOC15(GC, 0, regCP_INT_CNTL_RING0);
158+
159+
tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_BUSY_INT_ENABLE, enable ? 1 : 0);
160+
tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CNTX_EMPTY_INT_ENABLE, enable ? 1 : 0);
161+
tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, CMP_BUSY_INT_ENABLE, enable ? 1 : 0);
162+
if (adev->gfx.num_gfx_rings)
163+
tmp = REG_SET_FIELD(tmp, CP_INT_CNTL_RING0, GFX_IDLE_INT_ENABLE, enable ? 1 : 0);
164+
165+
WREG32_SOC15(GC, 0, regCP_INT_CNTL_RING0, tmp);
166+
}
167+
168+
static void gfx_v9_4_3_rlc_stop(struct amdgpu_device *adev)
169+
{
170+
WREG32_FIELD15_PREREG(GC, 0, RLC_CNTL, RLC_ENABLE_F32, 0);
171+
gfx_v9_4_3_enable_gui_idle_interrupt(adev, false);
172+
gfx_v9_4_3_wait_for_rlc_serdes(adev);
173+
}
174+
175+
static void gfx_v9_4_3_rlc_reset(struct amdgpu_device *adev)
176+
{
177+
WREG32_FIELD15_PREREG(GC, 0, GRBM_SOFT_RESET, SOFT_RESET_RLC, 1);
178+
udelay(50);
179+
WREG32_FIELD15_PREREG(GC, 0, GRBM_SOFT_RESET, SOFT_RESET_RLC, 0);
180+
udelay(50);
181+
}
182+
183+
static void gfx_v9_4_3_rlc_start(struct amdgpu_device *adev)
184+
{
185+
#ifdef AMDGPU_RLC_DEBUG_RETRY
186+
u32 rlc_ucode_ver;
187+
#endif
188+
189+
WREG32_FIELD15_PREREG(GC, 0, RLC_CNTL, RLC_ENABLE_F32, 1);
190+
udelay(50);
191+
192+
/* carrizo do enable cp interrupt after cp inited */
193+
if (!(adev->flags & AMD_IS_APU)) {
194+
gfx_v9_4_3_enable_gui_idle_interrupt(adev, true);
195+
udelay(50);
196+
}
197+
198+
#ifdef AMDGPU_RLC_DEBUG_RETRY
199+
/* RLC_GPM_GENERAL_6 : RLC Ucode version */
200+
rlc_ucode_ver = RREG32_SOC15(GC, 0, regRLC_GPM_GENERAL_6);
201+
if (rlc_ucode_ver == 0x108) {
202+
dev_info(adev->dev,
203+
"Using rlc debug ucode. regRLC_GPM_GENERAL_6 ==0x08%x / fw_ver == %i \n",
204+
rlc_ucode_ver, adev->gfx.rlc_fw_version);
205+
/* RLC_GPM_TIMER_INT_3 : Timer interval in RefCLK cycles,
206+
* default is 0x9C4 to create a 100us interval */
207+
WREG32_SOC15(GC, 0, regRLC_GPM_TIMER_INT_3, 0x9C4);
208+
/* RLC_GPM_GENERAL_12 : Minimum gap between wptr and rptr
209+
* to disable the page fault retry interrupts, default is
210+
* 0x100 (256) */
211+
WREG32_SOC15(GC, 0, regRLC_GPM_GENERAL_12, 0x100);
212+
}
213+
#endif
214+
}
215+
216+
static int gfx_v9_4_3_rlc_load_microcode(struct amdgpu_device *adev)
217+
{
218+
const struct rlc_firmware_header_v2_0 *hdr;
219+
const __le32 *fw_data;
220+
unsigned i, fw_size;
221+
222+
if (!adev->gfx.rlc_fw)
223+
return -EINVAL;
224+
225+
hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
226+
amdgpu_ucode_print_rlc_hdr(&hdr->header);
227+
228+
fw_data = (const __le32 *)(adev->gfx.rlc_fw->data +
229+
le32_to_cpu(hdr->header.ucode_array_offset_bytes));
230+
fw_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
231+
232+
WREG32_SOC15(GC, 0, regRLC_GPM_UCODE_ADDR,
233+
RLCG_UCODE_LOADING_START_ADDRESS);
234+
for (i = 0; i < fw_size; i++) {
235+
if (amdgpu_emu_mode == 1 && i % 100 == 0) {
236+
dev_info(adev->dev, "Write RLC ucode data %u DWs\n", i);
237+
msleep(1);
238+
}
239+
WREG32_SOC15(GC, 0, regRLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
240+
}
241+
WREG32_SOC15(GC, 0, regRLC_GPM_UCODE_ADDR, adev->gfx.rlc_fw_version);
242+
243+
return 0;
244+
}
245+
246+
static int gfx_v9_4_3_rlc_resume(struct amdgpu_device *adev)
247+
{
248+
int r;
249+
250+
adev->gfx.rlc.funcs->stop(adev);
251+
252+
/* disable CG */
253+
WREG32_SOC15(GC, 0, regRLC_CGCG_CGLS_CTRL, 0);
254+
255+
/* TODO: revisit pg function */
256+
/* gfx_v9_4_3_init_pg(adev);*/
257+
258+
if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
259+
/* legacy rlc firmware loading */
260+
r = gfx_v9_4_3_rlc_load_microcode(adev);
261+
if (r)
262+
return r;
263+
}
264+
265+
adev->gfx.rlc.funcs->start(adev);
266+
267+
return 0;
268+
}
269+
270+
static void gfx_v9_4_3_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)
271+
{
272+
u32 reg, data;
273+
274+
reg = SOC15_REG_OFFSET(GC, 0, regRLC_SPM_MC_CNTL);
275+
if (amdgpu_sriov_is_pp_one_vf(adev))
276+
data = RREG32_NO_KIQ(reg);
277+
else
278+
data = RREG32(reg);
279+
280+
data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;
281+
data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
282+
283+
if (amdgpu_sriov_is_pp_one_vf(adev))
284+
WREG32_SOC15_NO_KIQ(GC, 0, regRLC_SPM_MC_CNTL, data);
285+
else
286+
WREG32_SOC15(GC, 0, regRLC_SPM_MC_CNTL, data);
287+
}
288+
289+
static const struct soc15_reg_rlcg rlcg_access_gc_9_4_3[] = {
290+
{SOC15_REG_ENTRY(GC, 0, regGRBM_GFX_INDEX)},
291+
{SOC15_REG_ENTRY(GC, 0, regSQ_IND_INDEX)},
292+
};
293+
294+
static bool gfx_v9_4_3_check_rlcg_range(struct amdgpu_device *adev,
295+
uint32_t offset,
296+
struct soc15_reg_rlcg *entries, int arr_size)
297+
{
298+
int i;
299+
uint32_t reg;
300+
301+
if (!entries)
302+
return false;
303+
304+
for (i = 0; i < arr_size; i++) {
305+
const struct soc15_reg_rlcg *entry;
306+
307+
entry = &entries[i];
308+
reg = adev->reg_offset[entry->hwip][entry->instance][entry->segment] + entry->reg;
309+
if (offset == reg)
310+
return true;
311+
}
312+
313+
return false;
314+
}
315+
316+
static bool gfx_v9_4_3_is_rlcg_access_range(struct amdgpu_device *adev, u32 offset)
317+
{
318+
return gfx_v9_4_3_check_rlcg_range(adev, offset,
319+
(void *)rlcg_access_gc_9_4_3,
320+
ARRAY_SIZE(rlcg_access_gc_9_4_3));
321+
}
322+
323+
const struct amdgpu_rlc_funcs gfx_v9_4_3_rlc_funcs = {
324+
.is_rlc_enabled = gfx_v9_4_3_is_rlc_enabled,
325+
.set_safe_mode = gfx_v9_4_3_set_safe_mode,
326+
.unset_safe_mode = gfx_v9_4_3_unset_safe_mode,
327+
.init = gfx_v9_4_3_rlc_init,
328+
.resume = gfx_v9_4_3_rlc_resume,
329+
.stop = gfx_v9_4_3_rlc_stop,
330+
.reset = gfx_v9_4_3_rlc_reset,
331+
.start = gfx_v9_4_3_rlc_start,
332+
.update_spm_vmid = gfx_v9_4_3_update_spm_vmid,
333+
.is_rlcg_access_range = gfx_v9_4_3_is_rlcg_access_range,
334+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 Advanced Micro Devices, Inc.
3+
*
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:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
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.
21+
*
22+
*/
23+
24+
#ifndef __GFX_V9_4_3_H__
25+
#define __GFX_V9_4_3_H__
26+
27+
extern const struct amdgpu_rlc_funcs gfx_v9_4_3_rlc_funcs;
28+
29+
#endif /* __GFX_V9_4_3_H__ */

0 commit comments

Comments
 (0)