summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-31 09:12:34 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-02 08:37:22 +0200
commitb9958d497dfd9fc563b198f7233c57388d76cd06 (patch)
treeebe8793df8ec01ce33de9ac5eaf1a38bc440fd20
parent5b4dcc6fdeadf4844852efd7c950614de8525a83 (diff)
downloadbarebox-b9958d497dfd9fc563b198f7233c57388d76cd06.tar.gz
barebox-b9958d497dfd9fc563b198f7233c57388d76cd06.tar.xz
common: memory: allocate all memory devices at once
Follow-up commit will fuse overlapping RAM banks. As all memory is supposed to be registered during mem_initcall or before, we can postpone device creation to mmu_initcall, so we can directly allocate devices spanning the correct region. The mem driver and the devinfo command are the only consumers of these devices, so it's ok to register the devices at mmu_initcall. While at it, drop the struct memory_bank::dev member. It's unused anywhere. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210531071239.30653-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/memory.c17
-rw-r--r--include/memory.h1
2 files changed, 13 insertions, 5 deletions
diff --git a/common/memory.c b/common/memory.c
index 392522bfc3..612ed87168 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -115,15 +115,11 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size)
{
struct memory_bank *bank = xzalloc(sizeof(*bank));
- struct device_d *dev;
bank->res = request_iomem_region(name, start, start + size - 1);
if (IS_ERR(bank->res))
return PTR_ERR(bank->res);
- dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
-
- bank->dev = dev;
bank->start = start;
bank->size = size;
@@ -132,6 +128,19 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,
return 0;
}
+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,
+ IORESOURCE_MEM_WRITEABLE);
+ }
+
+ return 0;
+}
+mmu_initcall(add_mem_devices);
+
/*
* Request a region from the registered sdram
*/
diff --git a/include/memory.h b/include/memory.h
index 906d9f7b26..c793bb51ed 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -11,7 +11,6 @@ ulong mem_malloc_end(void);
struct memory_bank {
struct list_head list;
- struct device_d *dev;
unsigned long start;
unsigned long size;
struct resource *res;