Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- can squash for v2 --- drivers/of/reserved-mem.c | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 drivers/of/reserved-mem.c diff --git a/drivers/of/reserved-mem.c b/drivers/of/reserved-mem.c new file mode 100644 index 000000000000..efa96fe65cd9 --- /dev/null +++ b/drivers/of/reserved-mem.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: 2021 Rouven Czerwinski <r.czerwinski@xxxxxxxxxxxxxx>, Pengutronix + +#define pr_fmt(fmt) "reserved-memory: " fmt + +#include <common.h> +#include <init.h> +#include <of.h> +#include <of_address.h> + +static void reserve(const char *name, u64 start, u64 end, bool xn) +{ + int flags = OF_RESERVE_ENTRY_FLAG_NO_FIXUP; + + if (xn) + flags |= OF_RESERVE_ENTRY_FLAG_RUNTIME_FW; + + pr_debug("region %s 0x%08llx-0x%08llx\n", name, start, end); + + of_add_reserve_entry(start, end, flags); +} + +static int reserved_mem_read(void) +{ + struct device_node *node, *child; + struct resource resource; + const __be32 *reg; + + node = of_find_node_by_path("/reserved-memory"); + if (node) { + for_each_available_child_of_node(node, child) { + /* skip e.g. linux,cma */ + if (!of_get_property(child, "reg", NULL)) + continue; + + of_address_to_resource(child, 0, &resource); + + /* + * Just keep on mapping 1:1, but avoid speculative + * execution into such a region + */ + reserve(child->name, + resource.start, resource.end, + of_find_property(child, "no-map", 0)); + } + } + + node = of_find_node_by_path("/memreserve"); + reg = of_get_property(node, "reg", NULL); + if (reg) { + u32 na = 2, ns = 2; + u64 addr, size; + + of_property_read_u32(node, "#address-cells", &na); + of_property_read_u32(node, "#size-cells", &ns); + + addr = of_read_number(reg, na); + size = of_read_number(reg + na, ns); + + reserve("/memreserve", addr, addr + size - 1, false); + } + + return 0; +} +postconsole_initcall(reserved_mem_read); -- 2.30.2 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox