Skip to content

Commit 4c92d44

Browse files
Shyam Sundar S Kij-intel
authored andcommitted
platform/x86/amd/pmf: Use existing input event codes to update system states
At present, the PMF driver employs custom system state codes to update system states. It is recommended to replace these with existing input event codes (KEY_SLEEP, KEY_SUSPEND, and KEY_SCREENLOCK) to align system updates with the PMF-TA output actions. 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 d234302 commit 4c92d44

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define PMF_H
1313

1414
#include <linux/acpi.h>
15+
#include <linux/input.h>
1516
#include <linux/platform_profile.h>
1617

1718
#define POLICY_BUF_MAX_SZ 0x4b000
@@ -300,6 +301,7 @@ struct amd_pmf_dev {
300301
void __iomem *policy_base;
301302
bool smart_pc_enabled;
302303
u16 pmf_if_version;
304+
struct input_dev *pmf_idev;
303305
};
304306

305307
struct apmf_sps_prop_granular_v2 {

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

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,12 @@ static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,
6262
param[0].u.memref.shm_offs = 0;
6363
}
6464

65-
static int amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
65+
static void amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event)
6666
{
67-
char *envp[2] = {};
68-
69-
envp[0] = kasprintf(GFP_KERNEL, "EVENT_ID=%d", event);
70-
if (!envp[0])
71-
return -EINVAL;
72-
73-
kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, envp);
74-
75-
kfree(envp[0]);
76-
return 0;
67+
input_report_key(dev->pmf_idev, event, 1); /* key press */
68+
input_sync(dev->pmf_idev);
69+
input_report_key(dev->pmf_idev, event, 0); /* key release */
70+
input_sync(dev->pmf_idev);
7771
}
7872

7973
static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out)
@@ -149,7 +143,20 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
149143
break;
150144

151145
case PMF_POLICY_SYSTEM_STATE:
152-
amd_pmf_update_uevents(dev, val);
146+
switch (val) {
147+
case 0:
148+
amd_pmf_update_uevents(dev, KEY_SLEEP);
149+
break;
150+
case 1:
151+
amd_pmf_update_uevents(dev, KEY_SUSPEND);
152+
break;
153+
case 2:
154+
amd_pmf_update_uevents(dev, KEY_SCREENLOCK);
155+
break;
156+
default:
157+
dev_err(dev->dev, "Invalid PMF policy system state: %d\n", val);
158+
}
159+
153160
dev_dbg(dev->dev, "update SYSTEM_STATE: %s\n",
154161
amd_pmf_uevent_as_str(val));
155162
break;
@@ -363,6 +370,30 @@ static int amd_pmf_ta_open_session(struct tee_context *ctx, u32 *id)
363370
return rc;
364371
}
365372

373+
static int amd_pmf_register_input_device(struct amd_pmf_dev *dev)
374+
{
375+
int err;
376+
377+
dev->pmf_idev = devm_input_allocate_device(dev->dev);
378+
if (!dev->pmf_idev)
379+
return -ENOMEM;
380+
381+
dev->pmf_idev->name = "PMF-TA output events";
382+
dev->pmf_idev->phys = "amd-pmf/input0";
383+
384+
input_set_capability(dev->pmf_idev, EV_KEY, KEY_SLEEP);
385+
input_set_capability(dev->pmf_idev, EV_KEY, KEY_SCREENLOCK);
386+
input_set_capability(dev->pmf_idev, EV_KEY, KEY_SUSPEND);
387+
388+
err = input_register_device(dev->pmf_idev);
389+
if (err) {
390+
dev_err(dev->dev, "Failed to register input device: %d\n", err);
391+
return err;
392+
}
393+
394+
return 0;
395+
}
396+
366397
static int amd_pmf_tee_init(struct amd_pmf_dev *dev)
367398
{
368399
u32 size;
@@ -470,6 +501,10 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)
470501
if (pb_side_load)
471502
amd_pmf_open_pb(dev, dev->dbgfs_dir);
472503

504+
ret = amd_pmf_register_input_device(dev);
505+
if (ret)
506+
goto error;
507+
473508
return 0;
474509

475510
error:
@@ -480,6 +515,9 @@ int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev)
480515

481516
void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev)
482517
{
518+
if (dev->pmf_idev)
519+
input_unregister_device(dev->pmf_idev);
520+
483521
if (pb_side_load && dev->esbin)
484522
amd_pmf_remove_pb(dev);
485523

0 commit comments

Comments
 (0)