From patchwork Wed Jul 24 06:02:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 814140 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2618641wro; Tue, 23 Jul 2024 23:07:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXuAlng77tjz8yPINzEWRdWogrn6ju/Esc6BMx9/GT5l5ta4SfWcrRE2/0e5SVRuNctgDlCDzVvkt2a4Qx4MjuV X-Google-Smtp-Source: AGHT+IEfKlMeuAn9vVnnhgsnYFMCUGFW635Bvvbw5Z8XCazwL69j8GZN9lxJWnLVx6Yfjt3NZvyI X-Received: by 2002:a05:600c:35cc:b0:423:791:f446 with SMTP id 5b1f17b1804b1-427f9541ce2mr6571865e9.7.1721801238329; Tue, 23 Jul 2024 23:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721801238; cv=none; d=google.com; s=arc-20160816; b=SKMLvS40I1AT+7stjweSAF4o/kSnxiDeKw+0AxbghJ26Lcy7N/TSdlmuZjd7Z0C+hg E0uUkR5Kvmco27cbXiZXbyPF0PPwzl/iohbiwJOZ/vRTXFpWiyY6ptSmMwvtFjgLZhNS Rjl09SoJO4sGrSeZ4kJ0KEIeU20RAdyBiVxOSFkBQDheOj+NMbPAN6rje9pTWD9ugZgg 3bDBsdIaOhCf1ByE7a8pkHvMdar/5dOvmojYbwklT/OXq936Tu9qdxF71k5inOJQph1k 2a7KrRiqIrtR3Yq008mohJB2JNtMR8k5/sqEIGgHSUS/ex8n0u6xnAx+dFHxqT93uJNZ eRbw== 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=ZN0jVbPDf97Aej7wHty79YZ9MbyWI3wU4stXbp72xqw=; fh=eimiGswTlodK8yi2DcDfSicmKwvq5bxKQKpD+SkkTNY=; b=Mj8W7f44SUxgNFBQQZzRAMhAjoCRBEnsFE2y3s5rRrR6uLP4hQaC9IhZgdv2MRAkpq KnRH14cRMnQQxCNpfUPAlVhlxoUYyH4TWqrnMPPrtaT48POD4drai7ty2ycsFdm0Tn4C cU1ezSiNRnRCJ5Jyp508qYc3xQisY7r1o/ICMJMvVjxA0O2DBNihvWv8xQXF9soGvZBI a7LlKpiJNxgUL5w1m1MxZbfoCDf/Q1NL8bdWs8aSo2wTlDHOWGftgYWjd/vi0XNeuRsy iJoafpXu17wwe3DxssNTLP1ksX80Tc+A7SxETYlw5rtikEXUzdfPRBmO2JrCWPJuJjT9 TS7Q==; 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 ffacd0b85a97d-369e3818994si1336366f8f.537.2024.07.23.23.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 23:07:18 -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 8482A888F8; Wed, 24 Jul 2024 08:04:18 +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 787FD888F5; Wed, 24 Jul 2024 08:04:16 +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 6D42188805 for ; Wed, 24 Jul 2024 08:04: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 5F617106F; Tue, 23 Jul 2024 23:04:36 -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 48BFD3F766; Tue, 23 Jul 2024 23:04:06 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Marek Vasut , Mark Kettenis , Michal Simek , Patrick DELAUNAY , Patrice CHOTARD , Huan Wang , Angelo Dureghello , Daniel Schwierzeck , Thomas Chou , Rick Chen , Max Filippov , Sughosh Ganu Subject: [PATCH 17/40] lmb: introduce a function to add memory to the lmb memory map Date: Wed, 24 Jul 2024 11:32:01 +0530 Message-Id: <20240724060224.3071065-18-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240724060224.3071065-1-sughosh.ganu@linaro.org> References: <20240724060224.3071065-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 rfc: None include/lmb.h | 12 ++++++++++++ lib/lmb.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/lmb.h b/include/lmb.h index a308796d58..77e2a23c0d 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -40,6 +40,18 @@ struct lmb_region { 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 88352e9a25..db0874371a 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) @@ -728,5 +768,7 @@ int lmb_mem_regions_init(void) return -1; } + lmb_add_memory(); + return 0; }