From patchwork Mon Aug 26 11:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 822444 Delivered-To: patch@linaro.org Received: by 2002:adf:e044:0:b0:367:895a:4699 with SMTP id w4csp1476908wrh; Mon, 26 Aug 2024 05:01:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXFWW21COX+p/UIbt2Sw/wwcqj8CBfgMEY9qDKfsonBgLtKhTMH5hxIhSeg7oA3IfpV5hMHoA==@linaro.org X-Google-Smtp-Source: AGHT+IGeqKN7Antssy1so5l1ya9zEYkH3WiWsRuNPWWQvAmhtqgfxm7CIRGiXvLhT44vPxYWjLQI X-Received: by 2002:a05:600c:4f84:b0:429:994:41a2 with SMTP id 5b1f17b1804b1-42acd53455dmr55153135e9.7.1724673706833; Mon, 26 Aug 2024 05:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724673706; cv=none; d=google.com; s=arc-20160816; b=qvA6IvlHAo84Oj5ApPz/8Fk/Ez0IPVeVVjbK9Pjzbvy1WMmEUaMsS3mVAkWlHNsWv0 kIVKfAM5SApZ7AIFY+7d6Ab1jPM0TemY3SYhEN94maiBWyT5p5c1KBqejABgDyTqo4Tr okH3PRNONPcsvqSXauGpeSSisIhtwJjJ5jm3MMNVI3E1IQx2PW/FCrIJ5fhdz+HXQzYW 8jMHn4p+7hddgZbfAY2872acXaPph8IziIM88q015jy6BB81wcB2kQgYQzBc84S4wU1B x4/k/CVutEP2mwh55u2ic00A1FDbsDlAlAkH5m/uj9z7yA9Lq1xo6Buq/dRzXdfKIlUg LJ/A== 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=/48g5R156aiQrYuOVdr4qTYScjohoow9f/SvZcTtzqg=; fh=8IbOOFAUJYCfGYrzM0jWqtoOP7AaZuPOmdHZ5mvNk1Q=; b=tj8KFNpgzOEdBCg2B95C62GQUJ29FF2aWtULXujsxN+ijaHWGWFLwb2PcmR8+4fRsn mPWzwrSHjANCXCEvHhTqx6sEuQx2s39GyXdEezrQgeaziu6Wm9GarCy2yZEHe+lbvDc7 m1MenHN+OTlmG2DSDvnwohyi0l97xhJw+uH/Z9zNxB3ijzPZXwCD5s2+UC3s7mK05VDV chYUIJ0FflH6RNHYdkk/JTPXwj8EGGjKmYDB+gFX2gq7ySG0G9GrFSAQ+xLpNwGReDsY k3txAIgfadR2zRtEmE74fJjFLLz8WMN6Swrxu/uKpo/nKtVDmoGj4Dn7/EUtKjYqlqSV VOvA==; 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 ffacd0b85a97d-373082002b1si3513732f8f.470.2024.08.26.05.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 05:01:46 -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 4902188A82; Mon, 26 Aug 2024 14:00: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 0FBB088A82; Mon, 26 Aug 2024 14:00:51 +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 0E96782BA7 for ; Mon, 26 Aug 2024 14:00:49 +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 B038BDA7; Mon, 26 Aug 2024 05:01:14 -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 CD1AF3F762; Mon, 26 Aug 2024 05:00:44 -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 , =?utf-8?q?Marek_Beh=C3=BAn?= , Sughosh Ganu Subject: [PATCH v4 10/27] lmb: introduce a function to add memory to the lmb memory map Date: Mon, 26 Aug 2024 17:29:23 +0530 Message-Id: <20240826115940.3233167-11-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826115940.3233167-1-sughosh.ganu@linaro.org> References: <20240826115940.3233167-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 V3: None include/lmb.h | 11 +++++++++++ lib/lmb.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index cc2c426c13..70191456e5 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 8be0c1a583..44ecf96811 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) @@ -696,6 +733,8 @@ int lmb_init(void) return ret; } + lmb_add_memory(); + return 0; }