diff options
author | Rob Herring (Arm) <robh@kernel.org> | 2024-11-06 18:10:27 +0100 |
---|---|---|
committer | Rob Herring (Arm) <robh@kernel.org> | 2024-11-08 20:15:54 +0100 |
commit | 045b14ca5c3657dc6c16afa97a00dba17286d3e8 (patch) | |
tree | b979a9111728d09ae227d47572fdbdaa983d47e0 /drivers/of | |
parent | of/fdt: Don't use default address cell sizes for address translation (diff) | |
download | linux-045b14ca5c3657dc6c16afa97a00dba17286d3e8.tar.xz linux-045b14ca5c3657dc6c16afa97a00dba17286d3e8.zip |
of: WARN on deprecated #address-cells/#size-cells handling
While OpenFirmware originally allowed walking parent nodes and default
root values for #address-cells and #size-cells, FDT has long required
explicit values. It's been a warning in dtc for the root node since the
beginning (2005) and for any parent node since 2007. Of course, not all
FDT uses dtc, but that should be the majority by far. The various
extracted OF devicetrees I have dating back to the 1990s (various
PowerMac, OLPC, PASemi Nemo) all have explicit root node properties. The
warning is disabled for Sparc as there are known systems relying on
default root node values.
Link: https://lore.kernel.org/r/20241106171028.3830266-1-robh@kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 28 | ||||
-rw-r--r-- | drivers/of/fdt.c | 4 |
2 files changed, 24 insertions, 8 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index d94efee4a7fc..a8b0c42bdc8e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -87,15 +87,25 @@ static bool __of_node_is_type(const struct device_node *np, const char *type) return np && match && type && !strcmp(match, type); } +#define EXCLUDED_DEFAULT_CELLS_PLATFORMS ( \ + IS_ENABLED(CONFIG_SPARC) \ +) + int of_bus_n_addr_cells(struct device_node *np) { u32 cells; - for (; np; np = np->parent) + for (; np; np = np->parent) { if (!of_property_read_u32(np, "#address-cells", &cells)) return cells; - - /* No #address-cells property for the root node */ + /* + * Default root value and walking parent nodes for "#address-cells" + * is deprecated. Any platforms which hit this warning should + * be added to the excluded list. + */ + WARN_ONCE(!EXCLUDED_DEFAULT_CELLS_PLATFORMS, + "Missing '#address-cells' in %pOF\n", np); + } return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; } @@ -112,11 +122,17 @@ int of_bus_n_size_cells(struct device_node *np) { u32 cells; - for (; np; np = np->parent) + for (; np; np = np->parent) { if (!of_property_read_u32(np, "#size-cells", &cells)) return cells; - - /* No #size-cells property for the root node */ + /* + * Default root value and walking parent nodes for "#size-cells" + * is deprecated. Any platforms which hit this warning should + * be added to the excluded list. + */ + WARN_ONCE(!EXCLUDED_DEFAULT_CELLS_PLATFORMS, + "Missing '#size-cells' in %pOF\n", np); + } return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; } diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d3ecf2bdd202..0121100372b4 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -937,12 +937,12 @@ int __init early_init_dt_scan_root(void) dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT; prop = of_get_flat_dt_prop(node, "#size-cells", NULL); - if (prop) + if (!WARN(!prop, "No '#size-cells' in root node\n")) dt_root_size_cells = be32_to_cpup(prop); pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells); prop = of_get_flat_dt_prop(node, "#address-cells", NULL); - if (prop) + if (!WARN(!prop, "No '#address-cells' in root node\n")) dt_root_addr_cells = be32_to_cpup(prop); pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells); |