From b9958d497dfd9fc563b198f7233c57388d76cd06 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 31 May 2021 09:12:34 +0200 Subject: 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 Link: https://lore.barebox.org/20210531071239.30653-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- common/memory.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'common') 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 */ -- cgit v1.2.3