Skip to content

Commit 48d38f5

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmf: Add support to get APTS index numbers for static slider
APMF spec has a newer section called the APTS (AMD Performance and Thermal State) information, where each slider/power mode is associated with an index number. Add support to get these indices for the Static Slider. Reviewed-by: Ilpo Järvinen <[email protected]> Co-developed-by: Patil Rajesh Reddy <[email protected]> Signed-off-by: Patil Rajesh Reddy <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 6262938 commit 48d38f5

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

drivers/platform/x86/amd/pmf/acpi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
9696
return !!(pdev->supported_func & BIT(index - 1));
9797
}
9898

99+
int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
100+
struct apmf_static_slider_granular_output_v2 *data)
101+
{
102+
if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
103+
return -EINVAL;
104+
105+
return apmf_if_call_store_buffer(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR,
106+
data, sizeof(*data));
107+
}
108+
99109
int apmf_get_static_slider_granular(struct amd_pmf_dev *pdev,
100110
struct apmf_static_slider_granular_output *data)
101111
{

drivers/platform/x86/amd/pmf/pmf.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct cookie_header {
8989
#define MAX_OPERATION_PARAMS 4
9090

9191
#define PMF_IF_V1 1
92+
#define PMF_IF_V2 2
9293

9394
struct sbios_hb_event_v2 {
9495
u16 size;
@@ -228,6 +229,14 @@ enum power_modes {
228229
POWER_MODE_MAX,
229230
};
230231

232+
enum power_modes_v2 {
233+
POWER_MODE_BEST_PERFORMANCE,
234+
POWER_MODE_BALANCED,
235+
POWER_MODE_BEST_POWER_EFFICIENCY,
236+
POWER_MODE_ENERGY_SAVE,
237+
POWER_MODE_V2_MAX,
238+
};
239+
231240
struct amd_pmf_dev {
232241
void __iomem *regbase;
233242
void __iomem *smu_virt_addr;
@@ -268,6 +277,10 @@ struct amd_pmf_dev {
268277
u16 pmf_if_version;
269278
};
270279

280+
struct apmf_sps_prop_granular_v2 {
281+
u8 power_states[POWER_SOURCE_MAX][POWER_MODE_V2_MAX];
282+
} __packed;
283+
271284
struct apmf_sps_prop_granular {
272285
u32 fppt;
273286
u32 sppt;
@@ -289,6 +302,16 @@ struct amd_pmf_static_slider_granular {
289302
struct apmf_sps_prop_granular prop[POWER_SOURCE_MAX][POWER_MODE_MAX];
290303
};
291304

305+
struct apmf_static_slider_granular_output_v2 {
306+
u16 size;
307+
struct apmf_sps_prop_granular_v2 sps_idx;
308+
} __packed;
309+
310+
struct amd_pmf_static_slider_granular_v2 {
311+
u16 size;
312+
struct apmf_sps_prop_granular_v2 sps_idx;
313+
};
314+
292315
struct os_power_slider {
293316
u16 size;
294317
u8 slider_event;
@@ -643,6 +666,8 @@ const char *amd_pmf_source_as_str(unsigned int state);
643666

644667
int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx);
645668
int amd_pmf_set_sps_power_limits(struct amd_pmf_dev *pmf);
669+
int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *dev,
670+
struct apmf_static_slider_granular_output_v2 *data);
646671

647672
/* Auto Mode Layer */
648673
int apmf_get_auto_mode_def(struct amd_pmf_dev *pdev, struct apmf_auto_mode *data);

drivers/platform/x86/amd/pmf/sps.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,26 @@
1010

1111
#include "pmf.h"
1212

13+
static struct amd_pmf_static_slider_granular_v2 config_store_v2;
1314
static struct amd_pmf_static_slider_granular config_store;
1415

1516
#ifdef CONFIG_AMD_PMF_DEBUG
17+
static const char *slider_v2_as_str(unsigned int state)
18+
{
19+
switch (state) {
20+
case POWER_MODE_BEST_PERFORMANCE:
21+
return "Best Performance";
22+
case POWER_MODE_BALANCED:
23+
return "Balanced";
24+
case POWER_MODE_BEST_POWER_EFFICIENCY:
25+
return "Best Power Efficiency";
26+
case POWER_MODE_ENERGY_SAVE:
27+
return "Energy Save";
28+
default:
29+
return "Unknown Power Mode";
30+
}
31+
}
32+
1633
static const char *slider_as_str(unsigned int state)
1734
{
1835
switch (state) {
@@ -63,10 +80,44 @@ static void amd_pmf_dump_sps_defaults(struct amd_pmf_static_slider_granular *dat
6380

6481
pr_debug("Static Slider Data - END\n");
6582
}
83+
84+
static void amd_pmf_dump_sps_defaults_v2(struct amd_pmf_static_slider_granular_v2 *data)
85+
{
86+
unsigned int i, j;
87+
88+
pr_debug("Static Slider APTS state index data - BEGIN");
89+
pr_debug("size: %u\n", data->size);
90+
91+
for (i = 0; i < POWER_SOURCE_MAX; i++)
92+
for (j = 0; j < POWER_MODE_V2_MAX; j++)
93+
pr_debug("%s %s: %u\n", amd_pmf_source_as_str(i), slider_v2_as_str(j),
94+
data->sps_idx.power_states[i][j]);
95+
96+
pr_debug("Static Slider APTS state index data - END\n");
97+
}
6698
#else
6799
static void amd_pmf_dump_sps_defaults(struct amd_pmf_static_slider_granular *data) {}
100+
static void amd_pmf_dump_sps_defaults_v2(struct amd_pmf_static_slider_granular_v2 *data) {}
68101
#endif
69102

103+
static void amd_pmf_load_defaults_sps_v2(struct amd_pmf_dev *dev)
104+
{
105+
struct apmf_static_slider_granular_output_v2 output;
106+
unsigned int i, j;
107+
108+
memset(&config_store_v2, 0, sizeof(config_store_v2));
109+
apmf_get_static_slider_granular_v2(dev, &output);
110+
111+
config_store_v2.size = output.size;
112+
113+
for (i = 0; i < POWER_SOURCE_MAX; i++)
114+
for (j = 0; j < POWER_MODE_V2_MAX; j++)
115+
config_store_v2.sps_idx.power_states[i][j] =
116+
output.sps_idx.power_states[i][j];
117+
118+
amd_pmf_dump_sps_defaults_v2(&config_store_v2);
119+
}
120+
70121
static void amd_pmf_load_defaults_sps(struct amd_pmf_dev *dev)
71122
{
72123
struct apmf_static_slider_granular_output output;
@@ -256,7 +307,10 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
256307
dev->current_profile = PLATFORM_PROFILE_BALANCED;
257308

258309
if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
259-
amd_pmf_load_defaults_sps(dev);
310+
if (dev->pmf_if_version == PMF_IF_V2)
311+
amd_pmf_load_defaults_sps_v2(dev);
312+
else
313+
amd_pmf_load_defaults_sps(dev);
260314

261315
/* update SPS balanced power mode thermals */
262316
amd_pmf_set_sps_power_limits(dev);

0 commit comments

Comments
 (0)