Skip to content

Commit d02ddef

Browse files
Lijo Lazaralexdeucher
authored andcommitted
drm/amdgpu: Initialize VF partition mode
For SOCs with GFX v9.4.3, a VF may have multiple compute partitions. Fetch the partition information during init and initialize partition nodes. There is no support to switch partition mode in VF mode, hence disable the same. Signed-off-by: Lijo Lazar <[email protected]> Reviewed-by: Hawking Zhang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 5d64af4 commit d02ddef

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ struct amdgpu_gfx_funcs {
297297
int (*switch_partition_mode)(struct amdgpu_device *adev,
298298
int num_xccs_per_xcp);
299299
int (*ih_node_to_logical_xcc)(struct amdgpu_device *adev, int ih_node);
300+
int (*get_xccs_per_xcp)(struct amdgpu_device *adev);
300301
};
301302

302303
struct sq_work {

drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ int amdgpu_xcp_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags)
219219
{
220220
int mode;
221221

222-
if (xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
222+
if (!amdgpu_sriov_vf(xcp_mgr->adev) &&
223+
xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
223224
return xcp_mgr->mode;
224225

225226
if (!xcp_mgr->funcs || !xcp_mgr->funcs->query_partition_mode)
@@ -228,6 +229,12 @@ int amdgpu_xcp_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, u32 flags)
228229
if (!(flags & AMDGPU_XCP_FL_LOCKED))
229230
mutex_lock(&xcp_mgr->xcp_lock);
230231
mode = xcp_mgr->funcs->query_partition_mode(xcp_mgr);
232+
233+
/* First time query for VF, set the mode here */
234+
if (amdgpu_sriov_vf(xcp_mgr->adev) &&
235+
xcp_mgr->mode == AMDGPU_XCP_MODE_NONE)
236+
xcp_mgr->mode = mode;
237+
231238
if (xcp_mgr->mode != AMDGPU_XCP_MODE_TRANS && mode != xcp_mgr->mode)
232239
dev_WARN(
233240
xcp_mgr->adev->dev,
@@ -282,8 +289,7 @@ int amdgpu_xcp_mgr_init(struct amdgpu_device *adev, int init_mode,
282289
{
283290
struct amdgpu_xcp_mgr *xcp_mgr;
284291

285-
if (!xcp_funcs || !xcp_funcs->switch_partition_mode ||
286-
!xcp_funcs->get_ip_details)
292+
if (!xcp_funcs || !xcp_funcs->get_ip_details)
287293
return -EINVAL;
288294

289295
xcp_mgr = kzalloc(sizeof(*xcp_mgr), GFP_KERNEL);

drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,56 @@ u64 aqua_vanjaram_encode_ext_smn_addressing(int ext_id)
304304
return ext_offset;
305305
}
306306

307+
static enum amdgpu_gfx_partition
308+
__aqua_vanjaram_calc_xcp_mode(struct amdgpu_xcp_mgr *xcp_mgr)
309+
{
310+
struct amdgpu_device *adev = xcp_mgr->adev;
311+
int num_xcc, num_xcc_per_xcp = 0, mode = 0;
312+
313+
num_xcc = NUM_XCC(xcp_mgr->adev->gfx.xcc_mask);
314+
if (adev->gfx.funcs->get_xccs_per_xcp)
315+
num_xcc_per_xcp = adev->gfx.funcs->get_xccs_per_xcp(adev);
316+
if ((num_xcc_per_xcp) && (num_xcc % num_xcc_per_xcp == 0))
317+
mode = num_xcc / num_xcc_per_xcp;
318+
319+
if (num_xcc_per_xcp == 1)
320+
return AMDGPU_CPX_PARTITION_MODE;
321+
322+
switch (mode) {
323+
case 1:
324+
return AMDGPU_SPX_PARTITION_MODE;
325+
case 2:
326+
return AMDGPU_DPX_PARTITION_MODE;
327+
case 3:
328+
return AMDGPU_TPX_PARTITION_MODE;
329+
case 4:
330+
return AMDGPU_QPX_PARTITION_MODE;
331+
default:
332+
return AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE;
333+
}
334+
335+
return AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE;
336+
}
337+
307338
static int aqua_vanjaram_query_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr)
308339
{
309-
enum amdgpu_gfx_partition mode = AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE;
340+
enum amdgpu_gfx_partition derv_mode,
341+
mode = AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE;
310342
struct amdgpu_device *adev = xcp_mgr->adev;
311343

312-
if (adev->nbio.funcs->get_compute_partition_mode)
344+
derv_mode = __aqua_vanjaram_calc_xcp_mode(xcp_mgr);
345+
346+
if (amdgpu_sriov_vf(adev))
347+
return derv_mode;
348+
349+
if (adev->nbio.funcs->get_compute_partition_mode) {
313350
mode = adev->nbio.funcs->get_compute_partition_mode(adev);
351+
if (mode != derv_mode)
352+
dev_warn(
353+
adev->dev,
354+
"Mismatch in compute partition mode - reported : %d derived : %d",
355+
mode, derv_mode);
356+
}
314357

315358
return mode;
316359
}
@@ -624,6 +667,9 @@ static int aqua_vanjaram_xcp_mgr_init(struct amdgpu_device *adev)
624667
{
625668
int ret;
626669

670+
if (amdgpu_sriov_vf(adev))
671+
aqua_vanjaram_xcp_funcs.switch_partition_mode = NULL;
672+
627673
ret = amdgpu_xcp_mgr_init(adev, AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE, 1,
628674
&aqua_vanjaram_xcp_funcs);
629675
if (ret)

drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,15 @@ static void gfx_v9_4_3_select_me_pipe_q(struct amdgpu_device *adev,
652652
soc15_grbm_select(adev, me, pipe, q, vm, GET_INST(GC, xcc_id));
653653
}
654654

655+
static int gfx_v9_4_3_get_xccs_per_xcp(struct amdgpu_device *adev)
656+
{
657+
u32 xcp_ctl;
658+
659+
/* Value is expected to be the same on all, fetch from first instance */
660+
xcp_ctl = RREG32_SOC15(GC, GET_INST(GC, 0), regCP_HYP_XCP_CTL);
661+
662+
return REG_GET_FIELD(xcp_ctl, CP_HYP_XCP_CTL, NUM_XCC_IN_XCP);
663+
}
655664

656665
static int gfx_v9_4_3_switch_compute_partition(struct amdgpu_device *adev,
657666
int num_xccs_per_xcp)
@@ -706,6 +715,7 @@ static const struct amdgpu_gfx_funcs gfx_v9_4_3_gfx_funcs = {
706715
.select_me_pipe_q = &gfx_v9_4_3_select_me_pipe_q,
707716
.switch_partition_mode = &gfx_v9_4_3_switch_compute_partition,
708717
.ih_node_to_logical_xcc = &gfx_v9_4_3_ih_to_xcc_inst,
718+
.get_xccs_per_xcp = &gfx_v9_4_3_get_xccs_per_xcp,
709719
};
710720

711721
static int gfx_v9_4_3_aca_bank_parser(struct aca_handle *handle,
@@ -2050,18 +2060,31 @@ static int gfx_v9_4_3_xcc_cp_resume(struct amdgpu_device *adev, int xcc_id)
20502060

20512061
static int gfx_v9_4_3_cp_resume(struct amdgpu_device *adev)
20522062
{
2053-
int r = 0, i, num_xcc;
2063+
int r = 0, i, num_xcc, num_xcp, num_xcc_per_xcp;
2064+
2065+
num_xcc = NUM_XCC(adev->gfx.xcc_mask);
2066+
if (amdgpu_sriov_vf(adev)) {
2067+
enum amdgpu_gfx_partition mode;
20542068

2055-
if (amdgpu_xcp_query_partition_mode(adev->xcp_mgr,
2056-
AMDGPU_XCP_FL_NONE) ==
2057-
AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE)
2058-
r = amdgpu_xcp_switch_partition_mode(adev->xcp_mgr,
2059-
amdgpu_user_partt_mode);
2069+
mode = amdgpu_xcp_query_partition_mode(adev->xcp_mgr,
2070+
AMDGPU_XCP_FL_NONE);
2071+
if (mode == AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE)
2072+
return -EINVAL;
2073+
num_xcc_per_xcp = gfx_v9_4_3_get_xccs_per_xcp(adev);
2074+
adev->gfx.num_xcc_per_xcp = num_xcc_per_xcp;
2075+
num_xcp = num_xcc / num_xcc_per_xcp;
2076+
r = amdgpu_xcp_init(adev->xcp_mgr, num_xcp, mode);
20602077

2078+
} else {
2079+
if (amdgpu_xcp_query_partition_mode(adev->xcp_mgr,
2080+
AMDGPU_XCP_FL_NONE) ==
2081+
AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE)
2082+
r = amdgpu_xcp_switch_partition_mode(
2083+
adev->xcp_mgr, amdgpu_user_partt_mode);
2084+
}
20612085
if (r)
20622086
return r;
20632087

2064-
num_xcc = NUM_XCC(adev->gfx.xcc_mask);
20652088
for (i = 0; i < num_xcc; i++) {
20662089
r = gfx_v9_4_3_xcc_cp_resume(adev, i);
20672090
if (r)

0 commit comments

Comments
 (0)