[PATCH v2 1/6] memory: add support for requesting barebox area as a whole

Ahmad Fatoum a.fatoum at pengutronix.de
Thu May 16 23:45:06 PDT 2024


barebox-specific code and data is normally located at the end of
early-known memory. To ensure it's not overwritten, parts of it are
reserved with request_sdram_region at different places.

Gaps in the reservation lead to multiple issues in the past.
So for documentation purposes and to avoid functiosn like
memory_bank_first_find_space finding vacant area where there isn't,
allow architectures call register_barebox_area to do one full
SDRAM request for the area.

Region requests for subsets of this area will be switched in the
follow-up commit to use the new request_barebox_region, which allocates
a subregion if it lies inside a registered barebox area and defers
to request_sdram_region otherwise.

The motivation for this patch is that with the addition of handoff data,
doing separate memory reservation for every accounting structure (cookie
and linked list) in addition to the data could make iomem output a bit
unwieldy, but we really want to avoid anyone else overwriting it.

While at it, we also rename the regions for barebox code and bss to be
more descriptive.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 common/memory.c  | 38 ++++++++++++++++++++++++++++++++++++--
 include/memory.h |  6 ++++++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 583843cc34c0..8e68b5e8bb20 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -57,6 +57,40 @@ void mem_malloc_init(void *start, void *end)
 	mem_malloc_initialized = 1;
 }
 
+static struct resource *barebox_res;
+static resource_size_t barebox_start;
+static resource_size_t barebox_size;
+
+void register_barebox_area(resource_size_t start,
+			   resource_size_t size)
+{
+	barebox_start = start,
+	barebox_size = size;
+}
+
+static int mem_register_barebox(void)
+{
+	if (barebox_start && barebox_size)
+		barebox_res = request_sdram_region("barebox", barebox_start,
+						   barebox_size);
+	return 0;
+}
+postmem_initcall(mem_register_barebox);
+
+struct resource *request_barebox_region(const char *name,
+					resource_size_t start,
+					resource_size_t size)
+{
+	resource_size_t end = start + size - 1;
+
+	if (barebox_res && barebox_res->start <= start &&
+	    end <= barebox_res->end)
+		return __request_region(barebox_res, start, end,
+					name, IORESOURCE_MEM);
+
+	return request_sdram_region(name, start, size);
+}
+
 static int mem_malloc_resource(void)
 {
 #if !defined __SANDBOX__
@@ -69,7 +103,7 @@ static int mem_malloc_resource(void)
 	request_sdram_region("malloc space",
 			malloc_start,
 			malloc_end - malloc_start + 1);
-	request_sdram_region("barebox",
+	request_sdram_region("barebox code",
 			(unsigned long)&_stext,
 			(unsigned long)&_etext -
 			(unsigned long)&_stext);
@@ -77,7 +111,7 @@ static int mem_malloc_resource(void)
 			(unsigned long)&_sdata,
 			(unsigned long)&_edata -
 			(unsigned long)&_sdata);
-	request_sdram_region("bss",
+	request_sdram_region("barebox bss",
 			(unsigned long)&__bss_start,
 			(unsigned long)&__bss_stop -
 			(unsigned long)&__bss_start);
diff --git a/include/memory.h b/include/memory.h
index d8691972ec9b..571effd3b0d6 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -61,4 +61,10 @@ static inline u64 memory_sdram_size(unsigned int cols,
 	return (u64)banks * width << (rows + cols);
 }
 
+void register_barebox_area(resource_size_t start, resource_size_t size);
+
+struct resource *request_barebox_region(const char *name,
+					resource_size_t start,
+					resource_size_t size);
+
 #endif
-- 
2.39.2




More information about the barebox mailing list