From patchwork Thu Jul 4 07:35:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 809925 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1042873wru; Thu, 4 Jul 2024 00:39:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUQt5459xlN0sgQVLeGvC7IcUI//vJcSUPux3DRXTgJ3C8o6J+UIn+wOxLFMYf0WMdWNAPDy5IJo6sFDLa1lGWV X-Google-Smtp-Source: AGHT+IGlXEGgP7+0EToFDfJfRRWW1TZnv5+edWmLJoaz5dCSIc5Xx2U4cmMaimeDH3eojQZj4iJ4 X-Received: by 2002:a17:906:f287:b0:a72:b1a6:4f75 with SMTP id a640c23a62f3a-a77bdc1966emr49113466b.27.1720078774069; Thu, 04 Jul 2024 00:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720078774; cv=none; d=google.com; s=arc-20160816; b=c8m6i62dsQWOOveTd4Y9JkFynPcTAhq9/TA/aTE8LQwybNX2fOCdSHBC9xT91bSOXi 3Z1Ezitb7GYbKhhaa8Iut1SDJqppnYw6V3w9tWZP+wL0fI5AVjFJlSaZRb6LFE8E0NwM A0JK7P9aHml5LiMuKuCNFhlQqM5hNMK+SXmjG+aOBfa6wUEHink0JqLHhfyfV1wK4X3J FQ39k7D18sJUm0QQqSzpndhWVDkLS0kNh8IYbBhPM+X+0LfeTWi00CTJIw1bK6j6XhEM yEn3qnoPR+b+4/Z3XmPDNAvVCWrgBnKSBYSqtILz7GeCRWsC2a0gKUutyjcdB8fIMCCl RucA== 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=tcApE3tI3Jdle52MHaWWEzXiyUhjSjNZ7AKOx6QEVDM=; fh=ez1zzjhC0XWyqTp7tWutqrA/nFdALDnQKrnQnXYhk5Q=; b=tFg6WWfTtkzCrGJAe/uwQxqXTPL3wuNEOFsFoJ/6QZLGTI7U9mjt0rx1B9q13Szc4P 0UCqJ989ptjw8mUOgjPh6UO9kbCrTWFpHHP3i5Ntlep/Rf7BvabXFycFCmHwNpYRLUjd dm4/Hcia4bPlb0An5T6xrn5aN6zIBvOYZCpnmk0BwRhxi6hvMM0mH2V1t3OIBlYnr9Iv eEizUIqAXVmkN49stXvJjraK5UmjQifrfvYfoO6lYE476VUPHcYF+qgEzk0N4bpKWuIz 1BBPrCDtaeNAoxJim6ekTOUjZR4PX5dXaS6CLlBXzwYFOYErpOiEVEXheLb5RR+80Ly5 yJUg==; 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-a72aaef6a08si625535666b.207.2024.07.04.00.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 00:39:34 -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 12641888EA; Thu, 4 Jul 2024 09:37:14 +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 7DF44888A9; Thu, 4 Jul 2024 09:37:13 +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 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 3160588919 for ; Thu, 4 Jul 2024 09:37:11 +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 B16E51063; Thu, 4 Jul 2024 00:37:35 -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 8D6123F762; Thu, 4 Jul 2024 00:37:07 -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 , Michal Simek , Sughosh Ganu Subject: [RFC PATCH v2 18/48] lmb: introduce a function to add memory to the lmb memory map Date: Thu, 4 Jul 2024 13:05:14 +0530 Message-Id: <20240704073544.670249-19-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240704073544.670249-1-sughosh.ganu@linaro.org> References: <20240704073544.670249-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 --- Changes since V1: * Add memory only till ram_top to the LMB memory map, instead of all enumerated memory. include/lmb.h | 11 +++++++++++ lib/lmb.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index 27cdb18c37..d0c094107c 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -36,6 +36,17 @@ struct lmb_region { enum lmb_flags flags; }; +/** + * 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 a46bc8a7a3..e4733b82ac 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -239,6 +239,46 @@ void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob) 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. + * + * 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); + } + } +} + /* Initialize the struct, add memory and call arch/board reserve functions */ void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size, void *fdt_blob) @@ -710,5 +750,7 @@ int lmb_mem_regions_init(void) return -1; } + lmb_add_memory(); + return 0; }