All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>,
	 Arnd Bergmann <arnd@arndb.de>,
	Bjorn Andersson <andersson@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Souvik Chakravarty <Souvik.Chakravarty@arm.com>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	 Mark Rutland <mark.rutland@arm.com>,
	Conor Dooley <conor+dt@kernel.org>,
	 Konrad Dybcio <konradybcio@kernel.org>,
	John Stultz <john.stultz@linaro.org>,
	 Moritz Fischer <moritz.fischer@ettus.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	 Daniel Lezcano <daniel.lezcano@kernel.org>,
	Christian Loehle <christian.loehle@arm.com>,
	 Lee Jones <lee@kernel.org>, Ulf Hansson <ulfh@kernel.org>,
	 Pavan Kondeti <pavan.kondeti@oss.qualcomm.com>,
	Abel Vesa <abelvesa@kernel.org>,
	 Bartosz Golaszewski <brgl@kernel.org>,
	Sudeep Holla <sudeep.holla@kernel.org>,
	 Andy Yan <andyshrk@163.com>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	 Krzysztof Kozlowski <krzk@kernel.org>,
	Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
	 Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>,
	Andre Draszik <andre.draszik@linaro.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Kathiravan Thirumoorthy
	<kathiravan.thirumoorthy@oss.qualcomm.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
	 Srinivas Kandagatla <srini@kernel.org>
Subject: Re: [PATCH v27 02/10] power: reset: reboot-mode: Add support for predefined reboot modes
Date: Mon, 16 Nov 2026 00:13:02 +0100	[thread overview]
Message-ID: <avo7dUvBvULHCOY1@venus> (raw)
In-Reply-To: <20261029-arm-psci-system_reset2-vendor-reboots-v27-2-fa4b3ff1359b@oss.qualcomm.com>

[-- Attachment #1: Type: text/plain, Size: 13494 bytes --]

Hi,

On Thu, Oct 29, 2026 at 02:30:56PM +0530, Shivendra Pratap wrote:
> reboot-mode based drivers can define a reboot-mode by adding it under
> the reboot-mode node in device tree. This limits such drivers, to define
> any predefined reboot-modes statically within the driver and creates a
> dependency on device-tree.
> 
> Extend the reboot-mode framework to support driver-defined predefined
> reboot modes. Add a centralized initcall to initialize driver state
> along with predefined modes.
> 
> Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
> ---
>  drivers/power/reset/nvmem-reboot-mode.c  |   7 +-
>  drivers/power/reset/qcom-pon.c           |   7 +-
>  drivers/power/reset/reboot-mode.c        | 192 ++++++++++++++++++++++---------
>  drivers/power/reset/syscon-reboot-mode.c |   7 +-
>  include/linux/reboot-mode.h              |  26 ++++-
>  5 files changed, 175 insertions(+), 64 deletions(-)
> 
> diff --git a/drivers/power/reset/nvmem-reboot-mode.c b/drivers/power/reset/nvmem-reboot-mode.c
> index d260715fccf6..700732ed0f5b 100644
> --- a/drivers/power/reset/nvmem-reboot-mode.c
> +++ b/drivers/power/reset/nvmem-reboot-mode.c
> @@ -51,8 +51,11 @@ static int nvmem_reboot_mode_probe(struct platform_device *pdev)
>  	if (!nvmem_rbm)
>  		return -ENOMEM;
>  
> -	nvmem_rbm->reboot.dev = &pdev->dev;
> -	nvmem_rbm->reboot.write = nvmem_reboot_mode_write;
> +	ret = reboot_mode_driver_init(&nvmem_rbm->reboot, &pdev->dev,
> +				      nvmem_reboot_mode_write, NULL,
> +				      NULL, 0);
> +	if (ret)
> +		return ret;
>  
>  	nvmem_rbm->cell = devm_nvmem_cell_get(&pdev->dev, "reboot-mode");
>  	if (IS_ERR(nvmem_rbm->cell)) {
> diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c
> index cd7ba680b841..55aaa99d88b6 100644
> --- a/drivers/power/reset/qcom-pon.c
> +++ b/drivers/power/reset/qcom-pon.c
> @@ -84,9 +84,12 @@ static int qcom_pon_probe(struct platform_device *pdev)
>  	reason_shift = (long)of_device_get_match_data(&pdev->dev);
>  
>  	if (reason_shift != NO_REASON_SHIFT) {
> -		pon->reboot_mode.dev = &pdev->dev;
> +		error = reboot_mode_driver_init(&pon->reboot_mode, &pdev->dev,
> +						qcom_pon_reboot_mode_write, NULL,
> +						NULL, 0);
> +		if (error)
> +			return error;
>  		pon->reason_shift = reason_shift;
> -		pon->reboot_mode.write = qcom_pon_reboot_mode_write;
>  		error = devm_reboot_mode_register(&pdev->dev, &pon->reboot_mode);
>  		if (error) {
>  			dev_err(&pdev->dev, "can't register reboot mode\n");
> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
> index 328fa37598df..fd61de226383 100644
> --- a/drivers/power/reset/reboot-mode.c
> +++ b/drivers/power/reset/reboot-mode.c
> @@ -30,12 +30,12 @@ struct reboot_mode_sysfs_data {
>  	struct list_head head;
>  };
>  
> -static inline void reboot_mode_release_list(struct reboot_mode_sysfs_data *priv)
> +static void reboot_mode_release_list(struct list_head *head)
>  {
>  	struct mode_info *info;
>  	struct mode_info *next;
>  
> -	list_for_each_entry_safe(info, next, &priv->head, list) {
> +	list_for_each_entry_safe(info, next, head, list) {
>  		list_del(&info->list);
>  		kfree_const(info->mode);
>  		kfree(info);
> @@ -119,6 +119,80 @@ static int reboot_mode_notify(struct notifier_block *this,
>  	return NOTIFY_DONE;
>  }
>  
> +/**
> + * reboot_mode_driver_init - Initialize reboot-mode state
> + * @reboot: reboot mode driver object to initialize
> + * @dev: backing device
> + * @write: write callback to program a single magic value
> + * @write_array: write callback to program multiple magic values
> + * @predefined_modes: optional predefined reboot-mode table
> + * @predefined_mode_count: number of entries in @predefined_modes
> + *
> + * Exactly one write callback must be provided by the driver.
> + *
> + * This function must be called with a valid @dev before calling
> + * reboot_mode_register().
> + *
> + * Returns: 0 on success or -EINVAL if callback/predefined mode configuration
> + * is invalid.
> + */
> +int reboot_mode_driver_init(struct reboot_mode_driver *reboot,
> +			    struct device *dev,
> +			    int (*write)(struct reboot_mode_driver *reboot, unsigned int magic),
> +			    int (*write_array)(struct reboot_mode_driver *reboot,
> +					       const u32 *magic, u32 count),
> +			    const struct reboot_mode_entry *predefined_modes,
> +			    size_t predefined_mode_count)
> +{
> +	if (!reboot || !dev)
> +		return -EINVAL;
> +
> +	if (!write == !write_array)
> +		return -EINVAL;
> +
> +	memset(reboot, 0, sizeof(*reboot));
> +	reboot->dev = dev;
> +	reboot->write = write;
> +	reboot->write_array = write_array;
> +	reboot->predefined_modes = predefined_modes;
> +	reboot->predefined_mode_count = predefined_mode_count;
> +	INIT_LIST_HEAD(&reboot->head);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(reboot_mode_driver_init);
> +
> +static struct mode_info *reboot_mode_create_info(struct device *dev, const char *mode,
> +						 const u32 *magic, int count)
> +{
> +	struct mode_info *info;
> +
> +	if (!mode || mode[0] == '\0') {
> +		dev_err(dev, "invalid mode name\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	info = kzalloc_obj(*info, GFP_KERNEL);
> +	if (!info)
> +		return ERR_PTR(-ENOMEM);

info = kzalloc_obj(*info);

Otherwise:

Acked-by: Sebastian Reichel <sebastian@collabora.com>

Greetings,

-- Sebastian

> +
> +	info->mode = kstrdup_const(mode, GFP_KERNEL);
> +	if (!info->mode) {
> +		kfree(info);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	if (!memchr_inv(magic, 0, count * sizeof(u32))) {
> +		dev_dbg(dev, "reboot mode %s with zero magic values\n", mode);
> +		info->count = 0;
> +	} else {
> +		memcpy(info->magic, magic, count * sizeof(u32));
> +		info->count = count;
> +	}
> +
> +	return info;
> +}
> +
>  static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
>  {
>  	struct reboot_mode_sysfs_data *priv;
> @@ -160,11 +234,38 @@ static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
>  	return 0;
>  
>  error:
> -	reboot_mode_release_list(priv);
> +	reboot_mode_release_list(&priv->head);
>  	kfree(priv);
>  	return ret;
>  }
>  
> +static int reboot_mode_add_predefined_modes(struct reboot_mode_driver *reboot)
> +{
> +	const struct reboot_mode_entry *modes = reboot->predefined_modes;
> +	struct mode_info *info;
> +	size_t i;
> +
> +	if (!modes)
> +		return 0;
> +
> +	for (i = 0; i < reboot->predefined_mode_count; i++) {
> +		if (modes[i].name && strpbrk(modes[i].name, "\n ,/"))
> +			return -EINVAL;
> +
> +		if (!modes[i].count || modes[i].count > ARRAY_SIZE(modes[i].magic))
> +			return -EINVAL;
> +
> +		info = reboot_mode_create_info(reboot->dev, modes[i].name,
> +					       modes[i].magic, modes[i].count);
> +		if (IS_ERR(info))
> +			return PTR_ERR(info);
> +
> +		list_add_tail(&info->list, &reboot->head);
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * reboot_mode_register - register a reboot mode driver
>   * @reboot: reboot mode driver
> @@ -173,7 +274,7 @@ static int reboot_mode_create_device(struct reboot_mode_driver *reboot)
>   */
>  int reboot_mode_register(struct reboot_mode_driver *reboot)
>  {
> -	struct mode_info *info = NULL;
> +	struct mode_info *info;
>  	struct property *prop;
>  	struct device_node *np = reboot->dev->of_node;
>  	size_t len = strlen(PREFIX);
> @@ -183,52 +284,36 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>  
>  	INIT_LIST_HEAD(&reboot->head);
>  
> -	for_each_property_of_node(np, prop) {
> -		memset(magic, 0, sizeof(magic));
> -
> -		if (strncmp(prop->name, PREFIX, len))
> -			continue;
> -
> -		count = device_property_count_u32(reboot->dev, prop->name);
> -
> -		if (count <= 0 || count > ARRAY_SIZE(magic) ||
> -		    device_property_read_u32_array(reboot->dev, prop->name, magic, count)) {
> -			dev_dbg(reboot->dev, "reboot mode %s without magic number\n",
> -				prop->name);
> -			continue;
> -		}
> -
> -		info = kzalloc_obj(*info);
> -		if (!info) {
> -			ret = -ENOMEM;
> -			goto error;
> -		}
> -
> -		if (!memchr_inv(magic, 0, count * sizeof(u32))) {
> -			dev_dbg(reboot->dev, "reboot mode %s with zero magic values\n",
> -				prop->name);
> -			info->count = 0;
> -		} else {
> -			memcpy(info->magic, magic, count * sizeof(u32));
> -			info->count = count;
> -		}
> -
> -		info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
> -		if (!info->mode) {
> -			ret = -ENOMEM;
> -			goto error;
> -		} else if (info->mode[0] == '\0') {
> -			kfree_const(info->mode);
> -			ret = -EINVAL;
> -			dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
> -				prop->name);
> -			goto error;
> +	if (np) {
> +		for_each_property_of_node(np, prop) {
> +			memset(magic, 0, sizeof(magic));
> +			if (strncmp(prop->name, PREFIX, len))
> +				continue;
> +
> +			count = device_property_count_u32(reboot->dev, prop->name);
> +
> +			if (count <= 0 || count > ARRAY_SIZE(magic) ||
> +			    device_property_read_u32_array(reboot->dev, prop->name, magic, count)) {
> +				dev_dbg(reboot->dev, "reboot mode %s without magic number\n",
> +					prop->name);
> +				continue;
> +			}
> +
> +			info = reboot_mode_create_info(reboot->dev, prop->name + len,
> +						       magic, count);
> +			if (IS_ERR(info)) {
> +				ret = PTR_ERR(info);
> +				goto error;
> +			}
> +
> +			list_add_tail(&info->list, &reboot->head);
>  		}
> -
> -		list_add_tail(&info->list, &reboot->head);
> -		info = NULL;
>  	}
>  
> +	ret = reboot_mode_add_predefined_modes(reboot);
> +	if (ret)
> +		goto error;
> +
>  	reboot->reboot_notifier.notifier_call = reboot_mode_notify;
>  	register_reboot_notifier(&reboot->reboot_notifier);
>  
> @@ -239,7 +324,6 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>  	return 0;
>  
>  error:
> -	kfree(info);
>  	reboot_mode_unregister(reboot);
>  	return ret;
>  }
> @@ -272,7 +356,7 @@ static inline void reboot_mode_unregister_device(struct reboot_mode_driver *rebo
>  	if (!priv)
>  		return;
>  
> -	reboot_mode_release_list(priv);
> +	reboot_mode_release_list(&priv->head);
>  	kfree(priv);
>  }
>  
> @@ -282,17 +366,11 @@ static inline void reboot_mode_unregister_device(struct reboot_mode_driver *rebo
>   */
>  int reboot_mode_unregister(struct reboot_mode_driver *reboot)
>  {
> -	struct mode_info *info;
> -	struct mode_info *next;
> -
>  	unregister_reboot_notifier(&reboot->reboot_notifier);
> +	reboot->reboot_notifier.notifier_call = NULL;
>  	reboot_mode_unregister_device(reboot);
>  
> -	list_for_each_entry_safe(info, next, &reboot->head, list) {
> -		list_del(&info->list);
> -		kfree_const(info->mode);
> -		kfree(info);
> -	}
> +	reboot_mode_release_list(&reboot->head);
>  
>  	return 0;
>  }
> diff --git a/drivers/power/reset/syscon-reboot-mode.c b/drivers/power/reset/syscon-reboot-mode.c
> index e0772c9f70f7..7d3a95e8dfd7 100644
> --- a/drivers/power/reset/syscon-reboot-mode.c
> +++ b/drivers/power/reset/syscon-reboot-mode.c
> @@ -45,8 +45,11 @@ static int syscon_reboot_mode_probe(struct platform_device *pdev)
>  	if (!syscon_rbm)
>  		return -ENOMEM;
>  
> -	syscon_rbm->reboot.dev = &pdev->dev;
> -	syscon_rbm->reboot.write = syscon_reboot_mode_write;
> +	ret = reboot_mode_driver_init(&syscon_rbm->reboot, &pdev->dev,
> +				      syscon_reboot_mode_write, NULL,
> +				      NULL, 0);
> +	if (ret)
> +		return ret;
>  	syscon_rbm->mask = 0xffffffff;
>  
>  	syscon_rbm->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
> diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
> index 29ae39935d69..560d8b4d67ac 100644
> --- a/include/linux/reboot-mode.h
> +++ b/include/linux/reboot-mode.h
> @@ -4,14 +4,38 @@
>  
>  #include <linux/types.h>
>  
> +struct reboot_mode_entry {
> +	const char *name;
> +	u32 magic[3];
> +	u32 count;
> +};
> +
>  struct reboot_mode_driver {
>  	struct device *dev;
>  	struct list_head head;
> +	/*
> +	 * Optional predefined reboot-mode table.
> +	 *
> +	 * Must be initialized before reboot_mode_register() and remain valid
> +	 * until reboot_mode_unregister().
> +	 *
> +	 * If a predefined mode name duplicates a DT-defined mode name,
> +	 * the DT-defined mode takes precedence.
> +	 */
> +	const struct reboot_mode_entry *predefined_modes;
> +	size_t predefined_mode_count;
> +	int (*write_array)(struct reboot_mode_driver *reboot, const u32 *magic, u32 count);
>  	int (*write)(struct reboot_mode_driver *reboot, unsigned int magic);
> -	int (*write_array)(struct reboot_mode_driver *reboot, const u32 *magic, int count);
>  	struct notifier_block reboot_notifier;
>  };
>  
> +int reboot_mode_driver_init(struct reboot_mode_driver *reboot,
> +			    struct device *dev,
> +			    int (*write)(struct reboot_mode_driver *reboot, unsigned int magic),
> +			    int (*write_array)(struct reboot_mode_driver *reboot,
> +					       const u32 *magic, u32 count),
> +			    const struct reboot_mode_entry *predefined_modes,
> +			    size_t predefined_mode_count);
>  int reboot_mode_register(struct reboot_mode_driver *reboot);
>  int reboot_mode_unregister(struct reboot_mode_driver *reboot);
>  int devm_reboot_mode_register(struct device *dev,
> 
> -- 
> 2.34.1
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2026-11-16  6:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29  9:00 [PATCH v27 00/10] Implement PSCI reboot mode driver for PSCI resets Shivendra Pratap
2026-10-29  9:00 ` [PATCH v27 01/10] power: reset: reboot-mode: Support up to 3 magic values per mode Shivendra Pratap
2026-11-15 23:08   ` Sebastian Reichel
2026-10-29  9:00 ` [PATCH v27 02/10] power: reset: reboot-mode: Add support for predefined reboot modes Shivendra Pratap
2026-10-29  9:23   ` sashiko-bot
2026-11-15 23:13   ` Sebastian Reichel [this message]
2026-10-29  9:00 ` [PATCH v27 03/10] firmware: psci: Introduce command-based resets Shivendra Pratap
2026-10-29  9:00 ` [PATCH v27 04/10] firmware: psci: Add support for PSCI auxiliary devices Shivendra Pratap
2026-10-29 10:00   ` sashiko-bot
2026-10-29  9:00 ` [PATCH v27 05/10] dt-bindings: arm: Document reboot mode magic Shivendra Pratap
2026-11-02  9:40   ` Bartosz Golaszewski
2026-11-17 13:45   ` Bartosz Golaszewski
2026-10-29  9:01 ` [PATCH v27 06/10] power: reset: Add psci-reboot-mode driver Shivendra Pratap
2026-11-15 23:08   ` Sebastian Reichel
2026-10-29  9:01 ` [PATCH v27 07/10] arm64: dts: qcom: Add psci reboot-modes for kodiak boards Shivendra Pratap
2026-10-29 10:23   ` Abel Vesa
2026-10-29  9:01 ` [PATCH v27 08/10] arm64: dts: qcom: Add psci reboot-modes for lemans boards Shivendra Pratap
2026-10-29 10:23   ` Abel Vesa
2026-10-29  9:01 ` [PATCH v27 09/10] arm64: dts: qcom: Add psci reboot-modes for monaco boards Shivendra Pratap
2026-10-29 10:24   ` Abel Vesa
2026-10-29  9:01 ` [PATCH v27 10/10] arm64: dts: qcom: Add psci reboot-modes for talos boards Shivendra Pratap
2026-10-29 10:24   ` Abel Vesa
2026-11-09 15:47 ` [PATCH v27 00/10] Implement PSCI reboot mode driver for PSCI resets Ulf Hansson
2026-11-15 23:14   ` Sebastian Reichel

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=avo7dUvBvULHCOY1@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=Souvik.Chakravarty@arm.com \
    --cc=abelvesa@kernel.org \
    --cc=andersson@kernel.org \
    --cc=andre.draszik@linaro.org \
    --cc=andyshrk@163.com \
    --cc=arnd@arndb.de \
    --cc=brgl@kernel.org \
    --cc=christian.loehle@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.stultz@linaro.org \
    --cc=kathiravan.thirumoorthy@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=krzk@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=moritz.fischer@ettus.com \
    --cc=mukesh.ojha@oss.qualcomm.com \
    --cc=pavan.kondeti@oss.qualcomm.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=shivendra.pratap@oss.qualcomm.com \
    --cc=srini@kernel.org \
    --cc=sudeep.holla@kernel.org \
    --cc=ulfh@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.