From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v2 2/5] common: deep-probe: support specifying support in DT
Date: Mon, 2 Jun 2025 11:57:35 +0200 [thread overview]
Message-ID: <20250602095738.822334-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250602095738.822334-1-a.fatoum@barebox.org>
New boards should be deep probe enabled by default, which is currently
done via board code. We want to support second stage boot on new boards
without board code however, which means we need the possibility to make
deep probe opt-out instead of opt-in.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
v1 -> v2:
- add two comments to the functions as suggested by Marco
---
.../bindings/barebox/barebox,deep-probe.rst | 39 +++++++++++++++
common/deep-probe.c | 49 +++++++++++++++++--
drivers/base/Kconfig | 22 +++++++++
3 files changed, 106 insertions(+), 4 deletions(-)
create mode 100644 Documentation/devicetree/bindings/barebox/barebox,deep-probe.rst
diff --git a/Documentation/devicetree/bindings/barebox/barebox,deep-probe.rst b/Documentation/devicetree/bindings/barebox/barebox,deep-probe.rst
new file mode 100644
index 000000000000..8868fce7f3d8
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox/barebox,deep-probe.rst
@@ -0,0 +1,39 @@
+barebox deep probe properties
+=============================
+
+A ``barebox,deep-probe`` property in the top-level node indicates to barebox
+that the barebox board and device drivers support recursively probing devices
+on demand (deep probe).
+
+For drivers to support deep probe, they must not rely on initcall ordering.
+Resources needed by drivers should be referenced via device tree, e.g.,
+instead of direct use of hardcoded GPIO numbers, GPIOs must either be:
+
+* described in the device's device tree node and requested using API that
+ that takes the device or the device tree node as argument
+
+* probe of the GPIO controller be ensured via ``of_device_ensure_probed``,
+ e.g., ``of_devices_ensure_probed_by_property("gpio-controller");``
+
+The inverted flag is ``barebox,disable-deep-probe``, which means that the
+board is not deep probe capable (or tested) yet.
+
+The ``barebox,disable-deep-probe`` property takes precedence over
+``barebox,deep-probe``, but not over ``BAREBOX_DEEP_PROBE_ENABLE``
+in the board code.
+
+If neither property exists, the default deep probe behavior depends on
+the ``CONFIG_DEEP_PROBE_DEFAULT`` variable.
+
+.. code-block:: none
+
+ / { /* SoM Device Tree */
+ barebox,deep-probe;
+ };
+
+ / { /* Board Device Tree */
+ /* FIXME: While the SoM supports deep probe, our board code is broken
+ * currently, so override until it's fixed
+ */
+ barebox,disable-deep-probe;
+ };
diff --git a/common/deep-probe.c b/common/deep-probe.c
index ab1da87b626b..f4685cdf6e6c 100644
--- a/common/deep-probe.c
+++ b/common/deep-probe.c
@@ -20,12 +20,23 @@ static enum deep_probe_state boardstate = DEEP_PROBE_UNKNOWN;
bool deep_probe_is_supported(void)
{
+ bool deep_probe_default = IS_ENABLED(CONFIG_DEEP_PROBE_DEFAULT);
struct deep_probe_entry *board;
+ struct device_node *root;
if (boardstate > DEEP_PROBE_UNKNOWN)
return boardstate;
- /* determine boardstate */
+ /*
+ * Deep probe requires resources to be described in DT.
+ * We intentionally omit setting boardstate here on the
+ * off-chance that this function is called too early.
+ */
+ root = of_get_root_node();
+ if (!root)
+ return false;
+
+ /* determine boardstate according to BAREBOX_DEEP_PROBE_ENABLE */
for (board = __barebox_deep_probe_start;
board != __barebox_deep_probe_end; board++) {
const struct of_device_id *matches = board->device_id;
@@ -39,8 +50,38 @@ bool deep_probe_is_supported(void)
}
}
- boardstate = DEEP_PROBE_NOT_SUPPORTED;
- pr_info("not activated\n");
- return false;
+ /*
+ * Deep probe used to be opt-in. As we want all new board support
+ * to make use of it, we add a config option to make it opt-out and
+ * start emitting a warning for boards that are undecided:
+ *
+ * - Boards that don't support deep probe should explicitly opt-out
+ * using barebox,disable-deep-probe in their device tree.
+ *
+ * - Boards that support deep probe can indicate so using
+ * barebox,deep-probe if there is no BAREBOX_DEEP_PROBE_ENABLE
+ * already.
+ *
+ * - New boards without board code will default to deep-probe enabled,
+ * because CONFIG_DEEP_PROBE_DEFAULT=y would be set in the defconfigs.
+ *
+ * Refer to barebox,deep-probe.rst for more information.
+ */
+ if (of_property_read_bool(root, "barebox,disable-deep-probe")) {
+ boardstate = DEEP_PROBE_NOT_SUPPORTED;
+ pr_info("disabled in device tree\n");
+ } else if (of_property_read_bool(root, "barebox,deep-probe")) {
+ boardstate = DEEP_PROBE_SUPPORTED;
+ pr_debug("enabled in device tree\n");
+ } else if (deep_probe_default) {
+ boardstate = DEEP_PROBE_SUPPORTED;
+ pr_debug("activated by default\n");
+ } else {
+ boardstate = DEEP_PROBE_NOT_SUPPORTED;
+ pr_warn("DT missing barebox,deep-probe or barebox,disable-deep-probe property\n");
+ pr_info("not activated by default\n");
+ }
+
+ return boardstate;
}
EXPORT_SYMBOL_GPL(deep_probe_is_supported);
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 21a4793cfa47..5766e2afda9a 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -1,5 +1,27 @@
# SPDX-License-Identifier: GPL-2.0-only
+config DEEP_PROBE_DEFAULT
+ bool "Probe devices recursively on-demand"
+ help
+ The barebox 'deep probe' or 'probe on demand' mechanism gets
+ rid of the EPROBE_DEFER error code from probes by reordering
+ the device population and the driver registration.
+ All drivers are registered first and afterwards devices are
+ populated. When a device probing requires a resource that's
+ not yet available, the device providing that resource is probed
+ recursively, hence the probe callstack gets deeper until all
+ resources are available.
+
+ This changes the order in which drivers are initialized, which
+ can unearth bugs in drivers. Board code that makes use of
+ different initcall levels to interleave with driver probes
+ will behave differently.
+
+ If unsure and you want to fix implicit assumptions that may
+ break your startup, say 'y'.
+ If unsure and you want deep probe to only be enabled
+ explicitly per top-level machine compatible, say 'n'.
+
config PM_GENERIC_DOMAINS
bool
--
2.39.5
next prev parent reply other threads:[~2025-06-02 9:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-02 9:57 [PATCH v2 1/5] common: deep-probe: inform only about lack of deep-probe support Ahmad Fatoum
2025-06-02 9:57 ` Ahmad Fatoum [this message]
2025-06-02 10:09 ` [PATCH v2 2/5] common: deep-probe: support specifying support in DT Marco Felsch
2025-06-02 9:57 ` [PATCH v2 3/5] treewide: dts: describe deep probe support in device tree Ahmad Fatoum
2025-06-02 9:57 ` [PATCH v2 4/5] ARM: configs: enable deep probe for the most popular configs Ahmad Fatoum
2025-06-02 9:57 ` [PATCH v2 5/5] Documentation: migration-2025.07.0: document CONFIG_DEEP_PROBE_DEFAULT Ahmad Fatoum
2025-06-02 10:16 ` [PATCH v2 1/5] common: deep-probe: inform only about lack of deep-probe support 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=20250602095738.822334-2-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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