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 v3 2/3] resource: retire IORESOURCE_BUSY in favor of resource::type
Date: Thu,  5 Jun 2025 21:44:00 +0200	[thread overview]
Message-ID: <20250605194401.1841679-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250605194401.1841679-1-a.fatoum@barebox.org>

The way we use IORESOURCE_BUSY in barebox is different than in Linux and
was only done to have a bit that doesn't sound too off-topic.

Now that we have proper memory type and attributes, let's make use of
them and retire IORESOURCE_BUSY.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
v2 -> v3:
  - remove dependency on CONFIG_MEMORY_ATTRIBUTES
---
 commands/iomemport.c         |  2 +-
 common/memory.c              | 13 ++++++++-----
 common/oftree.c              |  2 +-
 drivers/tee/optee/of_fixup.c |  2 +-
 include/memory.h             |  6 +++---
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/commands/iomemport.c b/commands/iomemport.c
index f2baa0e29397..bbe41f571b48 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -18,7 +18,7 @@ static void __print_resources(struct resource *res, int indent)
 
 	printf("%pa - %pa (size %pa) %s%s\n",
 			&res->start, &res->end, &size,
-			res->flags & IORESOURCE_BUSY ? "[R] " : "",
+			is_reserved_resource(res) ? "[R] " : "",
 			res->name);
 
 	list_for_each_entry(r, &res->children, sibling) {
diff --git a/common/memory.c b/common/memory.c
index f407cf0ea7e3..57f58026df8e 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -251,18 +251,16 @@ postmem_initcall(add_mem_devices);
 /*
  * Request a region from the registered sdram
  */
-struct resource *__request_sdram_region(const char *name, unsigned flags,
+struct resource *__request_sdram_region(const char *name,
 					resource_size_t start, resource_size_t size)
 {
 	struct memory_bank *bank;
 
-	flags |= IORESOURCE_MEM;
-
 	for_each_memory_bank(bank) {
 		struct resource *res;
 
 		res = __request_region(bank->res, start, start + size - 1,
-				       name, flags);
+				       name, IORESOURCE_MEM);
 		if (!IS_ERR(res))
 			return res;
 	}
@@ -286,7 +284,12 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,
 		size = ALIGN(size, PAGE_SIZE);
 	}
 
-	res = __request_sdram_region(name, IORESOURCE_BUSY, start, size);
+	/*
+	 * We intentionally don't use request_sdram_region() here, because we
+	 * want to set the reserved flag independently of whether
+	 * CONFIG_MEMORY_ATTRIBUTES is enabled or not
+	 */
+	res = __request_sdram_region(name, start, size);
 	if (!res)
 		return NULL;
 
diff --git a/common/oftree.c b/common/oftree.c
index 58e96c39d897..c22793de89fb 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -304,7 +304,7 @@ int of_fixup_reserved_memory(struct device_node *root, void *_res)
 
 	child = of_get_child_by_name(node, res->name) ?: of_new_node(node, res->name);
 
-	if (res->flags & IORESOURCE_BUSY)
+	if (is_reserved_resource(res))
 		of_property_write_bool(child, "no-map", true);
 
 	of_write_number(reg, res->start, addr_n_cells);
diff --git a/drivers/tee/optee/of_fixup.c b/drivers/tee/optee/of_fixup.c
index 223f67e872aa..f3ccff31e68a 100644
--- a/drivers/tee/optee/of_fixup.c
+++ b/drivers/tee/optee/of_fixup.c
@@ -37,7 +37,7 @@ int of_optee_fixup(struct device_node *root, void *_data)
 		res_core.start = arm_mem_endmem_get() - OPTEE_SIZE;
 		res_core.end = arm_mem_endmem_get() - fixup_data->shm_size - 1;
 	}
-	res_core.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+	res_core.flags = IORESOURCE_MEM;
 	reserve_resource(&res_core);
 	res_core.name = "optee_core";
 
diff --git a/include/memory.h b/include/memory.h
index 77bd4d266a72..12dd4220422c 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -30,9 +30,9 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
 #define for_each_memory_bank(mem)	list_for_each_entry(mem, &memory_banks, list)
 #define for_each_reserved_region(mem, rsv) \
 	list_for_each_entry(rsv, &(mem)->res->children, sibling) \
-	if (((rsv)->flags & IORESOURCE_BUSY))
+		if (is_reserved_resource(rsv))
 
-struct resource *__request_sdram_region(const char *name, unsigned flags,
+struct resource *__request_sdram_region(const char *name,
 					resource_size_t start, resource_size_t size);
 
 static inline struct resource *request_sdram_region(const char *name,
@@ -44,7 +44,7 @@ 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, 0, start, size);
+	res = __request_sdram_region(name, start, size);
 	if (IS_ENABLED(CONFIG_MEMORY_ATTRIBUTES) && res) {
 		res->type = memtype;
 		res->attrs = memattrs;
-- 
2.39.5




  reply	other threads:[~2025-06-05 19:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 19:43 [PATCH v3 1/3] resource: supply memory type/attrs on all SDRAM requests Ahmad Fatoum
2025-06-05 19:44 ` Ahmad Fatoum [this message]
2025-06-05 19:44 ` [PATCH v3 3/3] commands: iomem: add support for printing type/attributes 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=20250605194401.1841679-2-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