From patchwork Wed Aug 21 10:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 820960 Delivered-To: patch@linaro.org Received: by 2002:adf:e98a:0:b0:367:895a:4699 with SMTP id h10csp639673wrm; Wed, 21 Aug 2024 04:00:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVSBvjIwbGGHEvtiDqfV8+w4wf9bKjvID3s6oXFkxWxRyz4zn4SSQgGPG7ud+QuEp8IRKie+g==@linaro.org X-Google-Smtp-Source: AGHT+IEox56mbP0/HQvPuC2HwQ63KBrMVA34jmB4p9ir3/SrlndSxXz0wr0jg+A+C8FdDU54X7NU X-Received: by 2002:a2e:e09:0:b0:2ee:88d8:e807 with SMTP id 38308e7fff4ca-2f3f88a6e99mr10981541fa.16.1724238043694; Wed, 21 Aug 2024 04:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724238043; cv=none; d=google.com; s=arc-20160816; b=xFHPO1PUUa9GNUS1iltg7V6gZncO9IYDr/RLL59QeiREw954iixNW7zfqL1Rh54/8B J5OZ1krsvdp2WL8EEXzriiDlIiQyakaX1jAJAGwXrkaIg37BzxoVNVUmqJ/PL4NJasCB XiyGQwsDCu64KJIxJ6nygL3qGwPf2lT6C2tyWY8DCyPrVrweEFLb8hyoDVRkkEAKP2u3 d9iwFSaHwv42yzh0Ft7QBF2v28r9X0d3bo2lmjQ86/C2yfOAARlZB5gGDmpbzOvaL/6f WifERcOjyljKUtBYhTDoyNXjfEdSlJYbN1IuVNbwB1wPpwzqRLrqyHbIutmZIOVa+d87 571A== 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=HA5DV5OUTBlIMXhHa2/l/IHkuM4gbHoVbLUPcDLBrvM=; fh=pnMZGD6unUPoMrkOwzXlkuYg+kVwGnSNRCTlQoWqjVc=; b=qEfK+wIPg+A4m4fyRin/pjaHsY7zmnxtrTQKGEaH/EihgD61WoXIISDR9QT6EIsO+4 NKhobHaXcShQk0qT8JtjGWXd5wrY3pd06cDL4NY8/jGNGouIx0Fz2/aAIZEf6F9EXlJy BVjm+1rgG2RXBPsdR9HLu2Yc/pvmUKKsdTwnsSFA066a1sOssf+6o5nlRb8v66UceGp/ R8yJB/sh3xszUnRXlFA3QmuhYoEyduW/vllN8ZcqqpW1zmfPwrlW0qmC2jw5R50O8U3x Esn6giXnacCWl/uq2oqT0PiHWD3IGBCAk1Znd2IxgSjnDfnuOpo20cC7JgWQZlLViA5v 1+pA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5bebc089687si8337187a12.408.2024.08.21.04.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 04:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 1697488D97; Wed, 21 Aug 2024 12:59:40 +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 2E92488C36; Wed, 21 Aug 2024 12:59:39 +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 36A9088D96 for ; Wed, 21 Aug 2024 12:59:37 +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 BE1DDDA7; Wed, 21 Aug 2024 04:00:02 -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 5D1723F73B; Wed, 21 Aug 2024 03:59:33 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Simon Glass , Tom Rini , Ilias Apalodimas , Heinrich Schuchardt , Marek Vasut , Mark Kettenis , Michal Simek , Patrick DELAUNAY , Patrice CHOTARD , Sughosh Ganu Subject: [PATCH v3 10/27] lmb: introduce a function to add memory to the lmb memory map Date: Wed, 21 Aug 2024 16:28:22 +0530 Message-Id: <20240821105839.2870293-11-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821105839.2870293-1-sughosh.ganu@linaro.org> References: <20240821105839.2870293-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 V2: * Do not define lmb_add_memory() as a weak function. include/lmb.h | 11 +++++++++++ lib/lmb.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index d0f1b65fb6..3f766caa45 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -66,6 +66,17 @@ int lmb_init(void); void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob); void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size, void *fdt_blob); + +/** + * 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 e85ee0a90b..b07235247f 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -246,6 +246,43 @@ void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size, lmb_reserve_common(fdt_blob); } +/** + * 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) +{ + 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) @@ -695,6 +732,8 @@ int lmb_init(void) return ret; } + lmb_add_memory(); + return 0; }