Skip to content

Commit d0ba7ad

Browse files
Shyam Sundar S Kjwrdegoede
authored andcommitted
platform/x86/amd/pmf: Add support to update system state
PMF driver based on the output actions from the TA can request to update the system states like entering s0i3, lock screen etc. by generating an uevent. Based on the udev rules set in the userspace the event id matching the uevent shall get updated accordingly using the systemctl. Sample udev rules under Documentation/admin-guide/pmf.rst. Reviewed-by: Mario Limonciello <[email protected]> Signed-off-by: Shyam Sundar S K <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent c3b4093 commit d0ba7ad

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

Documentation/admin-guide/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ configure specific aspects of kernel behavior to your liking.
119119
parport
120120
perf-security
121121
pm/index
122+
pmf
122123
pnp
123124
rapidio
124125
ras

Documentation/admin-guide/pmf.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
Set udev rules for PMF Smart PC Builder
4+
---------------------------------------
5+
6+
AMD PMF(Platform Management Framework) Smart PC Solution builder has to set the system states
7+
like S0i3, Screen lock, hibernate etc, based on the output actions provided by the PMF
8+
TA (Trusted Application).
9+
10+
In order for this to work the PMF driver generates a uevent for userspace to react to. Below are
11+
sample udev rules that can facilitate this experience when a machine has PMF Smart PC solution builder
12+
enabled.
13+
14+
Please add the following line(s) to
15+
``/etc/udev/rules.d/99-local.rules``::
16+
17+
DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="0", RUN+="/usr/bin/systemctl suspend"
18+
DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="1", RUN+="/usr/bin/systemctl hibernate"
19+
DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/bin/loginctl lock-sessions"
20+
21+
EVENT_ID values:
22+
0= Put the system to S0i3/S2Idle
23+
1= Put the system to hibernate
24+
2= Lock the screen

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define PMF_POLICY_STT_MIN 6
7474
#define PMF_POLICY_STT_SKINTEMP_APU 7
7575
#define PMF_POLICY_STT_SKINTEMP_HS2 8
76+
#define PMF_POLICY_SYSTEM_STATE 9
7677
#define PMF_POLICY_P3T 38
7778

7879
/* TA macros */
@@ -445,6 +446,13 @@ enum smart_pc_status {
445446
};
446447

447448
/* Smart PC - TA internals */
449+
enum system_state {
450+
SYSTEM_STATE_S0i3,
451+
SYSTEM_STATE_S4,
452+
SYSTEM_STATE_SCREEN_LOCK,
453+
SYSTEM_STATE_MAX,
454+
};
455+
448456
enum ta_slider {
449457
TA_BEST_BATTERY,
450458
TA_BETTER_BATTERY,
@@ -476,6 +484,7 @@ enum ta_pmf_error_type {
476484
};
477485

478486
struct pmf_action_table {
487+
enum system_state system_state;
479488
u32 spl; /* in mW */
480489
u32 sppt; /* in mW */
481490
u32 sppt_apuonly; /* in mW */

drivers/platform/x86/amd/pmf/tee-if.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (defau
2424
static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
2525
0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43);
2626

27+
static const char *amd_pmf_uevent_as_str(unsigned int state)
28+
{
29+
switch (state) {
30+
case SYSTEM_STATE_S0i3:
31+
return "S0i3";
32+
case SYSTEM_STATE_S4:
33+
return "S4";
34+
case SYSTEM_STATE_SCREEN_LOCK:
35+
return "SCREEN_LOCK";
36+
default:
37+
return "Unknown Smart PC event";
38+
}
39+
}
40+
2741
static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
2842
struct tee_ioctl_invoke_arg *arg,
2943
struct tee_param *param)
@@ -42,6 +56,20 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
4256
param[0].u.memref.shm_offs = 0;
4357
}
4458

59+
static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
60+
{
61+
char *envp[2] = {};
62+
63+
envp[0] = kasprintf(GFP_KERNEL, "EVENT_ID=%d", event);
64+
if (!envp[0])
65+
return -EINVAL;
66+
67+
kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, envp);
68+
69+
kfree(envp[0]);
70+
return 0;
71+
}
72+
4573
static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out)
4674
{
4775
u32 val;
@@ -113,6 +141,12 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
113141
dev->prev_data->p3t_limit = val;
114142
}
115143
break;
144+
145+
case PMF_POLICY_SYSTEM_STATE:
146+
amd_pmf_update_uevents(dev, val);
147+
dev_dbg(dev->dev, "update SYSTEM_STATE: %s\n",
148+
amd_pmf_uevent_as_str(val));
149+
break;
116150
}
117151
}
118152
}

0 commit comments

Comments
 (0)