From patchwork Wed Aug 14 10:59:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 819117 Delivered-To: patch@linaro.org Received: by 2002:adf:cd01:0:b0:367:895a:4699 with SMTP id w1csp645395wrm; Wed, 14 Aug 2024 04:03:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWGbCAoBAV2KYTPFgPgAca1EmRxGLEhF03Hw9biNXGRGfTK+NbpzwIvufvMIZVnrr2WiQeaAHY9kLZ7XYlMnp+B X-Google-Smtp-Source: AGHT+IF9kFUiv97/NHfyV0pdrJMP1JFhAzH6sUa//hjWREnF5P0pGspXNkxLpAtVSEvhP9GMotIN X-Received: by 2002:a2e:d11:0:b0:2ef:2f19:a8b3 with SMTP id 38308e7fff4ca-2f3aa2fa3afmr13460601fa.41.1723633394234; Wed, 14 Aug 2024 04:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723633394; cv=none; d=google.com; s=arc-20160816; b=TSU6Ui8gcjbhIq5sl0hQ9dtW7cQ12/wxARI/9x2G+/2VT6o3SYur3ngs6q1MXQdgei TLs6UxYQTRdRFARxDwR4UgrhIFoHgYoIGMZoVPibq1F9EdPXX4F+KwDnGDk0JL8/MDVo qYzPh81Snd+ZFGzZIpbTOnl67QuAX6yIF5xqLU9FUVr1asfv10yX/fn/K0+efwLiHVkj oThKUOdGwLa88eYq5OdR3aaWzE8+HEI0ll3lXhX0HZoMFzmOLsGC15639f2+MN3wQmCd g5062Tc3roqMHXASf+TfJQ5NJ+BF+5ExGPeSAg5WzNguW/XmcAf6xbKelYT7TVqGftP2 pb5w== 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=/AtKhaN69gLrKwd9wEcC7VGIkQzZokKrLVJ55ss0w8c=; fh=w4WyT9xL7ErtT1TeetrD/m0Y0mAgjnERgxacGUpGjSg=; b=MMJtjGXc4mkDbixwr02m8LO8a/CKiI05/qNEGuueILarzZqXeI+ChJuK7Ku46C0QdR YphPHWBd7tkk1lKZIgD/fQvLuwB4qxz44975rUo0Ppue8jXQ5KH78r9i8REP5EBGx1mP KhHbZ74sFaZEFguL9hBHsyqjl4vz48Sp+38z/pWVM8xAs9bQ0lWU3i96iIOHR+tJZrs/ MY4PnBqiyHYBPMCnbEW9R2cnwoVIHexFWMcKK4WB7NRufwClDYapF+6SnXGErdoJgepK e0vdnrWe7gDcdpQRpml/Oq2ykvtsVL5nLVKrWN3CudLUI5/bNqxQaEShm3QjeXRn5R93 Uu2w==; 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 4fb4d7f45d1cf-5bd1a63aac0si5381088a12.637.2024.08.14.04.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 04:03:14 -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 D447788A4B; Wed, 14 Aug 2024 13:01:46 +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 694DE889CA; Wed, 14 Aug 2024 13:01:45 +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 6830688A2F for ; Wed, 14 Aug 2024 13:01:43 +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 CC591DA7; Wed, 14 Aug 2024 04:02:08 -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 583D13F58B; Wed, 14 Aug 2024 04:01:38 -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 14/32] lmb: introduce a function to add memory to the lmb memory map Date: Wed, 14 Aug 2024 16:29:51 +0530 Message-Id: <20240814110009.45310-15-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 Introduce a function lmb_add_memory() to add available memory to the LMB memory map. Call this function during board init once the LMB data structures have been initialised. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass --- Changes since V1: * Call the lmb_add_memory() from lmb_init() instead of lmb_mem_regions_init(). include/lmb.h | 10 ++++++++++ lib/lmb.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index f6b2a81546..a82ea63d6c 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -63,6 +63,16 @@ struct lmb { */ int lmb_init(void); +/** + * lmb_add_memory() - Add memory range for LMB allocations + * + * 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(void); + 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 3ccee26a46..f35a94c41b 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -225,6 +225,46 @@ static void lmb_reserve_common(void *fdt_blob) efi_lmb_reserve(); } +/** + * lmb_add_memory() - Add memory range for LMB allocations + * + * Add the entire available memory range to the pool of memory that + * can be used by the LMB module for allocations. + * + * This can be overridden for specific boards/architectures. + * + * Return: None + * + */ +__weak void lmb_add_memory(void) +{ + int i; + phys_size_t size; + phys_addr_t rgn_top; + u64 ram_top = gd->ram_top; + struct bd_info *bd = gd->bd; + + /* Assume a 4GB ram_top if not defined */ + if (!ram_top) + ram_top = 0x100000000ULL; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + size = bd->bi_dram[i].size; + if (size) { + if (bd->bi_dram[i].start > ram_top) + continue; + + rgn_top = bd->bi_dram[i].start + + bd->bi_dram[i].size; + + if (rgn_top > ram_top) + size -= rgn_top - ram_top; + + lmb_add(bd->bi_dram[i].start, size); + } + } +} + static long lmb_resize_regions(struct alist *lmb_rgn_lst, unsigned long idx_start, phys_addr_t base, phys_size_t size) @@ -674,5 +714,7 @@ int lmb_init(void) return ret; } + lmb_add_memory(); + return 0; }