[PATCH v14 05/10] power: reset: reboot-mode: Expose sysfs for registered reboot_modes
Sebastian Reichel
sebastian.reichel at collabora.com
Tue Sep 16 12:02:41 PDT 2025
Hi,
On Fri, Aug 15, 2025 at 08:05:10PM +0530, Shivendra Pratap wrote:
> Currently, there is no standardized mechanism for userspace to
> discover which reboot-modes are supported on a given platform.
> This limitation forces tools and scripts to rely on hardcoded
> assumptions about the supported reboot-modes.
>
> Create a class 'reboot-mode' and a device under it to expose a
> sysfs interface to show the available reboot mode arguments to
> userspace.
>
> Provision the register function with an additional parameter to
> get an explicit driver_name. Create the device using this
> driver_name. For platform drivers, use the driver_name configured
> in dev node.
>
> This results in the creation of:
> /sys/class/reboot-mode/<driver>/reboot_modes
>
> This read-only sysfs file will exposes the list of supported
> reboot modes arguments provided by the driver, enabling userspace
> to query the list of arguments.
>
> Align the clean up path to maintain backward compatibility for
> existing reboot-mode based drivers.
>
> Signed-off-by: Shivendra Pratap <shivendra.pratap at oss.qualcomm.com>
> ---
> drivers/power/reset/reboot-mode.c | 131 +++++++++++++++++++++++++++++++-------
> include/linux/reboot-mode.h | 4 +-
> 2 files changed, 110 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
> index ac81b8b0a9b7fc31f8ef21024333a050087ce90f..7ecab050e496af3e1cc01c1a4614787707cb74b4 100644
> --- a/drivers/power/reset/reboot-mode.c
> +++ b/drivers/power/reset/reboot-mode.c
> @@ -6,6 +6,7 @@
> #define pr_fmt(fmt) "reboot-mode: " fmt
>
> #include <linux/device.h>
> +#include <linux/err.h>
> #include <linux/init.h>
> #include <linux/kernel.h>
> #include <linux/list.h>
> @@ -23,6 +24,8 @@ struct mode_info {
> struct list_head list;
> };
>
> +static struct class *rb_class;
> +
> static u64 get_reboot_mode_magic(struct reboot_mode_driver *reboot, const char *cmd)
> {
> const char *normal = "normal";
> @@ -75,26 +78,121 @@ static int reboot_mode_notify(struct notifier_block *this,
> return NOTIFY_DONE;
> }
>
> +static void release_reboot_mode_device(struct device *dev, void *res);
> +
> +static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct reboot_mode_driver **devres_reboot;
> + struct reboot_mode_driver *reboot;
> + struct mode_info *info;
> + ssize_t size = 0;
> +
> + devres_reboot = devres_find(dev, release_reboot_mode_device, NULL, NULL);
> + if (!devres_reboot || !(*devres_reboot))
> + return -ENODATA;
> +
> + reboot = *devres_reboot;
> + mutex_lock(&reboot->rb_lock);
> + list_for_each_entry(info, &reboot->head, list) {
> + size += sprintf(buf + size, "%s ", info->mode);
sysfs_emit_at
> + }
> + mutex_unlock(&reboot->rb_lock);
> +
> + if (size) {
> + size += sprintf(buf + size - 1, "\n");
sysfs_emit_at
> + return size;
> + }
> +
> + return -ENODATA;
> +}
> +static DEVICE_ATTR_RO(reboot_modes);
> +
> +static void release_reboot_mode_device(struct device *dev, void *res)
> +{
> + struct reboot_mode_driver *reboot = *(struct reboot_mode_driver **)res;
> + struct mode_info *info;
> + struct mode_info *next;
> +
> + unregister_reboot_notifier(&reboot->reboot_notifier);
> +
> + mutex_lock(&reboot->rb_lock);
> + list_for_each_entry_safe(info, next, &reboot->head, list) {
> + list_del(&info->list);
> + kfree_const(info->mode);
> + kfree(info);
> + }
> + mutex_unlock(&reboot->rb_lock);
> +
> + device_remove_file(reboot->reboot_dev, &dev_attr_reboot_modes);
> +}
> +
> +static int create_reboot_mode_device(struct reboot_mode_driver *reboot,
> + const char *dev_name)
Instead of adding more and more arguments to this, just add a name
field to struct reboot_mode_driver.
Greetings,
-- Sebastian
> [...]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20250916/91cfd6af/attachment.sig>
More information about the linux-arm-kernel
mailing list