From patchwork Fri Jun 7 18:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802319 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp948924wro; Fri, 7 Jun 2024 11:55:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZ5sFh4YQO4F9lkWVdXqqR9VXPslfecF3vJVl2J3zwv71pKoAuM4YfB7NWUqc8Z3jbEDj74/G5Dmpoxza1rfQx X-Google-Smtp-Source: AGHT+IGqpyjTg8gb402oU37Hw9BU5nTWXHadwiyVcY1pJTurW/KBpBEXnTZOGZJl7OT9o6VsEZ8D X-Received: by 2002:a17:906:c099:b0:a6e:7719:e4b1 with SMTP id a640c23a62f3a-a6e7719fdeemr147221066b.29.1717786501814; Fri, 07 Jun 2024 11:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786501; cv=none; d=google.com; s=arc-20160816; b=tos3HbYfyI79thIl8I7i2VD3NZIzMIYsM7nxDxQnYlfmCfioK/xa4p1nXsYISShWVk +OjGi8yQ1HW54LDxgJ6g6Bi9AjHHQ5h9AgHv4ulZX5nshGkwSoE2uTpvFfakbTXMr8ZO tZZlIUykcKa6gXwCuE4hY15q88srY6oFRXcnCA2V71p3hvA3Etpp35S+bO5ApAa6GZt3 sLao9SSmGL34EhtREhC7/IPpAFTzNaeIO1IPN2CpB94/0OzixHd8RXb0zXZtxkFvy6yo 1/16pTI6gubKMJL+YbMlhS9vcM+Xy+PLmKUHUde+McS2UD0la55ZAmZGKbHIijf3r0GQ //EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=rQ4pnTg/b1WnCUPAG3BLG6Oa++Mq7xpke3ZBdL8YgWk=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=qjwL1yUM//jivyXk5y1FuN8zUTlTV6izgdJ7nC7veLq1zpWBMRgfQgWNTyMTEsNQGA objgkOC8MvDH3kmno/6TZKnVd0Qo6IWrw8QttR1xL9sIz3YbsJ0ou2//VytjPujd1jUj opHNbRcWpjJxo1EIR9RJlEt7Ci+aKo5eCydb2LPTnwYXycK/UotchmldK3rKxd7FFxS2 annIXX6KWNBJGWwRLtO6Ky7P1WhvDAAXV/HlxW3DKZuIT+tWtzzQaC1jHAVrgluza1IR Sp8hIaspt3Ys9vLlrvKBpNUZC/r+eIbW+z/2PqgMd+9dqBOooIM8QeblxpNIRZavhBx+ gbpA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c8058d987si215021666b.30.2024.06.07.11.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:55:01 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5D966884D1; Fri, 7 Jun 2024 20:54:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 67CC4884D0; Fri, 7 Jun 2024 20:54:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 29B0788495 for ; Fri, 7 Jun 2024 20:53:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0FA9D1480; Fri, 7 Jun 2024 11:54:23 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAAD83F792; Fri, 7 Jun 2024 11:53:55 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Fabio Estevam , Sughosh Ganu Subject: [RFC PATCH 08/31] lmb: replcace the lmb_init_and_reserve() function Date: Sat, 8 Jun 2024 00:22:17 +0530 Message-Id: <20240607185240.1892031-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607185240.1892031-1-sughosh.ganu@linaro.org> References: <20240607185240.1892031-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean With the changes to make the Logical Memory Block(LMB) allocations persistent and with the common memory regions being reserved during board init, the lmb_init_and_reserve() API can be removed and replaced with a lmb_add_memory() API, which adds all the available memory to the LMB pool. Signed-off-by: Sughosh Ganu --- arch/arm/mach-apple/board.c | 2 +- arch/arm/mach-snapdragon/board.c | 2 +- arch/arm/mach-stm32mp/stm32mp1/cpu.c | 2 +- cmd/bdinfo.c | 2 +- cmd/load.c | 2 +- fs/fs.c | 2 +- include/lmb.h | 12 +++++++++++- lib/lmb.c | 15 +++++++++++---- net/tftp.c | 2 +- net/wget.c | 2 +- test/cmd/bdinfo.c | 10 +--------- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c index c877c7b94c..2e72d03edd 100644 --- a/arch/arm/mach-apple/board.c +++ b/arch/arm/mach-apple/board.c @@ -776,7 +776,7 @@ int board_late_init(void) { u32 status = 0; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); /* somewhat based on the Linux Kernel boot requirements: * align by 2M and maximal FDT size 2M diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index a63c8bec45..b3c9a21419 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -282,7 +282,7 @@ int board_late_init(void) { u32 status = 0; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); /* We need to be fairly conservative here as we support boards with just 1G of TOTAL RAM */ status |= env_set_hex("kernel_addr_r", addr_alloc(SZ_128M)); diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c index a223297034..8e3f001f74 100644 --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c @@ -143,7 +143,7 @@ int mach_cpu_init(void) void enable_caches(void) { /* parse device tree when data cache is still activated */ - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); /* I-cache is already enabled in start.S: icache_enable() not needed */ diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c index e08d3e2cf3..fc408e9820 100644 --- a/cmd/bdinfo.c +++ b/cmd/bdinfo.c @@ -163,7 +163,7 @@ static int bdinfo_print_all(struct bd_info *bd) bdinfo_print_num_l("multi_dtb_fit", (ulong)gd->multi_dtb_fit); #endif if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); lmb_dump_all_force(); if (IS_ENABLED(CONFIG_OF_REAL)) printf("devicetree = %s\n", fdtdec_get_srcname()); diff --git a/cmd/load.c b/cmd/load.c index f019111991..9918523806 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -154,7 +154,7 @@ static ulong load_serial(long offset) int line_count = 0; long ret; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); while (read_record(record, SREC_MAXRECLEN + 1) >= 0) { type = srec_decode(record, &binlen, &addr, binbuf); diff --git a/fs/fs.c b/fs/fs.c index 3c54eaa366..f72d3962d1 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -549,7 +549,7 @@ static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, if (len && len < read_len) read_len = len; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); lmb_dump_all(); if (lmb_alloc_addr(addr, read_len) == addr) diff --git a/include/lmb.h b/include/lmb.h index f3e3f716e5..03bce2a50c 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -84,7 +84,17 @@ struct lmb { struct lmb_region reserved; }; -void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob); +/** + * lmb_add_memory() - Add memory range for LMB allocations + * @bd: pointer to board info structure + * + * Add the entire available memory range to the pool of memory that + * can be used by the LMB module for allocations. + * + * Return: None + * + */ +void lmb_add_memory(struct bd_info *bd); long lmb_add(phys_addr_t base, phys_size_t size); long lmb_reserve(phys_addr_t base, phys_size_t size); /** diff --git a/lib/lmb.c b/lib/lmb.c index 5c056800c3..de5a2cf23b 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -240,8 +240,17 @@ void lmb_reserve_common(void *fdt_blob) efi_lmb_reserve(); } -/* Initialize the struct, add memory and call arch/board reserve functions */ -void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob) +/** + * lmb_add_memory() - Add memory range for LMB allocations + * @bd: pointer to board info structure + * + * Add the entire available memory range to the pool of memory that + * can be used by the LMB module for allocations. + * + * Return: None + * + */ +void lmb_add_memory(struct bd_info *bd) { int i; @@ -249,8 +258,6 @@ void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob) if (bd->bi_dram[i].size) lmb_add(bd->bi_dram[i].start, bd->bi_dram[i].size); } - - lmb_reserve_common(fdt_blob); } /* This routine called with relocation disabled. */ diff --git a/net/tftp.c b/net/tftp.c index 02a5ca0f9f..54ac5e1262 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -714,7 +714,7 @@ static int tftp_init_load_addr(void) #ifdef CONFIG_LMB phys_size_t max_size; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); max_size = lmb_get_free_size(image_load_addr); if (!max_size) diff --git a/net/wget.c b/net/wget.c index dbdc519946..87f2f33c8a 100644 --- a/net/wget.c +++ b/net/wget.c @@ -76,7 +76,7 @@ static int wget_init_load_size(void) { phys_size_t max_size; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); max_size = lmb_get_free_size(image_load_addr); if (!max_size) diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c index 31d5e28105..8ba785fc31 100644 --- a/test/cmd/bdinfo.c +++ b/test/cmd/bdinfo.c @@ -114,14 +114,6 @@ static int lmb_test_dump_region(struct unit_test_state *uts, end = base + size - 1; flags = rgn->region[i].flags; - /* - * this entry includes the stack (get_sp()) on many platforms - * so will different each time lmb_init_and_reserve() is called. - * We could instead have the bdinfo command put its lmb region - * in a known location, so we can check it directly, rather than - * calling lmb_init_and_reserve() to create a new (and hopefully - * identical one). But for now this seems good enough. - */ if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) { ut_assert_nextlinen(" %s[%d]\t[", name, i); continue; @@ -201,7 +193,7 @@ static int bdinfo_test_all(struct unit_test_state *uts) if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { struct lmb lmb; - lmb_init_and_reserve(gd->bd, (void *)gd->fdt_blob); + lmb_add_memory(gd->bd); ut_assertok(lmb_test_dump_all(uts, &lmb)); if (IS_ENABLED(CONFIG_OF_REAL)) ut_assert_nextline("devicetree = %s", fdtdec_get_srcname());