Skip to content

Commit 2181168

Browse files
author
CKI KWF Bot
committed
Merge: platform/x86/amd/pmf: Updates to PMF Driver for Improved Custom BIOS Input Handling
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1689 Description: Enhancements to PMF Driver for Improved Custom BIOS Input Handling and a fix for platform/x86/dell: Set USTT mode according to BIOS after reboot JIRA: https://issues.redhat.com/browse/RHEL-73301 Build Info: 69323710 Signed-off-by: Steve Best <sbest@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: David Arcari <darcari@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 35e6fbe + 609a350 commit 2181168

File tree

5 files changed

+249
-26
lines changed

5 files changed

+249
-26
lines changed

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

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ int is_apmf_func_supported(struct amd_pmf_dev *pdev, unsigned long index)
161161
return !!(pdev->supported_func & BIT(index - 1));
162162
}
163163

164+
int is_apmf_bios_input_notifications_supported(struct amd_pmf_dev *pdev)
165+
{
166+
return !!(pdev->notifications & CUSTOM_BIOS_INPUT_BITS);
167+
}
168+
164169
int apts_get_static_slider_granular_v2(struct amd_pmf_dev *pdev,
165170
struct amd_pmf_apts_granular_output *data, u32 apts_idx)
166171
{
@@ -315,12 +320,26 @@ int apmf_get_sbios_requests_v2(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v
315320
return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
316321
}
317322

323+
int apmf_get_sbios_requests_v1(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v1 *req)
324+
{
325+
return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS, req, sizeof(*req));
326+
}
327+
318328
int apmf_get_sbios_requests(struct amd_pmf_dev *pdev, struct apmf_sbios_req *req)
319329
{
320330
return apmf_if_call_store_buffer(pdev, APMF_FUNC_SBIOS_REQUESTS,
321331
req, sizeof(*req));
322332
}
323333

334+
static void amd_pmf_handle_early_preq(struct amd_pmf_dev *pdev)
335+
{
336+
if (!pdev->cb_flag)
337+
return;
338+
339+
amd_pmf_invoke_cmd_enact(pdev);
340+
pdev->cb_flag = false;
341+
}
342+
324343
static void apmf_event_handler_v2(acpi_handle handle, u32 event, void *data)
325344
{
326345
struct amd_pmf_dev *pmf_dev = data;
@@ -329,8 +348,32 @@ static void apmf_event_handler_v2(acpi_handle handle, u32 event, void *data)
329348
guard(mutex)(&pmf_dev->cb_mutex);
330349

331350
ret = apmf_get_sbios_requests_v2(pmf_dev, &pmf_dev->req);
332-
if (ret)
351+
if (ret) {
333352
dev_err(pmf_dev->dev, "Failed to get v2 SBIOS requests: %d\n", ret);
353+
return;
354+
}
355+
356+
dev_dbg(pmf_dev->dev, "Pending request (preq): 0x%x\n", pmf_dev->req.pending_req);
357+
358+
amd_pmf_handle_early_preq(pmf_dev);
359+
}
360+
361+
static void apmf_event_handler_v1(acpi_handle handle, u32 event, void *data)
362+
{
363+
struct amd_pmf_dev *pmf_dev = data;
364+
int ret;
365+
366+
guard(mutex)(&pmf_dev->cb_mutex);
367+
368+
ret = apmf_get_sbios_requests_v1(pmf_dev, &pmf_dev->req1);
369+
if (ret) {
370+
dev_err(pmf_dev->dev, "Failed to get v1 SBIOS requests: %d\n", ret);
371+
return;
372+
}
373+
374+
dev_dbg(pmf_dev->dev, "Pending request (preq1): 0x%x\n", pmf_dev->req1.pending_req);
375+
376+
amd_pmf_handle_early_preq(pmf_dev);
334377
}
335378

336379
static void apmf_event_handler(acpi_handle handle, u32 event, void *data)
@@ -385,6 +428,7 @@ static int apmf_if_verify_interface(struct amd_pmf_dev *pdev)
385428

386429
pdev->pmf_if_version = output.version;
387430

431+
pdev->notifications = output.notification_mask;
388432
return 0;
389433
}
390434

@@ -421,6 +465,11 @@ int apmf_get_dyn_slider_def_dc(struct amd_pmf_dev *pdev, struct apmf_dyn_slider_
421465
return apmf_if_call_store_buffer(pdev, APMF_FUNC_DYN_SLIDER_DC, data, sizeof(*data));
422466
}
423467

468+
static apmf_event_handler_t apmf_event_handlers[] = {
469+
[PMF_IF_V1] = apmf_event_handler_v1,
470+
[PMF_IF_V2] = apmf_event_handler_v2,
471+
};
472+
424473
int apmf_install_handler(struct amd_pmf_dev *pmf_dev)
425474
{
426475
acpi_handle ahandle = ACPI_HANDLE(pmf_dev->dev);
@@ -440,13 +489,26 @@ int apmf_install_handler(struct amd_pmf_dev *pmf_dev)
440489
apmf_event_handler(ahandle, 0, pmf_dev);
441490
}
442491

443-
if (pmf_dev->smart_pc_enabled && pmf_dev->pmf_if_version == PMF_IF_V2) {
492+
if (!pmf_dev->smart_pc_enabled)
493+
return -EINVAL;
494+
495+
switch (pmf_dev->pmf_if_version) {
496+
case PMF_IF_V1:
497+
if (!is_apmf_bios_input_notifications_supported(pmf_dev))
498+
break;
499+
fallthrough;
500+
case PMF_IF_V2:
444501
status = acpi_install_notify_handler(ahandle, ACPI_ALL_NOTIFY,
445-
apmf_event_handler_v2, pmf_dev);
502+
apmf_event_handlers[pmf_dev->pmf_if_version], pmf_dev);
446503
if (ACPI_FAILURE(status)) {
447-
dev_err(pmf_dev->dev, "failed to install notify handler for custom BIOS inputs\n");
504+
dev_err(pmf_dev->dev,
505+
"failed to install notify handler v%d for custom BIOS inputs\n",
506+
pmf_dev->pmf_if_version);
448507
return -ENODEV;
449508
}
509+
break;
510+
default:
511+
break;
450512
}
451513

452514
return 0;
@@ -500,8 +562,21 @@ void apmf_acpi_deinit(struct amd_pmf_dev *pmf_dev)
500562
is_apmf_func_supported(pmf_dev, APMF_FUNC_SBIOS_REQUESTS))
501563
acpi_remove_notify_handler(ahandle, ACPI_ALL_NOTIFY, apmf_event_handler);
502564

503-
if (pmf_dev->smart_pc_enabled && pmf_dev->pmf_if_version == PMF_IF_V2)
504-
acpi_remove_notify_handler(ahandle, ACPI_ALL_NOTIFY, apmf_event_handler_v2);
565+
if (!pmf_dev->smart_pc_enabled)
566+
return;
567+
568+
switch (pmf_dev->pmf_if_version) {
569+
case PMF_IF_V1:
570+
if (!is_apmf_bios_input_notifications_supported(pmf_dev))
571+
break;
572+
fallthrough;
573+
case PMF_IF_V2:
574+
acpi_remove_notify_handler(ahandle, ACPI_ALL_NOTIFY,
575+
apmf_event_handlers[pmf_dev->pmf_if_version]);
576+
break;
577+
default:
578+
break;
579+
}
505580
}
506581

507582
int apmf_acpi_init(struct amd_pmf_dev *pmf_dev)

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

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ struct cookie_header {
9393
#define PMF_POLICY_BIOS_OUTPUT_1 10
9494
#define PMF_POLICY_BIOS_OUTPUT_2 11
9595
#define PMF_POLICY_P3T 38
96+
#define PMF_POLICY_PMF_PPT 54
97+
#define PMF_POLICY_PMF_PPT_APU_ONLY 55
9698
#define PMF_POLICY_BIOS_OUTPUT_3 57
9799
#define PMF_POLICY_BIOS_OUTPUT_4 58
98100
#define PMF_POLICY_BIOS_OUTPUT_5 59
@@ -116,6 +118,9 @@ struct cookie_header {
116118
#define PMF_IF_V2 2
117119

118120
#define APTS_MAX_STATES 16
121+
#define CUSTOM_BIOS_INPUT_BITS GENMASK(16, 7)
122+
123+
typedef void (*apmf_event_handler_t)(acpi_handle handle, u32 event, void *data);
119124

120125
/* APTS PMF BIOS Interface */
121126
struct amd_pmf_apts_output {
@@ -184,6 +189,24 @@ struct apmf_sbios_req {
184189
u8 skin_temp_hs2;
185190
} __packed;
186191

192+
/* As per APMF spec 1.3 */
193+
struct apmf_sbios_req_v1 {
194+
u16 size;
195+
u32 pending_req;
196+
u8 rsvd;
197+
u8 cql_event;
198+
u8 amt_event;
199+
u32 fppt;
200+
u32 sppt;
201+
u32 sppt_apu_only;
202+
u32 spl;
203+
u32 stt_min_limit;
204+
u8 skin_temp_apu;
205+
u8 skin_temp_hs2;
206+
u8 enable_cnqf;
207+
u32 custom_policy[10];
208+
} __packed;
209+
187210
struct apmf_sbios_req_v2 {
188211
u16 size;
189212
u32 pending_req;
@@ -331,6 +354,10 @@ enum power_modes_v2 {
331354
POWER_MODE_V2_MAX,
332355
};
333356

357+
struct pmf_bios_inputs_prev {
358+
u32 custom_bios_inputs[10];
359+
};
360+
334361
struct amd_pmf_dev {
335362
void __iomem *regbase;
336363
void __iomem *smu_virt_addr;
@@ -375,6 +402,10 @@ struct amd_pmf_dev {
375402
struct resource *res;
376403
struct apmf_sbios_req_v2 req; /* To get custom bios pending request */
377404
struct mutex cb_mutex;
405+
u32 notifications;
406+
struct apmf_sbios_req_v1 req1;
407+
struct pmf_bios_inputs_prev cb_prev; /* To preserve custom BIOS inputs */
408+
bool cb_flag; /* To handle first custom BIOS input */
378409
};
379410

380411
struct apmf_sps_prop_granular_v2 {
@@ -621,14 +652,35 @@ enum ta_slider {
621652
TA_MAX,
622653
};
623654

624-
enum apmf_smartpc_custom_bios_inputs {
625-
APMF_SMARTPC_CUSTOM_BIOS_INPUT1,
626-
APMF_SMARTPC_CUSTOM_BIOS_INPUT2,
655+
struct amd_pmf_pb_bitmap {
656+
const char *name;
657+
u32 bit_mask;
658+
};
659+
660+
static const struct amd_pmf_pb_bitmap custom_bios_inputs[] __used = {
661+
{"NOTIFY_CUSTOM_BIOS_INPUT1", BIT(5)},
662+
{"NOTIFY_CUSTOM_BIOS_INPUT2", BIT(6)},
663+
{"NOTIFY_CUSTOM_BIOS_INPUT3", BIT(7)},
664+
{"NOTIFY_CUSTOM_BIOS_INPUT4", BIT(8)},
665+
{"NOTIFY_CUSTOM_BIOS_INPUT5", BIT(9)},
666+
{"NOTIFY_CUSTOM_BIOS_INPUT6", BIT(10)},
667+
{"NOTIFY_CUSTOM_BIOS_INPUT7", BIT(11)},
668+
{"NOTIFY_CUSTOM_BIOS_INPUT8", BIT(12)},
669+
{"NOTIFY_CUSTOM_BIOS_INPUT9", BIT(13)},
670+
{"NOTIFY_CUSTOM_BIOS_INPUT10", BIT(14)},
627671
};
628672

629-
enum apmf_preq_smartpc {
630-
NOTIFY_CUSTOM_BIOS_INPUT1 = 5,
631-
NOTIFY_CUSTOM_BIOS_INPUT2,
673+
static const struct amd_pmf_pb_bitmap custom_bios_inputs_v1[] __used = {
674+
{"NOTIFY_CUSTOM_BIOS_INPUT1", BIT(7)},
675+
{"NOTIFY_CUSTOM_BIOS_INPUT2", BIT(8)},
676+
{"NOTIFY_CUSTOM_BIOS_INPUT3", BIT(9)},
677+
{"NOTIFY_CUSTOM_BIOS_INPUT4", BIT(10)},
678+
{"NOTIFY_CUSTOM_BIOS_INPUT5", BIT(11)},
679+
{"NOTIFY_CUSTOM_BIOS_INPUT6", BIT(12)},
680+
{"NOTIFY_CUSTOM_BIOS_INPUT7", BIT(13)},
681+
{"NOTIFY_CUSTOM_BIOS_INPUT8", BIT(14)},
682+
{"NOTIFY_CUSTOM_BIOS_INPUT9", BIT(15)},
683+
{"NOTIFY_CUSTOM_BIOS_INPUT10", BIT(16)},
632684
};
633685

634686
enum platform_type {
@@ -677,6 +729,8 @@ struct pmf_action_table {
677729
u32 stt_skintemp_apu; /* in C */
678730
u32 stt_skintemp_hs2; /* in C */
679731
u32 p3t_limit; /* in mW */
732+
u32 pmf_ppt; /* in mW */
733+
u32 pmf_ppt_apu_only; /* in mW */
680734
};
681735

682736
/* Input conditions */
@@ -686,8 +740,7 @@ struct ta_pmf_condition_info {
686740
u32 power_slider;
687741
u32 lid_state;
688742
bool user_present;
689-
u32 bios_input1;
690-
u32 bios_input2;
743+
u32 bios_input_1[2];
691744
u32 monitor_count;
692745
u32 rsvd2[2];
693746
u32 bat_design;
@@ -711,7 +764,9 @@ struct ta_pmf_condition_info {
711764
u32 workload_type;
712765
u32 display_type;
713766
u32 display_state;
714-
u32 rsvd5[150];
767+
u32 rsvd5_1[17];
768+
u32 bios_input_2[8];
769+
u32 rsvd5[125];
715770
};
716771

717772
struct ta_pmf_load_policy_table {
@@ -737,6 +792,7 @@ struct ta_pmf_enact_table {
737792
struct ta_pmf_action {
738793
u32 action_index;
739794
u32 value;
795+
u32 spl_arg;
740796
};
741797

742798
/* Output actions from TA */
@@ -778,6 +834,7 @@ int apmf_os_power_slider_update(struct amd_pmf_dev *dev, u8 flag);
778834
int amd_pmf_set_dram_addr(struct amd_pmf_dev *dev, bool alloc_buffer);
779835
int amd_pmf_notify_sbios_heartbeat_event_v2(struct amd_pmf_dev *dev, u8 flag);
780836
u32 fixp_q88_fromint(u32 val);
837+
int is_apmf_bios_input_notifications_supported(struct amd_pmf_dev *pdev);
781838

782839
/* SPS Layer */
783840
int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf);
@@ -805,6 +862,7 @@ void amd_pmf_init_auto_mode(struct amd_pmf_dev *dev);
805862
void amd_pmf_deinit_auto_mode(struct amd_pmf_dev *dev);
806863
void amd_pmf_trans_automode(struct amd_pmf_dev *dev, int socket_power, ktime_t time_elapsed_ms);
807864
int apmf_get_sbios_requests(struct amd_pmf_dev *pdev, struct apmf_sbios_req *req);
865+
int apmf_get_sbios_requests_v1(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v1 *req);
808866
int apmf_get_sbios_requests_v2(struct amd_pmf_dev *pdev, struct apmf_sbios_req_v2 *req);
809867

810868
void amd_pmf_update_2_cql(struct amd_pmf_dev *dev, bool is_cql_event);
@@ -828,5 +886,6 @@ int amd_pmf_smartpc_apply_bios_output(struct amd_pmf_dev *dev, u32 val, u32 preq
828886
/* Smart PC - TA interfaces */
829887
void amd_pmf_populate_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);
830888
void amd_pmf_dump_ta_inputs(struct amd_pmf_dev *dev, struct ta_pmf_enact_table *in);
889+
int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev);
831890

832891
#endif /* PMF_H */

0 commit comments

Comments
 (0)