Skip to content

Commit 92cf050

Browse files
Evan Quanalexdeucher
authored andcommitted
drm/amd/pm: restore user customized OD settings properly for NV1x
The customized OD settings can be divided into two parts: those committed ones and non-committed ones. - For those changes which had been fed to SMU before S3/S4/Runpm suspend kicked, they are committed changes. They should be properly restored and fed to SMU on S3/S4/Runpm resume. - For those non-committed changes, they are restored only without feeding to SMU. Signed-off-by: Evan Quan <[email protected]> Reviewed-by: Lijo Lazar <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent b928ecf commit 92cf050

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-17
lines changed

drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ struct smu_user_dpm_profile {
231231
uint32_t power_limit;
232232
uint32_t fan_speed_percent;
233233
uint32_t flags;
234+
uint32_t user_od;
234235

235236
/* user clock state information */
236237
uint32_t clk_mask[SMU_CLK_COUNT];
@@ -352,6 +353,7 @@ struct smu_table_context
352353

353354
void *overdrive_table;
354355
void *boot_overdrive_table;
356+
void *user_overdrive_table;
355357

356358
uint32_t gpu_metrics_table_size;
357359
void *gpu_metrics_table;
@@ -623,6 +625,12 @@ struct pptable_funcs {
623625
enum PP_OD_DPM_TABLE_COMMAND type,
624626
long *input, uint32_t size);
625627

628+
/**
629+
* @restore_user_od_settings: Restore the user customized
630+
* OD settings on S3/S4/Runpm resume.
631+
*/
632+
int (*restore_user_od_settings)(struct smu_context *smu);
633+
626634
/**
627635
* @get_clock_by_type_with_latency: Get the speed and latency of a clock
628636
* domain.

drivers/gpu/drm/amd/pm/inc/smu_v11_0.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,5 +303,7 @@ void smu_v11_0_interrupt_work(struct smu_context *smu);
303303

304304
int smu_v11_0_set_light_sbr(struct smu_context *smu, bool enable);
305305

306+
int smu_v11_0_restore_user_od_settings(struct smu_context *smu);
307+
306308
#endif
307309
#endif

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)
417417
}
418418
}
419419

420+
/* Restore user customized OD settings */
421+
if (smu->user_dpm_profile.user_od) {
422+
if (smu->ppt_funcs->restore_user_od_settings) {
423+
ret = smu->ppt_funcs->restore_user_od_settings(smu);
424+
if (ret)
425+
dev_err(smu->adev->dev, "Failed to upload customized OD settings\n");
426+
}
427+
}
428+
420429
/* Disable restore flag */
421430
smu->user_dpm_profile.flags &= ~SMU_DPM_USER_PROFILE_RESTORE;
422431
}

drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,41 +2294,52 @@ static int navi10_set_default_od_settings(struct smu_context *smu)
22942294
(OverDriveTable_t *)smu->smu_table.overdrive_table;
22952295
OverDriveTable_t *boot_od_table =
22962296
(OverDriveTable_t *)smu->smu_table.boot_overdrive_table;
2297+
OverDriveTable_t *user_od_table =
2298+
(OverDriveTable_t *)smu->smu_table.user_overdrive_table;
22972299
int ret = 0;
22982300

2299-
ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, false);
2301+
/*
2302+
* For S3/S4/Runpm resume, no need to setup those overdrive tables again as
2303+
* - either they already have the default OD settings got during cold bootup
2304+
* - or they have some user customized OD settings which cannot be overwritten
2305+
*/
2306+
if (smu->adev->in_suspend)
2307+
return 0;
2308+
2309+
ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)boot_od_table, false);
23002310
if (ret) {
23012311
dev_err(smu->adev->dev, "Failed to get overdrive table!\n");
23022312
return ret;
23032313
}
23042314

2305-
if (!od_table->GfxclkVolt1) {
2315+
if (!boot_od_table->GfxclkVolt1) {
23062316
ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
2307-
&od_table->GfxclkVolt1,
2308-
od_table->GfxclkFreq1);
2317+
&boot_od_table->GfxclkVolt1,
2318+
boot_od_table->GfxclkFreq1);
23092319
if (ret)
23102320
return ret;
23112321
}
23122322

2313-
if (!od_table->GfxclkVolt2) {
2323+
if (!boot_od_table->GfxclkVolt2) {
23142324
ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
2315-
&od_table->GfxclkVolt2,
2316-
od_table->GfxclkFreq2);
2325+
&boot_od_table->GfxclkVolt2,
2326+
boot_od_table->GfxclkFreq2);
23172327
if (ret)
23182328
return ret;
23192329
}
23202330

2321-
if (!od_table->GfxclkVolt3) {
2331+
if (!boot_od_table->GfxclkVolt3) {
23222332
ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
2323-
&od_table->GfxclkVolt3,
2324-
od_table->GfxclkFreq3);
2333+
&boot_od_table->GfxclkVolt3,
2334+
boot_od_table->GfxclkFreq3);
23252335
if (ret)
23262336
return ret;
23272337
}
23282338

2329-
memcpy(boot_od_table, od_table, sizeof(OverDriveTable_t));
2339+
navi10_dump_od_table(smu, boot_od_table);
23302340

2331-
navi10_dump_od_table(smu, od_table);
2341+
memcpy(od_table, boot_od_table, sizeof(OverDriveTable_t));
2342+
memcpy(user_od_table, boot_od_table, sizeof(OverDriveTable_t));
23322343

23332344
return 0;
23342345
}
@@ -2429,11 +2440,20 @@ static int navi10_od_edit_dpm_table(struct smu_context *smu, enum PP_OD_DPM_TABL
24292440
memcpy(table_context->overdrive_table, table_context->boot_overdrive_table, sizeof(OverDriveTable_t));
24302441
break;
24312442
case PP_OD_COMMIT_DPM_TABLE:
2432-
navi10_dump_od_table(smu, od_table);
2433-
ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, true);
2434-
if (ret) {
2435-
dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
2436-
return ret;
2443+
if (memcmp(od_table, table_context->user_overdrive_table, sizeof(OverDriveTable_t))) {
2444+
navi10_dump_od_table(smu, od_table);
2445+
ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, true);
2446+
if (ret) {
2447+
dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
2448+
return ret;
2449+
}
2450+
memcpy(table_context->user_overdrive_table, od_table, sizeof(OverDriveTable_t));
2451+
smu->user_dpm_profile.user_od = true;
2452+
2453+
if (!memcmp(table_context->user_overdrive_table,
2454+
table_context->boot_overdrive_table,
2455+
sizeof(OverDriveTable_t)))
2456+
smu->user_dpm_profile.user_od = false;
24372457
}
24382458
break;
24392459
case PP_OD_EDIT_VDDC_CURVE:
@@ -3262,6 +3282,7 @@ static const struct pptable_funcs navi10_ppt_funcs = {
32623282
.set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
32633283
.set_default_od_settings = navi10_set_default_od_settings,
32643284
.od_edit_dpm_table = navi10_od_edit_dpm_table,
3285+
.restore_user_od_settings = smu_v11_0_restore_user_od_settings,
32653286
.run_btc = navi10_run_btc,
32663287
.set_power_source = smu_v11_0_set_power_source,
32673288
.get_pp_feature_mask = smu_cmn_get_pp_feature_mask,

drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,20 @@ int smu_v11_0_init_smc_tables(struct smu_context *smu)
425425
ret = -ENOMEM;
426426
goto err3_out;
427427
}
428+
429+
smu_table->user_overdrive_table =
430+
kzalloc(tables[SMU_TABLE_OVERDRIVE].size, GFP_KERNEL);
431+
if (!smu_table->user_overdrive_table) {
432+
ret = -ENOMEM;
433+
goto err4_out;
434+
}
435+
428436
}
429437

430438
return 0;
431439

440+
err4_out:
441+
kfree(smu_table->boot_overdrive_table);
432442
err3_out:
433443
kfree(smu_table->overdrive_table);
434444
err2_out:
@@ -445,12 +455,14 @@ int smu_v11_0_fini_smc_tables(struct smu_context *smu)
445455
struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
446456

447457
kfree(smu_table->gpu_metrics_table);
458+
kfree(smu_table->user_overdrive_table);
448459
kfree(smu_table->boot_overdrive_table);
449460
kfree(smu_table->overdrive_table);
450461
kfree(smu_table->max_sustainable_clocks);
451462
kfree(smu_table->driver_pptable);
452463
kfree(smu_table->clocks_table);
453464
smu_table->gpu_metrics_table = NULL;
465+
smu_table->user_overdrive_table = NULL;
454466
smu_table->boot_overdrive_table = NULL;
455467
smu_table->overdrive_table = NULL;
456468
smu_table->max_sustainable_clocks = NULL;
@@ -2104,3 +2116,16 @@ int smu_v11_0_deep_sleep_control(struct smu_context *smu,
21042116

21052117
return ret;
21062118
}
2119+
2120+
int smu_v11_0_restore_user_od_settings(struct smu_context *smu)
2121+
{
2122+
struct smu_table_context *table_context = &smu->smu_table;
2123+
void *user_od_table = table_context->user_overdrive_table;
2124+
int ret = 0;
2125+
2126+
ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)user_od_table, true);
2127+
if (ret)
2128+
dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
2129+
2130+
return ret;
2131+
}

0 commit comments

Comments
 (0)