/src/barebox/common/deep-probe.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-only |
2 | | |
3 | | #define pr_fmt(fmt) "deep-probe: " fmt |
4 | | |
5 | | #if defined(CONFIG_DEBUG_INITCALLS) || defined(CONFIG_DEBUG_PROBES) |
6 | | #define DEBUG |
7 | | #endif |
8 | | |
9 | | #include <common.h> |
10 | | #include <deep-probe.h> |
11 | | #include <of.h> |
12 | | |
13 | | enum deep_probe_state { |
14 | | DEEP_PROBE_UNKNOWN = -1, |
15 | | DEEP_PROBE_NOT_SUPPORTED, |
16 | | DEEP_PROBE_SUPPORTED |
17 | | }; |
18 | | |
19 | | static enum deep_probe_state boardstate = DEEP_PROBE_UNKNOWN; |
20 | | |
21 | | bool deep_probe_is_supported(void) |
22 | 256 | { |
23 | 256 | bool deep_probe_default = IS_ENABLED(CONFIG_DEEP_PROBE_DEFAULT); |
24 | 256 | struct deep_probe_entry *board; |
25 | 256 | struct device_node *root; |
26 | | |
27 | 256 | if (boardstate > DEEP_PROBE_UNKNOWN) |
28 | 224 | return boardstate; |
29 | | |
30 | | /* |
31 | | * Deep probe requires resources to be described in DT. |
32 | | * We intentionally omit setting boardstate here on the |
33 | | * off-chance that this function is called too early. |
34 | | */ |
35 | 32 | root = of_get_root_node(); |
36 | 32 | if (!root) |
37 | 0 | return false; |
38 | | |
39 | | /* determine boardstate according to BAREBOX_DEEP_PROBE_ENABLE */ |
40 | 32 | for (board = __barebox_deep_probe_start; |
41 | 32 | board != __barebox_deep_probe_end; board++) { |
42 | 32 | const struct of_device_id *matches = board->device_id; |
43 | | |
44 | 32 | for (; matches->compatible; matches++) { |
45 | 32 | if (of_machine_is_compatible(matches->compatible)) { |
46 | 32 | boardstate = DEEP_PROBE_SUPPORTED; |
47 | 32 | pr_debug("supported due to %s\n", matches->compatible); |
48 | 32 | return true; |
49 | 32 | } |
50 | 32 | } |
51 | 32 | } |
52 | | |
53 | | /* |
54 | | * Deep probe used to be opt-in. As we want all new board support |
55 | | * to make use of it, we add a config option to make it opt-out and |
56 | | * start emitting a warning for boards that are undecided: |
57 | | * |
58 | | * - Boards that don't support deep probe should explicitly opt-out |
59 | | * using barebox,disable-deep-probe in their device tree. |
60 | | * |
61 | | * - Boards that support deep probe can indicate so using |
62 | | * barebox,deep-probe if there is no BAREBOX_DEEP_PROBE_ENABLE |
63 | | * already. |
64 | | * |
65 | | * - New boards without board code will default to deep-probe enabled, |
66 | | * because CONFIG_DEEP_PROBE_DEFAULT=y would be set in the defconfigs. |
67 | | * |
68 | | * Refer to barebox,deep-probe.rst for more information. |
69 | | */ |
70 | 0 | if (of_property_read_bool(root, "barebox,disable-deep-probe")) { |
71 | 0 | boardstate = DEEP_PROBE_NOT_SUPPORTED; |
72 | 0 | pr_info("disabled in device tree\n"); |
73 | 0 | } else if (of_property_read_bool(root, "barebox,deep-probe")) { |
74 | 0 | boardstate = DEEP_PROBE_SUPPORTED; |
75 | 0 | pr_debug("enabled in device tree\n"); |
76 | 0 | } else if (deep_probe_default) { |
77 | 0 | boardstate = DEEP_PROBE_SUPPORTED; |
78 | 0 | pr_debug("activated by default\n"); |
79 | 0 | } else { |
80 | 0 | boardstate = DEEP_PROBE_NOT_SUPPORTED; |
81 | 0 | pr_warn("DT missing barebox,deep-probe or barebox,disable-deep-probe property\n"); |
82 | 0 | pr_info("not activated by default\n"); |
83 | 0 | } |
84 | |
|
85 | 0 | return boardstate; |
86 | 32 | } |
87 | | EXPORT_SYMBOL_GPL(deep_probe_is_supported); |