From patchwork Fri Jun 7 18:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 802317 Delivered-To: patch@linaro.org Received: by 2002:adf:f147:0:b0:35b:5a80:51b4 with SMTP id y7csp948833wro; Fri, 7 Jun 2024 11:54:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW/hytIPLJ4KIPJLM49+21N9ZJ0fzs6/xkvyD98u09g5OXLo/rg2jMhjYQ392Wne296NW0g9UC/Eu65I/dngQnH X-Google-Smtp-Source: AGHT+IHlI0aHQhdoeFFT2SJe5fWrpzKkLBmlCC1e63W3Yl5bmDsgCP8iNlAknWbsEIg3i0nCv28/ X-Received: by 2002:a05:6512:46f:b0:52b:c23f:9451 with SMTP id 2adb3069b0e04-52bc23f949cmr845788e87.38.1717786481315; Fri, 07 Jun 2024 11:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717786481; cv=none; d=google.com; s=arc-20160816; b=fOenoohcD/CHwkEpRaXm4sZ7cP4umHPKPeuMF77NtJ52xVNumnoz0GWcmPEVeim/eF 6ru1x76Q0JqH7aLu71neSdqItZgbpv6quK7L23PiibC6vMRNfs1ttUt4AsRVRK8Vjw78 BOoxB0nGbKCTPMsuZeMw5rfYeiAwQolTmjCQcMA5JOZyPAfJt/UwAVwZkrty9vV5sjwZ 2ndvHDfBAInlTS3TzsqkL0OhHX4vhfSttD7/NUh9nx42zNtyKL2sFpE6xR8aNdIOP//C lJwUb/NWF32nPEeadcr0b7kViPXLkDwqTvTJgAfYYU5LwK9dpIBG/3S1I1YKKUz8Pivp ITxA== 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=bylpVaz0Vxn5wSHZl5GFf7OpmDhENobpT1/L4ZXDwus=; fh=xLSOOz5Q0Mrmzd+lwBRTYS7D/8TpUWM8TEHgIjpMzow=; b=Vu0IjVDBzgRcWImGTv5i4OxOE+hBRIT/RJFKxCBzLe/q+9grJky7TI9HkSIE6la/nb dN68TKc9ejD5CAPCdjjwKLMUlA10EjXAeiqm4X3lp2zxFwW6neTXqc+PPOs61KNzZ/XR TuCCXDf0GIAdfez45oV1DVFsg+dMVhA/mxkCnzjNi5eqPf6VsviHYwDZUU6Ih5PTso8K U9M+8/t28wm3XGvP6luE+HgESPWzPwoYE8zjF7dPheh009/ixmZGmXgyyAlrWwiZ6ORc JpVC3+orbvj34fJjqL1TH1J3OtLQ4/diivoNYDZWGmO1baKQhAa3Il9ESPPR8aSXWQnm sdYw==; 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-a6c80708872si217967766b.676.2024.06.07.11.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:54:41 -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 9C9FD88498; Fri, 7 Jun 2024 20:53:57 +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 A1C32884B8; Fri, 7 Jun 2024 20:53:56 +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 D05E8884AC for ; Fri, 7 Jun 2024 20:53:52 +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 B04FC1480; Fri, 7 Jun 2024 11:54:16 -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 9813E3F8A4; Fri, 7 Jun 2024 11:53:49 -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 06/31] lmb: reserve and add common memory regions post relocation Date: Sat, 8 Jun 2024 00:22:15 +0530 Message-Id: <20240607185240.1892031-7-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 The LMB module provides API's for allocating chunks of memory. The LMB module should not be allocating memory regions that are in use, or that might be occupied by the U-Boot image. Prevent allocations of memory areas used by the U-Boot image by reserving these regions once U-Boot has been relocated. Also add the rest of the memory that is available for allocations to the LMB's memory map. Signed-off-by: Sughosh Ganu Reviewed-by: Tom Rini --- common/board_r.c | 15 +++++++++++++++ include/lmb.h | 14 ++++++++++++++ lib/lmb.c | 14 +++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/common/board_r.c b/common/board_r.c index da0b80f24f..a9f0b0cec1 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -555,6 +556,17 @@ static int run_main_loop(void) return 0; } +#if defined(CONFIG_LMB) +static int initr_lmb(void) +{ + lmb_reserve_common((void *)gd->fdt_blob); + + lmb_add_memory(gd->bd); + + return 0; +} +#endif + /* * Over time we hope to remove these functions with code fragments and * stub functions, and instead call the relevant function directly. @@ -613,6 +625,9 @@ static init_fnc_t init_sequence_r[] = { #endif #ifdef CONFIG_EFI_LOADER efi_memory_init, +#endif +#if defined(CONFIG_LMB) + initr_lmb, #endif initr_binman, #ifdef CONFIG_FSP_VERSION2 diff --git a/include/lmb.h b/include/lmb.h index 8f8a32c2ca..d2b829ace1 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -125,6 +125,20 @@ void board_lmb_reserve(void); void arch_lmb_reserve(void); void arch_lmb_reserve_generic(ulong sp, ulong end, ulong align); +/** + * lmb_reserve_common() - Reserve memory region occupied by U-Boot image + * @fdt_blob: pointer to the FDT blob + * + * Reserve common areas of memory that are occupied by the U-Boot image. + * This function gets called once U-Boot has been relocated, so that any + * request for memory allocations would not touch memory region occupied + * by the U-Boot image, heap, bss etc. + * + * Return: None + * + */ +void lmb_reserve_common(void *fdt_blob); + #endif /* __KERNEL__ */ #endif /* _LINUX_LMB_H */ diff --git a/lib/lmb.c b/lib/lmb.c index b0c9e2ef30..8003aae6f7 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -216,7 +216,19 @@ static __maybe_unused int efi_lmb_reserve(void) return 0; } -static void lmb_reserve_common(void *fdt_blob) +/** + * lmb_reserve_common() - Reserve memory region occupied by U-Boot image + * @fdt_blob: pointer to the FDT blob + * + * Reserve common areas of memory that are occupied by the U-Boot image. + * This function gets called once U-Boot has been relocated, so that any + * request for memory allocations would not touch memory region occupied + * by the U-Boot image, heap, bss etc. + * + * Return: None + * + */ +void lmb_reserve_common(void *fdt_blob) { arch_lmb_reserve(); board_lmb_reserve();