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] fixup! of: request reserved memory regions so other code can't
Date: Thu,  9 Jun 2022 10:31:18 +0200	[thread overview]
Message-ID: <20220609083118.865853-1-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220609054342.661505-5-a.fatoum@pengutronix.de>

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
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@pengutronix.de>, 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-06-09  8:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  5:43 [PATCH 0/4] " Ahmad Fatoum
2022-06-09  5:43 ` [PATCH 1/4] nvmem: rmem: get, don't request, memory region Ahmad Fatoum
2022-06-09  5:43 ` [PATCH 2/4] of: reserve: mark runtime firmware code regions specially Ahmad Fatoum
2022-06-09  8:05   ` Sascha Hauer
2022-06-09  8:17     ` Ahmad Fatoum
2022-06-09  5:43 ` [PATCH 3/4] of: add of_get_reserve_map stub for !CONFIG_OFTREE Ahmad Fatoum
2022-06-09  9:14   ` Sascha Hauer
2022-06-09  5:43 ` [PATCH 4/4] of: request reserved memory regions so other code can't Ahmad Fatoum
2022-06-09  8:31   ` Ahmad Fatoum [this message]
2022-06-09  8:31   ` Sascha Hauer
2022-06-09  8:36     ` Ahmad Fatoum

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=20220609083118.865853-1-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