mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 09/10] memory: always print errors on request_sdram_region failure
Date: Mon,  5 Jan 2026 09:03:41 +0100	[thread overview]
Message-ID: <20260105080653.3240497-10-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260105080653.3240497-1-a.fatoum@barebox.org>

A failed request_sdram_region is nearly always a problem and warrants a
print out.

Introduce request_sdram_region_silent() for the few cases, where an
error is tolerated and print an error message in the general case.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/cpu/armv7r-mpu.c |  6 +++---
 arch/arm/cpu/bootm-fip.c  |  6 +++---
 arch/arm/cpu/mmu_32.c     |  4 ++--
 common/elf.c              |  4 ++--
 common/memory.c           | 20 +++++++++++++-------
 include/memory.h          | 39 +++++++++++++++++++++++++++++++--------
 6 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/arch/arm/cpu/armv7r-mpu.c b/arch/arm/cpu/armv7r-mpu.c
index 4fb867c50a42..d96411a61632 100644
--- a/arch/arm/cpu/armv7r-mpu.c
+++ b/arch/arm/cpu/armv7r-mpu.c
@@ -206,9 +206,9 @@ int armv7r_mpu_init_coherent(unsigned long start, enum size reg_size)
 static int armv7r_request_pool(void)
 {
 	if (dma_coherent_start && dma_coherent_size)
-		request_sdram_region("DMA coherent pool",
-				     dma_coherent_start, dma_coherent_size,
-				     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
+		request_sdram_region_silent("DMA coherent pool",
+					    dma_coherent_start, dma_coherent_size,
+					    MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
 	return 0;
 }
 postmem_initcall(armv7r_request_pool);
diff --git a/arch/arm/cpu/bootm-fip.c b/arch/arm/cpu/bootm-fip.c
index 8d1ea3f109d1..a4da4c538abe 100644
--- a/arch/arm/cpu/bootm-fip.c
+++ b/arch/arm/cpu/bootm-fip.c
@@ -36,9 +36,9 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)
 	if (desc_get_res(loadable))
 		return 0;
 
-	res = request_sdram_region("fip", load_address,
-				   loadable->image->toc_e.size,
-				   MEMTYPE_LOADER_CODE, MEMATTRS_RW);
+	res = request_sdram_region_silent("fip", load_address,
+					  loadable->image->toc_e.size,
+					  MEMTYPE_LOADER_CODE, MEMATTRS_RW);
 	if (!res)
 		return -EBUSY;
 
diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 912d14e8cf82..caa41e1beb3a 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -540,8 +540,8 @@ static void create_zero_page(void)
 	 * In case the zero page is in SDRAM request it to prevent others
 	 * from using it
 	 */
-	request_sdram_region("zero page", 0x0, PAGE_SIZE,
-			     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_FAULT);
+	request_sdram_region_silent("zero page", 0x0, PAGE_SIZE,
+				    MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_FAULT);
 
 	zero_page_faulting();
 	pr_debug("Created zero page\n");
diff --git a/common/elf.c b/common/elf.c
index 4f4151f722d7..330505e9a2bf 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -31,8 +31,8 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,
 	if (!r)
 		return -ENOMEM;
 
-	r_new = request_sdram_region("elf_segment", start, size,
-				     MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
+	r_new = request_sdram_region_silent("elf_segment", start, size,
+					    MEMTYPE_LOADER_CODE, MEMATTRS_RWX);
 	if (!r_new) {
 		r_new = request_iomem_region("elf_segment", start, size);
 		if (!r_new) {
diff --git a/common/memory.c b/common/memory.c
index 7dc7f40db7fc..49ff0ef619d5 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -67,7 +67,7 @@ void register_barebox_area(resource_size_t start,
 static int mem_register_barebox(void)
 {
 	if (barebox_start && barebox_size)
-		barebox_res = request_sdram_region("barebox", barebox_start,
+		barebox_res = request_sdram_region_silent("barebox", barebox_start,
 						   barebox_size,
 						   MEMTYPE_BOOT_SERVICES_CODE,
 						   MEMATTRS_RWX); // FIXME
@@ -108,7 +108,7 @@ struct resource *request_barebox_region(const char *name,
 		return iores;
 	}
 
-	return request_sdram_region(name, start, size, memtype, memattrs);
+	return request_sdram_region_silent(name, start, size, memtype, memattrs);
 }
 
 static int mem_malloc_resource(void)
@@ -122,7 +122,7 @@ static int mem_malloc_resource(void)
 	 * regions are outside of sdram in which case
 	 * the following fails.
 	 */
-	request_sdram_region("malloc space",
+	request_sdram_region_silent("malloc space",
 			malloc_start,
 			malloc_end - malloc_start + 1,
 			MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
@@ -179,7 +179,7 @@ static int mem_malloc_resource(void)
 			MEMATTRS_RW);
 #endif
 #ifdef STACK_BASE
-	request_sdram_region("stack", STACK_BASE, STACK_SIZE,
+	request_sdram_region_silent("stack", STACK_BASE, STACK_SIZE,
 			     MEMTYPE_BOOT_SERVICES_DATA, MEMATTRS_RW);
 #endif
 
@@ -302,19 +302,25 @@ postmem_initcall(add_mem_devices);
  * Request a region from the registered sdram
  */
 struct resource *__request_sdram_region(const char *name,
-					resource_size_t start, resource_size_t size)
+					resource_size_t start, resource_size_t size,
+					bool verbose)
 {
 	struct memory_bank *bank;
+	resource_size_t end = start + size - 1;
 
 	for_each_memory_bank(bank) {
 		struct resource *res;
 
-		res = __request_region(bank->res, start, start + size - 1,
+		res = __request_region(bank->res, start, end,
 				       name, IORESOURCE_MEM);
 		if (!IS_ERR(res))
 			return res;
 	}
 
+	if (verbose)
+		pr_err("unable to request SDRAM region for %s at %pa-%pa\n",
+		       name, &start, &end);
+
 	return NULL;
 }
 
@@ -339,7 +345,7 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,
 	 * want to set the reserved flag independently of whether
 	 * CONFIG_MEMORY_ATTRIBUTES is enabled or not
 	 */
-	res = __request_sdram_region(name, start, size);
+	res = __request_sdram_region(name, start, size, true);
 	if (!res)
 		return NULL;
 
diff --git a/include/memory.h b/include/memory.h
index 3475e9211b0c..6b7ada641c9d 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -39,7 +39,21 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
 	for_each_resource_region_reverse((bank)->res, region)
 
 struct resource *__request_sdram_region(const char *name,
-					resource_size_t start, resource_size_t size);
+					resource_size_t start, resource_size_t size,
+					bool verbose);
+
+static inline struct resource *sdram_region_with_attrs(struct resource *res,
+						       enum resource_memtype memtype,
+						       unsigned memattrs)
+{
+	if (IS_ENABLED(CONFIG_MEMORY_ATTRIBUTES) && res) {
+		res->type = memtype;
+		res->attrs = memattrs;
+		res->flags |= IORESOURCE_TYPE_VALID;
+	}
+
+	return res;
+}
 
 static inline struct resource *request_sdram_region(const char *name,
 						    resource_size_t start,
@@ -50,14 +64,23 @@ static inline struct resource *request_sdram_region(const char *name,
 	struct resource *res;
 
 	/* IORESOURCE_MEM is implicit for all SDRAM regions */
-	res = __request_sdram_region(name, start, size);
-	if (IS_ENABLED(CONFIG_MEMORY_ATTRIBUTES) && res) {
-		res->type = memtype;
-		res->attrs = memattrs;
-		res->flags |= IORESOURCE_TYPE_VALID;
-	}
+	res = __request_sdram_region(name, start, size, true);
 
-	return res;
+	return sdram_region_with_attrs(res, memtype, memattrs);
+}
+
+static inline struct resource *request_sdram_region_silent(const char *name,
+							   resource_size_t start,
+							   resource_size_t size,
+							   enum resource_memtype memtype,
+							   unsigned memattrs)
+{
+	struct resource *res;
+
+	/* IORESOURCE_MEM is implicit for all SDRAM regions */
+	res = __request_sdram_region(name, start, size, false);
+
+	return sdram_region_with_attrs(res, memtype, memattrs);
 }
 
 struct resource *reserve_sdram_region(const char *name, resource_size_t start,
-- 
2.47.3




  parent reply	other threads:[~2026-01-05  8:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 01/10] bootm: set image_data::initrd_res at a single place Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 02/10] bootm: fit: split support into dedicated file Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 03/10] bootm: uimage: " Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 04/10] filetype: introduce filetype_fit Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 05/10] bootm: refactor for readability and extensibility Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 06/10] memory: move release_sdram_region into header Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 07/10] resource: make NULL in release_[sdram_]region a no-op Ahmad Fatoum
2026-01-05  8:03 ` [PATCH 08/10] common: elf: use release_region unconditionally Ahmad Fatoum
2026-01-05  8:03 ` Ahmad Fatoum [this message]
2026-01-05  8:03 ` [PATCH 10/10] memory: drop now duplicate request_sdram_region error messages Ahmad Fatoum
2026-01-09  8:20 ` [PATCH 00/10] bootm: refactor to prepare multiple initrd support Sascha Hauer

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=20260105080653.3240497-10-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --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