* [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters
@ 2025-11-28 17:21 Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] memory: keep memory_banks sorted Ahmad Fatoum
2025-12-01 9:10 ` [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
These struct members do not have more info than what's already in the
resource, so just drop them, so code doesn't have to keep them in-sync.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/cpu/mmu-common.c | 4 ++--
arch/arm/lib32/atags.c | 6 +++---
arch/arm/lib32/bootm.c | 6 +++---
arch/arm/lib32/bootz.c | 10 +++++-----
commands/bfetch.c | 2 +-
common/memory.c | 18 +++++++-----------
include/memory.h | 2 --
7 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index b3d9e9579686..227ae4aa34e6 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -145,7 +145,7 @@ static void mmu_remap_memory_banks(void)
struct resource *rsv;
resource_size_t pos;
- pos = bank->start;
+ pos = bank->res->start;
/* Skip reserved regions */
for_each_reserved_region(bank, rsv) {
@@ -154,7 +154,7 @@ static void mmu_remap_memory_banks(void)
pos = rsv->end + 1;
}
- remap_range_end_sans_text(pos, bank->start + bank->size, MAP_CACHED);
+ remap_range_end_sans_text(pos, bank->res->end + 1, MAP_CACHED);
}
/* Do this while interrupt vectors are still writable */
diff --git a/arch/arm/lib32/atags.c b/arch/arm/lib32/atags.c
index d567a13563b6..4af97f001855 100644
--- a/arch/arm/lib32/atags.c
+++ b/arch/arm/lib32/atags.c
@@ -74,7 +74,7 @@ struct tag *armlinux_get_bootparams(void)
return armlinux_bootparams;
for_each_memory_bank(mem)
- return (void *)mem->start + 0x100;
+ return (void *)mem->res->start + 0x100;
BUG();
}
@@ -110,8 +110,8 @@ static void setup_memory_tags(void)
params->hdr.tag = ATAG_MEM;
params->hdr.size = tag_size(tag_mem32);
- params->u.mem.start = bank->start;
- params->u.mem.size = bank->size;
+ params->u.mem.start = bank->res->start;
+ params->u.mem.size = resource_size(bank->res);
params = tag_next(params);
}
diff --git a/arch/arm/lib32/bootm.c b/arch/arm/lib32/bootm.c
index 69ca6d31d6c5..dca4fec0204c 100644
--- a/arch/arm/lib32/bootm.c
+++ b/arch/arm/lib32/bootm.c
@@ -66,11 +66,11 @@ static int sdram_start_and_size(unsigned long *start, unsigned long *size)
res = list_first_entry_or_null(&bank->res->children, struct resource,
sibling);
if (res)
- *size = res->start - bank->start;
+ *size = res->start - bank->res->start;
else
- *size = bank->size;
+ *size = resource_size(bank->res);
- *start = bank->start;
+ *start = bank->res->start;
return 0;
}
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index ddc53431ebd3..6ed6af1d19e3 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -48,8 +48,8 @@ static int do_bootz(int argc, char *argv[])
* the first 128MB of SDRAM.
*/
zimage = memmap(fd, PROT_READ);
- if (zimage && (unsigned long)zimage >= bank->start &&
- (unsigned long)zimage < bank->start + SZ_128M) {
+ if (zimage && (unsigned long)zimage >= bank->res->start &&
+ (unsigned long)zimage < bank->res->start + SZ_128M) {
usemap = 1;
header = zimage;
}
@@ -82,12 +82,12 @@ static int do_bootz(int argc, char *argv[])
end = swab32(end);
if (!usemap) {
- if (bank->size <= SZ_128M) {
+ if (resource_size(bank->res) <= SZ_128M) {
zimage = xmalloc(end);
} else {
- zimage = (void *)bank->start + SZ_8M;
+ zimage = (void *)bank->res->start + SZ_8M;
res = request_sdram_region("zimage",
- bank->start + SZ_8M, end,
+ bank->res->start + SZ_8M, end,
MEMTYPE_LOADER_CODE,
MEMATTRS_RWX);
if (!res) {
diff --git a/commands/bfetch.c b/commands/bfetch.c
index 4de6513ff08e..4de4692a6278 100644
--- a/commands/bfetch.c
+++ b/commands/bfetch.c
@@ -271,7 +271,7 @@ static struct bobject *print_cpu_mem_info(unsigned *line)
}
for_each_memory_bank(mem) {
- memsize += mem->size;
+ memsize += resource_size(mem->res);
nbanks++;
}
diff --git a/common/memory.c b/common/memory.c
index bee55bd647e1..f179a3243ff1 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -185,8 +185,8 @@ static int barebox_grow_memory_bank(struct memory_bank *bank, const char *name,
struct resource *res;
resource_size_t bank_end = bank->res->end;
- if (newres->start < bank->start) {
- res = request_iomem_region(name, newres->start, bank->start - 1);
+ if (newres->start < bank->res->start) {
+ res = request_iomem_region(name, newres->start, bank->res->start - 1);
if (IS_ERR(res))
return PTR_ERR(res);
__merge_regions(name, bank->res, res);
@@ -199,9 +199,6 @@ static int barebox_grow_memory_bank(struct memory_bank *bank, const char *name,
__merge_regions(name, bank->res, res);
}
- bank->start = newres->start;
- bank->size = resource_size(bank->res);
-
return 0;
}
@@ -232,8 +229,6 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
bank = xzalloc(sizeof(*bank));
bank->res = res;
- bank->start = start;
- bank->size = size;
list_add_tail(&bank->list, &memory_banks);
@@ -245,7 +240,8 @@ static int add_mem_devices(void)
struct memory_bank *bank;
for_each_memory_bank(bank) {
- add_mem_device(bank->res->name, bank->start, bank->size,
+ add_mem_device(bank->res->name,
+ bank->res->start, resource_size(bank->res),
IORESOURCE_MEM_WRITEABLE);
}
@@ -400,7 +396,7 @@ static int of_memory_fixup(struct device_node *root, void *unused)
int len = 0;
/* Create a /memory node for each bank */
- memnode_name = xasprintf("/memory@%lx", bank->start);
+ memnode_name = xasprintf("/memory@%llx", (u64)bank->res->start);
memnode = of_create_node(root, memnode_name);
if (!memnode) {
@@ -413,9 +409,9 @@ static int of_memory_fixup(struct device_node *root, void *unused)
if (err)
goto err_free;
- of_write_number(tmp, bank->start, addr_cell_len);
+ of_write_number(tmp, bank->res->start, addr_cell_len);
len += addr_cell_len * 4;
- of_write_number(tmp + len, bank->size, size_cell_len);
+ of_write_number(tmp + len, resource_size(bank->res), size_cell_len);
len += size_cell_len * 4;
err = of_set_property(memnode, "reg", tmp, len, 1);
diff --git a/include/memory.h b/include/memory.h
index 12dd4220422c..dea76dd2b1f7 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -17,8 +17,6 @@ static inline ulong mem_malloc_size(void)
struct memory_bank {
struct list_head list;
- unsigned long start;
- unsigned long size;
struct resource *res;
};
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] memory: keep memory_banks sorted
2025-11-28 17:21 [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Ahmad Fatoum
@ 2025-11-28 17:21 ` Ahmad Fatoum
2025-12-01 9:10 ` [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Failing to sort the memory banks can lead to surprising behavior, e.g.
kernel ending up beyond the lower 4G.
Keep the memory banks sorted, also to support more optimal lookups in
future.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/memory.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/common/memory.c b/common/memory.c
index f179a3243ff1..2b1523c5d0bf 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -202,6 +202,17 @@ static int barebox_grow_memory_bank(struct memory_bank *bank, const char *name,
return 0;
}
+static int sort_memory_banks(struct list_head *a, struct list_head *b)
+{
+ struct resource *res_a = list_entry(a, struct memory_bank, list)->res;
+ struct resource *res_b = list_entry(b, struct memory_bank, list)->res;
+
+ /* banks are requested from iomem_resource, so they can't overlap
+ * and thus comparing just the start is sufficient
+ */
+ return compare3(res_a->start, res_b->start);
+}
+
int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size)
{
@@ -230,7 +241,7 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
bank->res = res;
- list_add_tail(&bank->list, &memory_banks);
+ list_add_sort(&bank->list, &memory_banks, sort_memory_banks);
return 0;
}
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters
2025-11-28 17:21 [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] memory: keep memory_banks sorted Ahmad Fatoum
@ 2025-12-01 9:10 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-12-01 9:10 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Fri, 28 Nov 2025 18:21:45 +0100, Ahmad Fatoum wrote:
> These struct members do not have more info than what's already in the
> resource, so just drop them, so code doesn't have to keep them in-sync.
>
>
Applied, thanks!
[1/2] memory: drop superfluous struct memory_bank::start/size parameters
https://git.pengutronix.de/cgit/barebox/commit/?id=f352f1dce8b4 (link may not be stable)
[2/2] memory: keep memory_banks sorted
https://git.pengutronix.de/cgit/barebox/commit/?id=f48a68983067 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-01 9:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 17:21 [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] memory: keep memory_banks sorted Ahmad Fatoum
2025-12-01 9:10 ` [PATCH 1/2] memory: drop superfluous struct memory_bank::start/size parameters Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox