From: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
To: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Cc: Sebastian Reichel <sre@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-pm@vger.kernel.org
Subject: Re: [PATCH 2/2] power: reset: reboot-mode: Expose sysfs for registered reboot_modes
Date: Mon, 17 Nov 2025 23:22:21 +0530 [thread overview]
Message-ID: <1c2963ff-fa1a-7e28-62bc-51bd2f6f3f5a@oss.qualcomm.com> (raw)
In-Reply-To: <CACMJSeu6BGS+AyEXyR9S7d6qGkbP3GiEzq6qy1860QaOQ-peQA@mail.gmail.com>
On 11/17/2025 6:55 PM, Bartosz Golaszewski wrote:
> On Sun, 16 Nov 2025 at 16:20, Shivendra Pratap
> <shivendra.pratap@oss.qualcomm.com> 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. Use
>> the driver_name field of the struct reboot_mode_driver to create the
>> device. For device-based drivers, configure the device driver name as
>> driver_name.
>>
>> 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.
>>
>> Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
>> ---
>> drivers/power/reset/reboot-mode.c | 72 +++++++++++++++++++++++++++++++++++++++
>> include/linux/reboot-mode.h | 3 ++
>> 2 files changed, 75 insertions(+)
>>
>> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
>> index fba53f638da04655e756b5f8b7d2d666d1379535..062df67735c4818cfeb894941e537f19ea9d4ccb 100644
>> --- a/drivers/power/reset/reboot-mode.c
>> +++ b/drivers/power/reset/reboot-mode.c
>> @@ -7,18 +7,77 @@
>> #include <linux/init.h>
>> #include <linux/kernel.h>
>> #include <linux/module.h>
>> +#include <linux/mutex.h>
>> #include <linux/of.h>
>> #include <linux/reboot.h>
>> #include <linux/reboot-mode.h>
>>
>> #define PREFIX "mode-"
>>
>> +static DEFINE_MUTEX(reboot_mode_mutex);
>> +
>> struct mode_info {
>> const char *mode;
>> u32 magic;
>> struct list_head list;
>> };
>>
>> +static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
>> +{
>> + struct reboot_mode_driver *reboot;
>> + struct mode_info *info;
>> + ssize_t size = 0;
>> +
>> + reboot = container_of(dev, struct reboot_mode_driver, reboot_mode_device);
>> + if (!reboot)
>> + return -ENODATA;
>> +
>> + list_for_each_entry(info, &reboot->head, list)
>> + size += sysfs_emit_at(buf, size, "%s ", info->mode);
>> +
>> + if (!size)
>> + return -ENODATA;
>> +
>> + return size + sysfs_emit_at(buf, size - 1, "\n");
>> +}
>> +static DEVICE_ATTR_RO(reboot_modes);
>> +
>> +static struct attribute *reboot_mode_attrs[] = {
>> + &dev_attr_reboot_modes.attr,
>> + NULL,
>> +};
>> +ATTRIBUTE_GROUPS(reboot_mode);
>> +
>> +static const struct class reboot_mode_class = {
>> + .name = "reboot-mode",
>> + .dev_groups = reboot_mode_groups,
>> +};
>> +
>> +static void reboot_mode_device_release(struct device *dev)
>> +{
>> + /* place holder to avoid warning on device_unregister. nothing to free */
>> +}
>> +
>> +static void reboot_mode_create_device(struct reboot_mode_driver *reboot)
>> +{
>> + static bool is_class_registered;
>> +
>> + reboot->reboot_mode_device_registered = false;
>> +
>> + scoped_guard(mutex, &reboot_mode_mutex) {
>> + if (!is_class_registered) {
>> + if (!class_register(&reboot_mode_class))
>> + is_class_registered = true;
>> + }
>> + }
>
> This could be achieved with DO_ONCE() but you still haven't explained
> why this needs to be done here. Why not in the module's
> subsys_initcall()? As of now, the class will not appear in sysfs until
> the first device is registered which isn't a very common behavior.
sure will add a subsys_initcall() and add it there.
thanks,
Shivendra
next prev parent reply other threads:[~2025-11-17 17:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-16 15:19 [PATCH 0/2] reboot-mode: Expose sysfs for registered reboot modes Shivendra Pratap
2025-11-16 15:19 ` [PATCH 1/2] Documentation: ABI: Add sysfs-class-reboot-mode-reboot_modes Shivendra Pratap
2025-11-16 17:44 ` Dmitry Baryshkov
2025-11-17 5:40 ` Shivendra Pratap
2025-11-17 20:48 ` Bjorn Andersson
2025-11-18 16:37 ` Shivendra Pratap
2025-11-19 3:22 ` Bjorn Andersson
2025-11-16 15:19 ` [PATCH 2/2] power: reset: reboot-mode: Expose sysfs for registered reboot_modes Shivendra Pratap
2025-11-17 13:25 ` Bartosz Golaszewski
2025-11-17 17:52 ` Shivendra Pratap [this message]
2025-11-17 13:03 ` [PATCH 0/2] reboot-mode: Expose sysfs for registered reboot modes Bartosz Golaszewski
2025-11-17 18:05 ` Shivendra Pratap
2025-11-18 10:00 ` Bartosz Golaszewski
2025-11-18 14:20 ` Shivendra Pratap
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=1c2963ff-fa1a-7e28-62bc-51bd2f6f3f5a@oss.qualcomm.com \
--to=shivendra.pratap@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@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: link
Be 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.