Skip to content

Commit 3eecb43

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmf: Add support to get sps default APTS index values
During the driver probe, the default cache values for the static slider would be obtained by evaluating the APTS method. Add support to use these values as the thermal settings to be updated on the system based on the changing platform-profiles. 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] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 48d38f5 commit 3eecb43

File tree

3 files changed

+148
-2
lines changed

3 files changed

+148
-2
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,86 @@ static int apmf_if_call_store_buffer(struct amd_pmf_dev *pdev, int fn, void *des
9090
return err;
9191
}
9292

93+
static union acpi_object *apts_if_call(struct amd_pmf_dev *pdev, u32 state_index)
94+
{
95+
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
96+
acpi_handle ahandle = ACPI_HANDLE(pdev->dev);
97+
struct acpi_object_list apts_if_arg_list;
98+
union acpi_object apts_if_args[3];
99+
acpi_status status;
100+
101+
apts_if_arg_list.count = 3;
102+
apts_if_arg_list.pointer = &apts_if_args[0];
103+
104+
apts_if_args[0].type = ACPI_TYPE_INTEGER;
105+
apts_if_args[0].integer.value = 1;
106+
apts_if_args[1].type = ACPI_TYPE_INTEGER;
107+
apts_if_args[1].integer.value = state_index;
108+
apts_if_args[2].type = ACPI_TYPE_INTEGER;
109+
apts_if_args[2].integer.value = 0;
110+
111+
status = acpi_evaluate_object(ahandle, "APTS", &apts_if_arg_list, &buffer);
112+
if (ACPI_FAILURE(status)) {
113+
dev_err(pdev->dev, "APTS state_idx:%u call failed\n", state_index);
114+
kfree(buffer.pointer);
115+
return NULL;
116+
}
117+
118+
return buffer.pointer;
119+
}
120+
121+
static int apts_if_call_store_buffer(struct amd_pmf_dev *pdev,
122+
u32 index, void *data, size_t out_sz)
123+
{
124+
union acpi_object *info;
125+
size_t size;
126+
int err = 0;
127+
128+
info = apts_if_call(pdev, index);
129+
if (!info)
130+
return -EIO;
131+
132+
if (info->type != ACPI_TYPE_BUFFER) {
133+
dev_err(pdev->dev, "object is not a buffer\n");
134+
err = -EINVAL;
135+
goto out;
136+
}
137+
138+
size = *(u16 *)info->buffer.pointer;
139+
if (info->buffer.length < size) {
140+
dev_err(pdev->dev, "buffer smaller than header size %u < %zu\n",
141+
info->buffer.length, size);
142+
err = -EINVAL;
143+
goto out;
144+
}
145+
146+
if (size < out_sz) {
147+
dev_err(pdev->dev, "buffer too small %zu\n", size);
148+
err = -EINVAL;
149+
goto out;
150+
}
151+
152+
memcpy(data, info->buffer.pointer, out_sz);
153+
out:
154+
kfree(info);
155+
return err;
156+
}
157+
93158
int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
94159
{
95160
/* If bit-n is set, that indicates function n+1 is supported */
96161
return !!(pdev->supported_func & BIT(index - 1));
97162
}
98163

164+
int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
165+
struct amd_pmf_apts_granular_output *data, u32 apts_idx)
166+
{
167+
if (!is_apmf_func_supported(pdev, APMF_FUNC_STATIC_SLIDER_GRANULAR))
168+
return -EINVAL;
169+
170+
return apts_if_call_store_buffer(pdev, apts_idx, data, sizeof(*data));
171+
}
172+
99173
int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
100174
struct apmf_static_slider_granular_output_v2 *data)
101175
{

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ struct cookie_header {
9191
#define PMF_IF_V1 1
9292
#define PMF_IF_V2 2
9393

94+
#define APTS_MAX_STATES 16
95+
96+
/* APTS PMF BIOS Interface */
97+
struct amd_pmf_apts_output {
98+
u16 table_version;
99+
u32 fan_table_idx;
100+
u32 pmf_ppt;
101+
u32 ppt_pmf_apu_only;
102+
u32 stt_min_limit;
103+
u8 stt_skin_temp_limit_apu;
104+
u8 stt_skin_temp_limit_hs2;
105+
} __packed;
106+
107+
struct amd_pmf_apts_granular_output {
108+
u16 size;
109+
struct amd_pmf_apts_output val;
110+
} __packed;
111+
112+
struct amd_pmf_apts_granular {
113+
u16 size;
114+
struct amd_pmf_apts_output val[APTS_MAX_STATES];
115+
};
116+
94117
struct sbios_hb_event_v2 {
95118
u16 size;
96119
u8 load;
@@ -668,6 +691,8 @@ int apmf_update_fan_idx(struct amd_pmf_dev *pdev, bool manual, u32 idx);
668691
int amd_pmf_set_sps_power_limits(struct amd_pmf_dev *pmf);
669692
int apmf_get_static_slider_granular_v2(struct amd_pmf_dev *dev,
670693
struct apmf_static_slider_granular_output_v2 *data);
694+
int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
695+
struct amd_pmf_apts_granular_output *data, u32 apts_idx);
671696

672697
/* Auto Mode Layer */
673698
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: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
static struct amd_pmf_static_slider_granular_v2 config_store_v2;
1414
static struct amd_pmf_static_slider_granular config_store;
15+
static struct amd_pmf_apts_granular apts_config_store;
1516

1617
#ifdef CONFIG_AMD_PMF_DEBUG
1718
static const char *slider_v2_as_str(unsigned int state)
@@ -95,11 +96,55 @@ static void amd_pmf_dump_sps_defaults_v2(struct amd_pmf_static_slider_granular_v
9596

9697
pr_debug("Static Slider APTS state index data - END\n");
9798
}
99+
100+
static void amd_pmf_dump_apts_sps_defaults(struct amd_pmf_apts_granular *info)
101+
{
102+
int i;
103+
104+
pr_debug("Static Slider APTS index default values data - BEGIN");
105+
106+
for (i = 0; i < APTS_MAX_STATES; i++) {
107+
pr_debug("Table Version[%d] = %u\n", i, info->val[i].table_version);
108+
pr_debug("Fan Index[%d] = %u\n", i, info->val[i].fan_table_idx);
109+
pr_debug("PPT[%d] = %u\n", i, info->val[i].pmf_ppt);
110+
pr_debug("PPT APU[%d] = %u\n", i, info->val[i].ppt_pmf_apu_only);
111+
pr_debug("STT Min[%d] = %u\n", i, info->val[i].stt_min_limit);
112+
pr_debug("STT APU[%d] = %u\n", i, info->val[i].stt_skin_temp_limit_apu);
113+
pr_debug("STT HS2[%d] = %u\n", i, info->val[i].stt_skin_temp_limit_hs2);
114+
}
115+
116+
pr_debug("Static Slider APTS index default values data - END");
117+
}
98118
#else
99119
static void amd_pmf_dump_sps_defaults(struct amd_pmf_static_slider_granular *data) {}
100120
static void amd_pmf_dump_sps_defaults_v2(struct amd_pmf_static_slider_granular_v2 *data) {}
121+
static void amd_pmf_dump_apts_sps_defaults(struct amd_pmf_apts_granular *info) {}
101122
#endif
102123

124+
static void amd_pmf_load_apts_defaults_sps_v2(struct amd_pmf_dev *pdev)
125+
{
126+
struct amd_pmf_apts_granular_output output;
127+
struct amd_pmf_apts_output *ps;
128+
int i;
129+
130+
memset(&apts_config_store, 0, sizeof(apts_config_store));
131+
132+
ps = apts_config_store.val;
133+
134+
for (i = 0; i < APTS_MAX_STATES; i++) {
135+
apts_get_static_slider_granular_v2(pdev, &output, i);
136+
ps[i].table_version = output.val.table_version;
137+
ps[i].fan_table_idx = output.val.fan_table_idx;
138+
ps[i].pmf_ppt = output.val.pmf_ppt;
139+
ps[i].ppt_pmf_apu_only = output.val.ppt_pmf_apu_only;
140+
ps[i].stt_min_limit = output.val.stt_min_limit;
141+
ps[i].stt_skin_temp_limit_apu = output.val.stt_skin_temp_limit_apu;
142+
ps[i].stt_skin_temp_limit_hs2 = output.val.stt_skin_temp_limit_hs2;
143+
}
144+
145+
amd_pmf_dump_apts_sps_defaults(&apts_config_store);
146+
}
147+
103148
static void amd_pmf_load_defaults_sps_v2(struct amd_pmf_dev *dev)
104149
{
105150
struct apmf_static_slider_granular_output_v2 output;
@@ -307,10 +352,12 @@ int amd_pmf_init_sps(struct amd_pmf_dev *dev)
307352
dev->current_profile = PLATFORM_PROFILE_BALANCED;
308353

309354
if (is_apmf_func_supported(dev, APMF_FUNC_STATIC_SLIDER_GRANULAR)) {
310-
if (dev->pmf_if_version == PMF_IF_V2)
355+
if (dev->pmf_if_version == PMF_IF_V2) {
311356
amd_pmf_load_defaults_sps_v2(dev);
312-
else
357+
amd_pmf_load_apts_defaults_sps_v2(dev);
358+
} else {
313359
amd_pmf_load_defaults_sps(dev);
360+
}
314361

315362
/* update SPS balanced power mode thermals */
316363
amd_pmf_set_sps_power_limits(dev);

0 commit comments

Comments
 (0)