From patchwork Wed Aug 14 10:59:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 819118 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp645492wrm; Wed, 14 Aug 2024 04:03:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0cLgDuEfPJW3NkMrkUZmS0NkQ7JnnJXSeqXdgAtgNiFeITiksQWCxPhXcsbG3zsq9TY0OpOFbdz5YwKN4aZA4 X-Google-Smtp-Source: AGHT+IGuEIPtmRTr4wYVNfjncVz12iofs+ojrJNSaYIRXwEhpdnJ33Bp8RQtmqRIUa00uIBnWnxU X-Received: by 2002:a17:907:e24c:b0:a77:e1fb:7dea with SMTP id a640c23a62f3a-a8366c1f2eemr180678866b.2.1723633404592; Wed, 14 Aug 2024 04:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723633404; cv=none; d=google.com; s=arc-20160816; b=nohSHFOwB9Vcplni5WnhnPCbH/xbpOab/PUQziDHe0E+ArynyG+Az3oPyfq0X0mJrC 9klhShHgSmxeNhUjN+zcddrd1YbSi4bBRrek+o9sAQ4Lgn8eSuuhpPJUsHAimUZ6PzIF H5SCC7RbSvlJFNl3s5JSF7BHrAgw06hUPpJjUA758qkqKOUhVTbZMFI+Efxvyb9bnAui 7jBzBF2YbuMFGUfuLlWyx7J+sML7m7gmQG06A6rsxFC+WUNT2EVzEqZPOkqz4PcNydjC 66hgam5OmWh+sRnfWzw+VI7bC+g9+We2e+eu6Eh33Ts8Ovlr6//D6YU3iw8GMxjEAWvx K83w== 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=+e8HOe8ZXGRUMB5xRmnzajVoYHrgxR7iAsXLprCyMfs=; fh=w4WyT9xL7ErtT1TeetrD/m0Y0mAgjnERgxacGUpGjSg=; b=hkYdDi+69b1SgmAGGwAFNfI6YqK4ukRrZuZJ04VMynroGPaXY8hOc9oVf+fJcERUlu ZU3wnLoJoguEVg3XlEn1NDAxy75f4e/ZzU3P8KoihZ3k/o9op2vDL8onWk1VjeWKlF3+ OvuhfkTWz04hIRBCP2pGY+SrUYD34D3aO4Z1VEIhwcKgfcmEVd1MIewbCSqYzcan7Qxo Xlst8ek0vPch5lJekhhJyYbWzj8Tpan6eb90cu40GuESHOxVUEdtYzRag5mag1+Qod+5 Uvjc8DFS3NTbw3IEfDEiWF8yjWDPQk7HCLnysiXQL3PhfuRqk7NiNPBYHVry8blMp74K 6edg==; 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-a80f4150eecsi195838766b.667.2024.08.14.04.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 04:03:24 -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 3F1F288763; Wed, 14 Aug 2024 13:01:51 +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 AA06B882E6; Wed, 14 Aug 2024 13:01:50 +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 7309B889DA for ; Wed, 14 Aug 2024 13:01:48 +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 D7E58DA7; Wed, 14 Aug 2024 04:02:13 -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 645613F58B; Wed, 14 Aug 2024 04:01:43 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Tom Rini , Mark Kettenis , Michal Simek , Patrick DELAUNAY , Patrice CHOTARD , Huan Wang , Angelo Dureghello , Daniel Schwierzeck , Thomas Chou , Rick Chen , Max Filippov , Sughosh Ganu Subject: [PATCH v2 15/32] lmb: reserve common areas during board init Date: Wed, 14 Aug 2024 16:29:52 +0530 Message-Id: <20240814110009.45310-16-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240814110009.45310-1-sughosh.ganu@linaro.org> References: <20240814110009.45310-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 The LMB module provides API's for allocating and reserving chunks of memory which is then typically used for things like loading images for booting. Reserve the portion of memory that is occupied by the U-Boot image itself, and other parts of memory that might have been marked as reserved in the board's DTB. When executing in SPL, reserve the sections that get relocated to the ram memory, the stack and the global data structure and also the bss. Mark these regions of memory with the LMB_NOOVERWRITE flag to indicate that these regions cannot be re-requested or overwritten. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass --- Changes since V1: None lib/lmb.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index f35a94c41b..a661dd2c4c 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -172,10 +173,11 @@ void arch_lmb_reserve_generic(ulong sp, ulong end, ulong align) if (bank_end > end) bank_end = end - 1; - lmb_reserve(sp, bank_end - sp + 1); + lmb_reserve_flags(sp, bank_end - sp + 1, LMB_NOOVERWRITE); if (gd->flags & GD_FLG_SKIP_RELOC) - lmb_reserve((phys_addr_t)(uintptr_t)_start, gd->mon_len); + lmb_reserve_flags((phys_addr_t)(uintptr_t)_start, + gd->mon_len, LMB_NOOVERWRITE); break; } @@ -225,6 +227,30 @@ static void lmb_reserve_common(void *fdt_blob) efi_lmb_reserve(); } +static __maybe_unused void lmb_reserve_common_spl(void) +{ + phys_addr_t rsv_start; + phys_size_t rsv_size; + + /* + * Assume a SPL stack of 16KB. This must be + * more than enough for the SPL stage. + */ + if (IS_ENABLED(CONFIG_SPL_STACK_R_ADDR)) { + rsv_start = gd->start_addr_sp - 16384; + rsv_size = 16384; + lmb_reserve_flags(rsv_start, rsv_size, LMB_NOOVERWRITE); + } + + if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) { + /* Reserve the bss region */ + rsv_start = (phys_addr_t)(uintptr_t)__bss_start; + rsv_size = (phys_addr_t)(uintptr_t)__bss_end - + (phys_addr_t)(uintptr_t)__bss_start; + lmb_reserve_flags(rsv_start, rsv_size, LMB_NOOVERWRITE); + } +} + /** * lmb_add_memory() - Add memory range for LMB allocations * @@ -716,5 +742,11 @@ int lmb_init(void) lmb_add_memory(); + /* Reserve the U-Boot image region once U-Boot has relocated */ + if (spl_phase() == PHASE_SPL) + lmb_reserve_common_spl(); + else if (spl_phase() == PHASE_BOARD_R) + lmb_reserve_common((void *)gd->fdt_blob); + return 0; }