From: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> To: <hdegoede@redhat.com>, <markgross@kernel.org>, <basavaraj.natikar@amd.com>, <jikos@kernel.org>, <benjamin.tissoires@redhat.com>, <alexander.deucher@amd.com>, <christian.koenig@amd.com>, <Xinhui.Pan@amd.com>, <airlied@gmail.com>, <daniel@ffwll.ch> Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>, amd-gfx@lists.freedesktop.org, platform-driver-x86@vger.kernel.org, dri-devel@lists.freedesktop.org, Patil.Reddy@amd.com, linux-input@vger.kernel.org, mario.limonciello@amd.com Subject: [PATCH 08/15] platform/x86/amd/pmf: Add support to update system state Date: Fri, 22 Sep 2023 23:20:49 +0530 [thread overview] Message-ID: <20230922175056.244940-9-Shyam-sundar.S-k@amd.com> (raw) In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> 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. Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> --- Documentation/admin-guide/pmf.rst | 24 ++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 9 ++++++ drivers/platform/x86/amd/pmf/tee-if.c | 40 ++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/pmf.rst diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst new file mode 100644 index 000000000000..b60f381410c3 --- /dev/null +++ b/Documentation/admin-guide/pmf.rst @@ -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}=="1", RUN+="/usr/bin/systemctl suspend" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/usr/bin/systemctl hibernate" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="3", RUN+="/bin/loginctl lock-sessions" + +EVENT_ID values: +1= Put the system to S0i3/S2Idle +2= Put the system to hibernate +3= Lock the screen + diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 897f61b75e2f..c5334f1177a4 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -70,6 +70,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 */ @@ -436,6 +437,13 @@ struct apmf_dyn_slider_output { } __packed; /* Smart PC - TA internals */ +enum system_state { + SYSTEM_STATE__S0i3 = 1, + SYSTEM_STATE__S4, + SYSTEM_STATE__SCREEN_LOCK, + SYSTEM_STATE__MAX +}; + enum ta_slider { TA_BEST_BATTERY, /* Best Battery */ TA_BETTER_BATTERY, /* Better Battery */ @@ -467,6 +475,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + enum system_state system_state; unsigned long spl; /* in mW */ unsigned long sppt; /* in mW */ unsigned long sppt_apuonly; /* in mW */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 883dd143375a..1629856c20b4 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -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,9 +56,23 @@ 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; + u32 val, event = 0; int idx; for (idx = 0; idx < out->actions_count; idx++) { @@ -113,6 +141,16 @@ 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: + event = val + 1; + if (dev->prev_data->system_state != event) { + amd_pmf_update_uevents(dev, event); + dev_dbg(dev->dev, "update SYSTEM_STATE : %s\n", + amd_pmf_uevent_as_str(event)); + dev->prev_data->system_state = 0; + } + break; } } } -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> To: <hdegoede@redhat.com>, <markgross@kernel.org>, <basavaraj.natikar@amd.com>, <jikos@kernel.org>, <benjamin.tissoires@redhat.com>, <alexander.deucher@amd.com>, <christian.koenig@amd.com>, <Xinhui.Pan@amd.com>, <airlied@gmail.com>, <daniel@ffwll.ch> Cc: <Patil.Reddy@amd.com>, <mario.limonciello@amd.com>, <platform-driver-x86@vger.kernel.org>, <linux-input@vger.kernel.org>, <amd-gfx@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>, "Shyam Sundar S K" <Shyam-sundar.S-k@amd.com> Subject: [PATCH 08/15] platform/x86/amd/pmf: Add support to update system state Date: Fri, 22 Sep 2023 23:20:49 +0530 [thread overview] Message-ID: <20230922175056.244940-9-Shyam-sundar.S-k@amd.com> (raw) In-Reply-To: <20230922175056.244940-1-Shyam-sundar.S-k@amd.com> 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. Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> --- Documentation/admin-guide/pmf.rst | 24 ++++++++++++++++ drivers/platform/x86/amd/pmf/pmf.h | 9 ++++++ drivers/platform/x86/amd/pmf/tee-if.c | 40 ++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/pmf.rst diff --git a/Documentation/admin-guide/pmf.rst b/Documentation/admin-guide/pmf.rst new file mode 100644 index 000000000000..b60f381410c3 --- /dev/null +++ b/Documentation/admin-guide/pmf.rst @@ -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}=="1", RUN+="/usr/bin/systemctl suspend" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="2", RUN+="/usr/bin/systemctl hibernate" + DRIVERS=="amd-pmf", ACTION=="change", ENV{EVENT_ID}=="3", RUN+="/bin/loginctl lock-sessions" + +EVENT_ID values: +1= Put the system to S0i3/S2Idle +2= Put the system to hibernate +3= Lock the screen + diff --git a/drivers/platform/x86/amd/pmf/pmf.h b/drivers/platform/x86/amd/pmf/pmf.h index 897f61b75e2f..c5334f1177a4 100644 --- a/drivers/platform/x86/amd/pmf/pmf.h +++ b/drivers/platform/x86/amd/pmf/pmf.h @@ -70,6 +70,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 */ @@ -436,6 +437,13 @@ struct apmf_dyn_slider_output { } __packed; /* Smart PC - TA internals */ +enum system_state { + SYSTEM_STATE__S0i3 = 1, + SYSTEM_STATE__S4, + SYSTEM_STATE__SCREEN_LOCK, + SYSTEM_STATE__MAX +}; + enum ta_slider { TA_BEST_BATTERY, /* Best Battery */ TA_BETTER_BATTERY, /* Better Battery */ @@ -467,6 +475,7 @@ enum ta_pmf_error_type { }; struct pmf_action_table { + enum system_state system_state; unsigned long spl; /* in mW */ unsigned long sppt; /* in mW */ unsigned long sppt_apuonly; /* in mW */ diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 883dd143375a..1629856c20b4 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -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,9 +56,23 @@ 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; + u32 val, event = 0; int idx; for (idx = 0; idx < out->actions_count; idx++) { @@ -113,6 +141,16 @@ 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: + event = val + 1; + if (dev->prev_data->system_state != event) { + amd_pmf_update_uevents(dev, event); + dev_dbg(dev->dev, "update SYSTEM_STATE : %s\n", + amd_pmf_uevent_as_str(event)); + dev->prev_data->system_state = 0; + } + break; } } } -- 2.25.1
next prev parent reply other threads:[~2023-09-22 17:52 UTC|newest] Thread overview: 127+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-22 17:50 [PATCH 00/15] Introduce PMF Smart PC Solution Builder Feature Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-22 17:50 ` [PATCH 01/15] platform/x86/amd/pmf: Add PMF TEE interface Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-26 16:42 ` Ilpo Järvinen 2023-09-26 16:42 ` Ilpo Järvinen 2023-09-26 16:42 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 02/15] platform/x86/amd/pmf: Add support PMF-TA interaction Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-26 16:48 ` Ilpo Järvinen 2023-09-26 16:48 ` Ilpo Järvinen 2023-09-26 16:48 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 03/15] platform/x86/amd/pmf: Change signature of amd_pmf_set_dram_addr Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-26 16:52 ` Ilpo Järvinen 2023-09-26 16:52 ` Ilpo Järvinen 2023-09-26 16:52 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 04/15] platform/x86/amd/pmf: Add support for PMF Policy Binary Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-22 18:51 ` Mario Limonciello 2023-09-22 18:51 ` Mario Limonciello 2023-09-30 3:55 ` Shyam Sundar S K 2023-09-30 3:55 ` Shyam Sundar S K 2023-09-26 17:05 ` Ilpo Järvinen 2023-09-26 17:05 ` Ilpo Järvinen 2023-09-26 17:05 ` Ilpo Järvinen 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 05/15] platform/x86/amd/pmf: change debugfs init sequence Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-26 16:53 ` Ilpo Järvinen 2023-09-26 16:53 ` Ilpo Järvinen 2023-09-26 16:53 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 06/15] platform/x86/amd/pmf: Add support to get inputs from other subsystems Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-26 17:08 ` Ilpo Järvinen 2023-09-26 17:08 ` Ilpo Järvinen 2023-09-26 17:08 ` Ilpo Järvinen 2023-09-30 8:40 ` Shyam Sundar S K 2023-09-30 8:40 ` Shyam Sundar S K 2023-09-30 8:40 ` Shyam Sundar S K 2023-10-02 9:10 ` Ilpo Järvinen 2023-10-02 9:10 ` Ilpo Järvinen 2023-10-02 9:10 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 07/15] platform/x86/amd/pmf: Add support update p3t limit Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-27 12:19 ` Ilpo Järvinen 2023-09-22 17:50 ` Shyam Sundar S K [this message] 2023-09-22 17:50 ` [PATCH 08/15] platform/x86/amd/pmf: Add support to update system state Shyam Sundar S K 2023-09-25 21:42 ` kernel test robot 2023-09-25 21:42 ` kernel test robot 2023-09-27 12:22 ` Ilpo Järvinen 2023-09-27 12:22 ` Ilpo Järvinen 2023-09-27 12:22 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 09/15] platform/x86/amd/pmf: Add facility to dump TA inputs Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-27 12:25 ` Ilpo Järvinen 2023-09-27 12:25 ` Ilpo Järvinen 2023-09-27 12:25 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 10/15] platform/x86/amd/pmf: Add capability to sideload of policy binary Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-25 2:14 ` kernel test robot 2023-09-25 2:14 ` kernel test robot 2023-09-27 12:33 ` Ilpo Järvinen 2023-09-27 12:33 ` Ilpo Järvinen 2023-09-27 12:33 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 11/15] platform/x86/amd/pmf: dump policy binary data Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-22 19:01 ` Mario Limonciello 2023-09-22 19:01 ` Mario Limonciello 2023-09-30 4:41 ` Shyam Sundar S K 2023-09-30 4:41 ` Shyam Sundar S K 2023-09-22 17:50 ` [PATCH 12/15] platform/x86/amd/pmf: Add PMF-AMDGPU get interface Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-27 12:54 ` Ilpo Järvinen 2023-09-27 12:54 ` Ilpo Järvinen 2023-09-27 12:54 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 13/15] platform/x86/amd/pmf: Add PMF-AMDGPU set interface Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-25 16:27 ` Deucher, Alexander 2023-09-25 16:27 ` Deucher, Alexander 2023-09-25 16:27 ` Deucher, Alexander 2023-09-25 16:30 ` Mario Limonciello 2023-09-25 16:30 ` Mario Limonciello 2023-09-26 11:17 ` Shyam Sundar S K 2023-09-26 11:17 ` Shyam Sundar S K 2023-09-26 11:15 ` Shyam Sundar S K 2023-09-26 11:15 ` Shyam Sundar S K 2023-09-26 10:35 ` Hans de Goede 2023-09-26 10:35 ` Hans de Goede 2023-09-26 11:24 ` Shyam Sundar S K 2023-09-26 11:24 ` Shyam Sundar S K 2023-09-26 12:56 ` Hans de Goede 2023-09-26 12:56 ` Hans de Goede 2023-09-26 13:17 ` Christian König 2023-09-26 13:17 ` Christian König 2023-09-26 13:48 ` Shyam Sundar S K 2023-09-26 13:48 ` Shyam Sundar S K 2023-09-27 13:04 ` Hans de Goede 2023-09-27 13:04 ` Hans de Goede 2023-09-27 13:47 ` Shyam Sundar S K 2023-09-27 13:47 ` Shyam Sundar S K 2023-09-27 13:36 ` Ilpo Järvinen 2023-09-27 13:36 ` Ilpo Järvinen 2023-09-27 13:36 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 14/15] platform/x86/amd/pmf: Add PMF-AMDSFH interface for HPD Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-22 19:04 ` Mario Limonciello 2023-09-22 19:04 ` Mario Limonciello 2023-09-22 21:04 ` Mario Limonciello 2023-09-22 21:04 ` Mario Limonciello 2023-09-27 13:32 ` Ilpo Järvinen 2023-09-27 13:32 ` Ilpo Järvinen 2023-09-27 13:32 ` Ilpo Järvinen 2023-09-22 17:50 ` [PATCH 15/15] platform/x86/amd/pmf: Add PMF-AMDSFH interface for ALS Shyam Sundar S K 2023-09-22 17:50 ` Shyam Sundar S K 2023-09-22 19:06 ` Mario Limonciello 2023-09-22 19:06 ` Mario Limonciello 2023-09-27 13:33 ` Ilpo Järvinen 2023-09-27 13:33 ` Ilpo Järvinen 2023-09-27 13:33 ` Ilpo Järvinen 2023-09-27 13:48 ` Shyam Sundar S K 2023-09-27 13:48 ` Shyam Sundar S K 2023-09-27 13:48 ` Shyam Sundar S K
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230922175056.244940-9-Shyam-sundar.S-k@amd.com \ --to=shyam-sundar.s-k@amd.com \ --cc=Patil.Reddy@amd.com \ --cc=Xinhui.Pan@amd.com \ --cc=airlied@gmail.com \ --cc=alexander.deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=basavaraj.natikar@amd.com \ --cc=benjamin.tissoires@redhat.com \ --cc=christian.koenig@amd.com \ --cc=daniel@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=hdegoede@redhat.com \ --cc=jikos@kernel.org \ --cc=linux-input@vger.kernel.org \ --cc=mario.limonciello@amd.com \ --cc=markgross@kernel.org \ --cc=platform-driver-x86@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.