mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] fdt: Do not reserve device tree blob
@ 2023-10-19 11:27 Sascha Hauer
  2023-10-19 11:27 ` [PATCH 2/4] bootm: print memreserve map in verbose mode Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-10-19 11:27 UTC (permalink / raw)
  To: Barebox List

As a matter of fact the reservation is buggy. fdt_add_reserve_map()
added the reservation for the address the fdt currently is placed,
but the fdt is relocated in bootm_load_devicetree() later. This means
we just add a reserve region for some arbitrary piece of memory which
can equally well be removed.

Linux doesn't require reserving the device tree blob. Some architectures
use early_init_fdt_reserve_self() to mark the fdt as reserved, some like
arm64 use architecture code to reserve the region, others like arm move
the fdt away.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/fdt.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9d72fafd36..734dbfc92a 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -554,9 +554,7 @@ void of_clean_reserve_map(void)
  * @__fdt: The devicetree blob
  *
  * This adds the reservemap entries previously collected in
- * of_add_reserve_entry() to a devicetree binary blob. This also
- * adds the devicetree itself to the reserved list, so after calling
- * this function the tree should not be relocated anymore.
+ * of_add_reserve_entry() to a devicetree binary blob.
  */
 void fdt_add_reserve_map(void *__fdt)
 {
@@ -584,10 +582,6 @@ void fdt_add_reserve_map(void *__fdt)
 		fdt_res++;
 	}
 
-	of_write_number(&fdt_res->address, (unsigned long)__fdt, 2);
-	of_write_number(&fdt_res->size, be32_to_cpu(fdt->totalsize), 2);
-	fdt_res++;
-
 	of_write_number(&fdt_res->address, 0, 2);
 	of_write_number(&fdt_res->size, 0, 2);
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/4] bootm: print memreserve map in verbose mode
  2023-10-19 11:27 [PATCH 1/4] fdt: Do not reserve device tree blob Sascha Hauer
@ 2023-10-19 11:27 ` Sascha Hauer
  2023-10-19 11:27 ` [PATCH 3/4] arm: layerscape: ppa: reserve SDRAM region for PPA Sascha Hauer
  2023-10-19 11:27 ` [PATCH 4/4] arm: layerscape: ppa: Add PPA as /reserved-memory/ppa node Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-10-19 11:27 UTC (permalink / raw)
  To: Barebox List

There currently is no way to print the /memreserve/ map barebox boots
the kernel with. As this contains useful debugging information sometimes
print it along with the device tree when booting with -vv.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c   |  4 +++-
 drivers/of/fdt.c | 23 +++++++++++++++++++++++
 include/of.h     |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 2469d43441..29ea13e28c 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -468,8 +468,10 @@ int bootm_load_devicetree(struct image_data *data, void *fdt,
 	memcpy((void *)data->oftree_res->start, fdt, fdt_size);
 
 	of_print_cmdline(data->of_root_node);
-	if (bootm_verbose(data) > 1)
+	if (bootm_verbose(data) > 1) {
 		of_print_nodes(data->of_root_node, 0, ~0);
+		fdt_print_reserve_map(fdt);
+	}
 
 	return 0;
 }
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 734dbfc92a..223abe9375 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -585,3 +585,26 @@ void fdt_add_reserve_map(void *__fdt)
 	of_write_number(&fdt_res->address, 0, 2);
 	of_write_number(&fdt_res->size, 0, 2);
 }
+
+void fdt_print_reserve_map(const void *__fdt)
+{
+	const struct fdt_header *fdt = __fdt;
+	const struct fdt_reserve_entry *fdt_res =
+		__fdt + be32_to_cpu(fdt->off_mem_rsvmap);
+	int n = 0;
+
+	while (1) {
+		uint64_t size = fdt64_to_cpu(fdt_res->size);
+		uint64_t address = fdt64_to_cpu(fdt_res->address);
+
+		if (!size)
+			break;
+
+		printf("/memreserve/ #%d: 0x%08llx - 0x%08llx\n", n, address, address + size - 1);
+
+		n++;
+		fdt_res++;
+		if (n == OF_MAX_RESERVE_MAP)
+			return;
+	}
+}
diff --git a/include/of.h b/include/of.h
index a7a1ce125f..5686709fcf 100644
--- a/include/of.h
+++ b/include/of.h
@@ -61,6 +61,7 @@ struct of_reserve_map {
 int of_add_reserve_entry(resource_size_t start, resource_size_t end);
 void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
+void fdt_print_reserve_map(const void *fdt);
 
 struct device;
 struct driver;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/4] arm: layerscape: ppa: reserve SDRAM region for PPA
  2023-10-19 11:27 [PATCH 1/4] fdt: Do not reserve device tree blob Sascha Hauer
  2023-10-19 11:27 ` [PATCH 2/4] bootm: print memreserve map in verbose mode Sascha Hauer
@ 2023-10-19 11:27 ` Sascha Hauer
  2023-10-19 11:27 ` [PATCH 4/4] arm: layerscape: ppa: Add PPA as /reserved-memory/ppa node Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-10-19 11:27 UTC (permalink / raw)
  To: Barebox List

The region the PPA is stored may not be speculated into by the CPU.
We have reserve_sdram_region() for this purpose. With this the region
is mapped uncached with excute never bit set. Use this rather than
request_sdram_region().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-layerscape/ppa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-layerscape/ppa.c b/arch/arm/mach-layerscape/ppa.c
index 3fa73d555f..6c3fdff381 100644
--- a/arch/arm/mach-layerscape/ppa.c
+++ b/arch/arm/mach-layerscape/ppa.c
@@ -117,7 +117,7 @@ int ls1046a_ppa_init(resource_size_t ppa_start, resource_size_t ppa_size)
 	size_t ppa_fw_size;
 	int ret;
 
-	res = request_sdram_region("ppa", ppa_start, ppa_size);
+	res = reserve_sdram_region("ppa", ppa_start, ppa_size);
 	if (!res) {
 		pr_err("Cannot request SDRAM region %pa - %pa\n",
 		       &ppa_start, &ppa_end);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 4/4] arm: layerscape: ppa: Add PPA as /reserved-memory/ppa node
  2023-10-19 11:27 [PATCH 1/4] fdt: Do not reserve device tree blob Sascha Hauer
  2023-10-19 11:27 ` [PATCH 2/4] bootm: print memreserve map in verbose mode Sascha Hauer
  2023-10-19 11:27 ` [PATCH 3/4] arm: layerscape: ppa: reserve SDRAM region for PPA Sascha Hauer
@ 2023-10-19 11:27 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-10-19 11:27 UTC (permalink / raw)
  To: Barebox List

Instead of adding a /memreserve/ entry, add the PPA as a
/reserved-memory/ppa node. For the Kernel it doesn't make a difference,
but using a node makes the range visible in /sys/firmware/devicetree and
the node name also gives a hint what the region is reserved for.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-layerscape/ppa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-layerscape/ppa.c b/arch/arm/mach-layerscape/ppa.c
index 6c3fdff381..521e6b89da 100644
--- a/arch/arm/mach-layerscape/ppa.c
+++ b/arch/arm/mach-layerscape/ppa.c
@@ -130,7 +130,7 @@ int ls1046a_ppa_init(resource_size_t ppa_start, resource_size_t ppa_size)
 	if (ret)
 		return ret;
 
-	of_add_reserve_entry(ppa_start, ppa_end);
+	of_register_fixup(of_fixup_reserved_memory, res);
 
 	return 0;
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-19 11:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 11:27 [PATCH 1/4] fdt: Do not reserve device tree blob Sascha Hauer
2023-10-19 11:27 ` [PATCH 2/4] bootm: print memreserve map in verbose mode Sascha Hauer
2023-10-19 11:27 ` [PATCH 3/4] arm: layerscape: ppa: reserve SDRAM region for PPA Sascha Hauer
2023-10-19 11:27 ` [PATCH 4/4] arm: layerscape: ppa: Add PPA as /reserved-memory/ppa node Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox