mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 04/10] power: reset: reboot-mode: fix up node into boot device tree
Date: Mon, 28 Sep 2020 16:45:08 +0200	[thread overview]
Message-ID: <20200928144514.14398-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200928144514.14398-1-a.fatoum@pengutronix.de>

Instead of relying that the kernel and barebox device trees are in sync,
just enforce it by having barebox fix up the device tree node it probed
into the kernel device tree. We usually want that, but some reboot mode
drivers might want to inhibit the fixup, e.g. because they implement
a non-upstream binding or because they communicate with the BootROM,
while the kernel shouldn't. For those the fixup is made optional via
a struct reboot_mode_driver::no_fixup member.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/power/reset/reboot-mode.c | 43 +++++++++++++++++++++++++++++++
 include/linux/reboot-mode.h       |  1 +
 2 files changed, 44 insertions(+)

diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index 5992a2acd99a..bf51c00aee75 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -52,6 +52,46 @@ static int reboot_mode_add_param(struct device_d *dev,
 	return PTR_ERR_OR_ZERO(param);
 }
 
+static struct device_node *of_get_node_by_reproducible_name(struct device_node *dstroot,
+							    struct device_node *srcnp)
+{
+	struct device_node *dstnp;
+	char *name;
+
+	name = of_get_reproducible_name(srcnp);
+	dstnp = of_find_node_by_reproducible_name(dstroot, name);
+	free(name);
+
+	return dstnp;
+}
+
+static int of_reboot_mode_fixup(struct device_node *root, void *ctx)
+{
+	struct reboot_mode_driver *reboot = ctx;
+	struct device_node *dstnp, *srcnp, *dstparent;
+
+	srcnp = reboot->dev->device_node;
+	dstnp = of_get_node_by_reproducible_name(root, srcnp);
+
+	/* nothing to do when called on barebox-internal tree */
+	if (srcnp == dstnp)
+		return 0;
+
+	if (dstnp) {
+		dstparent = dstnp->parent;
+		of_delete_node(dstnp);
+	} else {
+		dstparent = of_get_node_by_reproducible_name(root, srcnp->parent);
+	}
+
+	if (!dstparent)
+		return -EINVAL;
+
+	of_copy_node(dstparent, srcnp);
+
+	return 0;
+}
+
 static int reboot_mode_add_globalvar(void)
 {
 	struct reboot_mode_driver *reboot = __boot_mode;
@@ -59,6 +99,9 @@ static int reboot_mode_add_globalvar(void)
 	if (!reboot)
 		return 0;
 
+	if (!reboot->no_fixup)
+		of_register_fixup(of_reboot_mode_fixup, reboot);
+
 	return reboot_mode_add_param(&global_device, "system.reboot_mode.", reboot);
 }
 late_initcall(reboot_mode_add_globalvar);
diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
index 92a1da7b5562..bc57f1d72df7 100644
--- a/include/linux/reboot-mode.h
+++ b/include/linux/reboot-mode.h
@@ -11,6 +11,7 @@ struct reboot_mode_driver {
 	struct device_d *dev;
 	int (*write)(struct reboot_mode_driver *reboot, u32 magic);
 	int priority;
+	bool no_fixup;
 
 	/* filled by reboot_mode_register */
 	int reboot_mode_prev, reboot_mode_next;
-- 
2.28.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-09-28 14:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 14:45 [PATCH v2 00/10] power: reset: add support for syscon reboot Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 01/10] usbgadget: autostart: support delayed usbgadget.autostart=1 Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 02/10] drivers: add reboot-mode infrastructure Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 03/10] power: reset: reboot-mode: port syscon-reboot-mode support Ahmad Fatoum
2020-09-28 14:45 ` Ahmad Fatoum [this message]
2020-09-28 14:45 ` [PATCH v2 05/10] defaultenv: provide defaults for generic reboot modes Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 06/10] ARM: dts: stm32mp: setup syscon-reboot-mode on TAMP general purpose register Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 07/10] ARM: stm32mp: remove custom reboot mode logic from arch code Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 08/10] power: reset: reboot-mode: support multi-word magic Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 09/10] power: reset: syscon-reboot-mode: support multi-word reboot modes Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 10/10] ARM: dts: i.MX6qdl: define BootROM reboot-mode on top of SRC_GPR{9, 10} Ahmad Fatoum
2020-09-29  8:25 ` [PATCH v2 00/10] power: reset: add support for syscon reboot Sascha Hauer

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=20200928144514.14398-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox