[PATCH 1/6] common: memory: allocate all memory devices at once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 common/memory.c  | 17 +++++++++++++----
 include/memory.h |  1 -
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/common/memory.c b/common/memory.c
index 392522bfc3db..612ed87168b5 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 906d9f7b2689..c793bb51ed77 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;
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux