]> www.infradead.org Git - users/hch/configfs.git/commitdiff
platform/x86/amd/pmf: Add support to update system state
authorShyam Sundar S K <Shyam-sundar.S-k@amd.com>
Tue, 12 Dec 2023 01:47:01 +0000 (07:17 +0530)
committerHans de Goede <hdegoede@redhat.com>
Mon, 18 Dec 2023 11:47:46 +0000 (12:47 +0100)
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 <mario.limonciello@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Link: https://lore.kernel.org/r/20231212014705.2017474-9-Shyam-sundar.S-k@amd.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Documentation/admin-guide/index.rst
Documentation/admin-guide/pmf.rst [new file with mode: 0644]
drivers/platform/x86/amd/pmf/pmf.h
drivers/platform/x86/amd/pmf/tee-if.c

index 43ea35613dfcd464f2d861a5baaa62a4fd0fa18e..fb40a1f6f79e18d85ddb1ff254c9a04fed9ade2b 100644 (file)
@@ -119,6 +119,7 @@ configure specific aspects of kernel behavior to your liking.
    parport
    perf-security
    pm/index
+   pmf
    pnp
    rapidio
    ras
diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst
new file mode 100644 (file)
index 0000000..9ee729f
--- /dev/null
@@ -0,0 +1,24 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Set udev rules for PMF Smart PC Builder
+---------------------------------------
+
+AMD PMF(Platform Management Framework) Smart PC Solution builder has to set the system states
+like S0i3, Screen lock, hibernate etc, based on the output actions provided by the PMF
+TA (Trusted Application).
+
+In order for this to work the PMF driver generates a uevent for userspace to react to. Below are
+sample udev rules that can facilitate this experience when a machine has PMF Smart PC solution builder
+enabled.
+
+Please add the following line(s) to
+``/etc/udev/rules.d/99-local.rules``::
+
+        DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="0", RUN+="/usr/bin/systemctl suspend"
+        DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="1", RUN+="/usr/bin/systemctl hibernate"
+        DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/bin/loginctl lock-sessions"
+
+EVENT_ID values:
+0= Put the system to S0i3/S2Idle
+1= Put the system to hibernate
+2= Lock the screen
index 37bf1c701361f24e5ffa8e6235d2814b2660f975..50f98c398727900fe752a008817f3a17bfb77b62 100644 (file)
@@ -73,6 +73,7 @@
 #define PMF_POLICY_STT_MIN                                     6
 #define PMF_POLICY_STT_SKINTEMP_APU                            7
 #define PMF_POLICY_STT_SKINTEMP_HS2                            8
+#define PMF_POLICY_SYSTEM_STATE                                        9
 #define PMF_POLICY_P3T                                         38
 
 /* TA macros */
@@ -445,6 +446,13 @@ enum smart_pc_status {
 };
 
 /* Smart PC - TA internals */
+enum system_state {
+       SYSTEM_STATE_S0i3,
+       SYSTEM_STATE_S4,
+       SYSTEM_STATE_SCREEN_LOCK,
+       SYSTEM_STATE_MAX,
+};
+
 enum ta_slider {
        TA_BEST_BATTERY,
        TA_BETTER_BATTERY,
@@ -476,6 +484,7 @@ enum ta_pmf_error_type {
 };
 
 struct pmf_action_table {
+       enum system_state system_state;
        u32 spl;                /* in mW */
        u32 sppt;               /* in mW */
        u32 sppt_apuonly;       /* in mW */
index bf8cb98d41ec25f7281963c82655801e18d02340..8811631c7be507af1c36bc4adba639ff68f531da 100644 (file)
@@ -24,6 +24,20 @@ MODULE_PARM_DESC(pb_actions_ms, "Policy binary actions sampling frequency (defau
 static const uuid_t amd_pmf_ta_uuid = UUID_INIT(0x6fd93b77, 0x3fb8, 0x524d,
                                                0xb1, 0x2d, 0xc5, 0x29, 0xb1, 0x3d, 0x85, 0x43);
 
+static const char *amd_pmf_uevent_as_str(unsigned int state)
+{
+       switch (state) {
+       case SYSTEM_STATE_S0i3:
+               return "S0i3";
+       case SYSTEM_STATE_S4:
+               return "S4";
+       case SYSTEM_STATE_SCREEN_LOCK:
+               return "SCREEN_LOCK";
+       default:
+               return "Unknown Smart PC event";
+       }
+}
+
 static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
                                 struct tee_ioctl_invoke_arg *arg,
                                 struct tee_param *param)
@@ -42,6 +56,20 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
        param[0].u.memref.shm_offs = 0;
 }
 
+static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
+{
+       char *envp[2] = {};
+
+       envp[0] = kasprintf(GFP_KERNEL, "EVENT_ID=%d", event);
+       if (!envp[0])
+               return -EINVAL;
+
+       kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, envp);
+
+       kfree(envp[0]);
+       return 0;
+}
+
 static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out)
 {
        u32 val;
@@ -113,6 +141,12 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
                                dev->prev_data->p3t_limit = val;
                        }
                        break;
+
+               case PMF_POLICY_SYSTEM_STATE:
+                       amd_pmf_update_uevents(dev, val);
+                       dev_dbg(dev->dev, "update SYSTEM_STATE: %s\n",
+                               amd_pmf_uevent_as_str(val));
+                       break;
                }
        }
 }