lkml.org 
[lkml]   [2022]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 12/16] firmware: arm_scmi: Add Sensor notifications testing support
Date
Add a few debugfs entry to enable Sensor notifications support, namely
continuos sensor updates notifications and sensor trip point events
notifications.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
Documentation/ABI/testing/debugfs-scmi | 50 +++++++++
.../arm_scmi/scmi_test_driver/test_sensors.c | 104 +++++++++++++++++-
2 files changed, 153 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/debugfs-scmi b/Documentation/ABI/testing/debugfs-scmi
index 72835516dee8..8b3f9a12053d 100644
--- a/Documentation/ABI/testing/debugfs-scmi
+++ b/Documentation/ABI/testing/debugfs-scmi
@@ -217,3 +217,53 @@ Description: SCMI Sensor Protocol trip points configuration operation for
writing a base-10 integer value configure and enable trip point
<YYY> for sensor <XXX>.
Users: KSelftest, Debugging
+
+What: /sys/kernel/debug/scmi/protocol_0x15/<XXX>/sensor_update_notifs
+Date: Feb 2022
+KernelVersion: 5.19
+Contact: cristian.marussi@arm.com
+Description: A RW entry to support SENSOR_UPDATE notifications testing.
+ Writing a true value (Y/y/1) to this entry will trigger the
+ registration of a common notifier block for the SENSOR_UPDATE
+ notification as defined in SCMI Sensor Protocol: this common
+ notifier block starts collecting all the received notification
+ payload in a circular buffer.
+ The rate at which such notifications are emitted depends on the
+ specific update interval currently selected by the resource
+ at hand using the SENSOR_CONFIG command.
+ Note that, as per SCMI specification, the related sensor
+ resource <XXX> has also to be in an enabled state for the
+ notifications to be emitted by the platform.
+ Reading from this entry will return the latest content of the
+ above mentioned circular buffer.
+ Writing a false value (N/n/0) to this entry will cause the above
+ mentioned common notifier block to be unregistered and so
+ effectively the notification emission to be stopped.
+ When the notifier is unregistered the notification circular
+ buffer is cleared empty.
+ This entry is present only if the related resource <XXX> has
+ been advertised as supporting continuos updated notifications.
+Users: KSelftest, Debugging
+
+What: /sys/kernel/debug/scmi/protocol_0x15/<XXX>/sensor_trip_notifs
+Date: Feb 2022
+KernelVersion: 5.19
+Contact: cristian.marussi@arm.com
+Description: A RW entry to support SENSOR_TRIP_POINT_EVENT notifications
+ testing. Writing a true value (Y/y/1) to this entry will trigger
+ the registration of a common notifier block for
+ SENSOR_TRIP_POINT_EVENT notification as defined in SCMI Sensor
+ Protocol: this common notifier block starts collecting all the
+ received notification payload in a circular buffer.
+ Such notifications will be emitted once the related sensor
+ resource crosses one of the configured trip point: such trip
+ point can be cofigured using SENSOR_TRIP_POINT_CONFIG command
+ and related entries in the SCMI debugfs filesystem.
+ Reading from this entry will return the latest content of the
+ above mentioned circular buffer.
+ Writing a false value (N/n/0) to this entry will cause the above
+ mentioned common notifier block to be unregistered and so
+ effectively the notification emission to be stopped.
+ When the notifier is unregistered the notification circular
+ buffer is cleared empty.
+Users: KSelftest, Debugging
diff --git a/drivers/firmware/arm_scmi/scmi_test_driver/test_sensors.c b/drivers/firmware/arm_scmi/scmi_test_driver/test_sensors.c
index 23206c2bac98..2d610d84390f 100644
--- a/drivers/firmware/arm_scmi/scmi_test_driver/test_sensors.c
+++ b/drivers/firmware/arm_scmi/scmi_test_driver/test_sensors.c
@@ -284,6 +284,79 @@ static const struct file_operations test_sensor_trip_config_fops = {
.write = scmi_test_sensor_trip_config_write,
};

+static ssize_t scmi_test_sensor_updates_write(struct file *filp,
+ const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ bool enabled;
+ int ret;
+ u32 src_id;
+ struct scmi_test_setup *tsp = filp->f_inode->i_private;
+ struct scmi_test_buffer *data = filp->private_data;
+
+ if (!tsp || !data)
+ return count;
+
+ ret = kstrtobool_from_user(buf, count, &enabled);
+ if (ret)
+ return ret;
+
+ src_id = data->id;
+ ret = scmi_test_notif_manage(tsp, enabled,
+ SCMI_PROTOCOL_SENSOR,
+ SCMI_EVENT_SENSOR_UPDATE, &src_id,
+ sizeof(struct scmi_sensor_update_report),
+ scmi_test_generic_notif_cb);
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
+static const struct file_operations test_sensor_updates_fops_rw = {
+ .open = scmi_test_setup_open,
+ .release = scmi_test_release,
+ .read = scmi_test_notif_reports_read,
+ .write = scmi_test_sensor_updates_write,
+};
+
+static ssize_t scmi_test_sensor_trip_point_write(struct file *filp,
+ const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ bool enabled;
+ int ret;
+ u32 src_id;
+ struct scmi_test_setup *tsp = filp->f_inode->i_private;
+ struct scmi_test_buffer *data = filp->private_data;
+
+ if (!tsp || !data)
+ return count;
+
+ ret = kstrtobool_from_user(buf, count, &enabled);
+ if (ret)
+ return ret;
+
+ src_id = data->id;
+ ret = scmi_test_notif_manage(tsp, enabled,
+ SCMI_PROTOCOL_SENSOR,
+ SCMI_EVENT_SENSOR_TRIP_POINT_EVENT,
+ &src_id,
+ sizeof(struct scmi_sensor_trip_point_report),
+ scmi_test_generic_notif_cb);
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
+static const struct file_operations test_sensor_trips_fops_rw = {
+ .open = scmi_test_setup_open,
+ .release = scmi_test_release,
+ .read = scmi_test_notif_reports_read,
+ .write = scmi_test_sensor_trip_point_write,
+};
+
static void scmi_test_sensor_trips_debugfs(struct dentry *pdentry,
struct scmi_test_setup *tsp,
unsigned int num_points)
@@ -514,10 +587,39 @@ int scmi_test_sensor_init(struct scmi_test_setup *tsp)
sensor_dentry, tsp,
&test_sensor_config_fops_rw);

- if (sdata->sinfo[i]->num_trip_points)
+ if (sdata->sinfo[i]->update) {
+ struct scmi_test_setup *tsp_copy;
+
+ tsp_copy = scmi_test_tsp_shallow_copy(dev, tsp);
+ if (IS_ERR(tsp_copy))
+ return PTR_ERR(tsp_copy);
+
+ /* Bigger dedicated buffer for notifs */
+ tsp_copy->blen = 4096;
+ debugfs_create_file("sensor_update_notifs",
+ 0600, sensor_dentry,
+ tsp_copy,
+ &test_sensor_updates_fops_rw);
+ }
+
+ if (sdata->sinfo[i]->num_trip_points) {
+ struct scmi_test_setup *tsp_copy;
+
scmi_test_sensor_trips_debugfs(sensor_dentry,
tsp,
sdata->sinfo[i]->num_trip_points);
+
+ tsp_copy = scmi_test_tsp_shallow_copy(dev, tsp);
+ if (IS_ERR(tsp_copy))
+ return PTR_ERR(tsp_copy);
+
+ /* Bigger dedicated buffer for notifs */
+ tsp_copy->blen = 4096;
+ debugfs_create_file("sensor_trip_notifs",
+ 0600, sensor_dentry,
+ tsp_copy,
+ &test_sensor_trips_fops_rw);
+ }
}
}

--
2.17.1
\
 
 \ /
  Last update: 2022-02-27 21:57    [W:0.158 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site