From patchwork Tue Oct 15 15:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 835455 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c8f:0:b0:37d:45d0:187 with SMTP id z15csp301325wrs; Tue, 15 Oct 2024 08:39:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWaSLC6OCUWThnVLpZ164q+IKF1j70vYRBz7TO11lKTD6ZztF2kAzyUT3oYjfUxHY6cCV7dCQ==@linaro.org X-Google-Smtp-Source: AGHT+IHV/SNCeBDCluTS79hAIg4dO6Zb7cG4aLVJcRDqrVEKO8FLV0/lxNV39lkgGR6Y40slfksP X-Received: by 2002:a05:6602:6014:b0:83a:71c6:26fb with SMTP id ca18e2360f4ac-83a71c629ffmr863835839f.6.1729006774270; Tue, 15 Oct 2024 08:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729006774; cv=none; d=google.com; s=arc-20240605; b=RqwFhtsgp5hf07NF/wxNozJ/btI5gUle2aHxZMFGdOQnLg/i0tb6Bo5KdvrTvbGWc4 q2l4D3ifAu5dZ79PdPVL9SMfavp3JD2QN5pOchpBn1gkQRBEuPjOAt1n3ZLWtkoPYhSu diWYLlKN2sjPHPEdqaYDTUySFm1A3Nv7VztrKSyEuN3ALGMPj0E1oygBRbXrbZ3j3XAT 17Cji5YuylyVm0uXQp7yChqDtBpvtjg48NwkwophPQVVUl+P97ID2gXKkfgwE8ctmSnI suCpszKS3IvWs7T8O1BFS3Ez+KB11XQXR5SVF2lTKPaQTyqTh6sD7ZyeerfTCzPxQv1k QnzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=hrUc77vnuSH1koBMfq7RJWL3KE7G67Hd60uOmSDf7NA=; fh=MYvlzMqd61VHJORtkCu1tTA+qP9jRMJFkVEqSzDEdy8=; b=LgEQI1Fk4TCsy3INXiL6Ohqf7cBoIn1GKfVmgGmjhW3xV4lRWdIMzxnvJ0hfNSeBL/ +b0XWpFgkXn2jPevFEAuTBpKEtGFvVOLrA8bqPi0rX/2+DMOviOm/TXb6OCrjNQzGXjv iJ9yhIdxUHA/LMlfh1mdusDnse3OYQTs7dhWELFngvNalwpeTmKfEn9rgfBsvqVc6rcf 3zs3wobxeWpJrlFNW5bG0qowbk/EUY73BIvxA/6lkub8d18k2bDCF/wueEX54XDOM6Ml L5tnKLKg3D69jMHZ6TmNS4BdQnUl0xWG+mtpAqI59wA1H2M5pPME/5D25NoQD2InqIta X1Hg==; 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 ca18e2360f4ac-83a8b251cdbsi72506139f.75.2024.10.15.08.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 08:39:34 -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 CE29888D72; Tue, 15 Oct 2024 17:38:19 +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 5D07288D54; Tue, 15 Oct 2024 17:38:18 +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_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_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 4B44E88730 for ; Tue, 15 Oct 2024 17:38:16 +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 60DFB1713; Tue, 15 Oct 2024 08:38:45 -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 E1E893F528; Tue, 15 Oct 2024 08:38:12 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Tom Rini , Caleb Connolly , Jonas Karlman , Mark Kettenis , Sughosh Ganu Subject: [PATCH v4 11/15] x86: e820: use the lmb API for adding RAM memory Date: Tue, 15 Oct 2024 21:07:13 +0530 Message-Id: <20241015153717.401371-12-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015153717.401371-1-sughosh.ganu@linaro.org> References: <20241015153717.401371-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 The EFI_CONVENTIONAL_MEMORY type is now being managed through the LMB module. Add a separate function, lmb_arch_add_memory() to add the RAM memory to the LMB memory map. The efi_add_known_memory() function is now used for adding any other memory type to the EFI memory map. Signed-off-by: Sughosh Ganu --- Changes since V3: None arch/x86/lib/e820.c | 47 ++++++++++++++++++++++++++++++++++----------- lib/Kconfig | 2 +- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/arch/x86/lib/e820.c b/arch/x86/lib/e820.c index 122b4f7ca01..d478b7486e3 100644 --- a/arch/x86/lib/e820.c +++ b/arch/x86/lib/e820.c @@ -4,6 +4,7 @@ */ #include +#include #include #include @@ -41,15 +42,11 @@ void efi_add_known_memory(void) { struct e820_entry e820[E820MAX]; unsigned int i, num; - u64 start, ram_top; + u64 start; int type; num = install_e820_map(ARRAY_SIZE(e820), e820); - ram_top = (u64)gd->ram_top & ~EFI_PAGE_MASK; - if (!ram_top) - ram_top = 0x100000000ULL; - for (i = 0; i < num; ++i) { start = e820[i].addr; @@ -72,13 +69,41 @@ void efi_add_known_memory(void) break; } - if (type == EFI_CONVENTIONAL_MEMORY) { - efi_add_conventional_memory_map(start, - start + e820[i].size, - ram_top); - } else { + if (type != EFI_CONVENTIONAL_MEMORY) efi_add_memory_map(start, e820[i].size, type); - } } } #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ + +#if CONFIG_IS_ENABLED(LMB_ARCH_MEM_MAP) +void lmb_arch_add_memory(void) +{ + struct e820_entry e820[E820MAX]; + unsigned int i, num; + u64 ram_top; + + num = install_e820_map(ARRAY_SIZE(e820), e820); + + ram_top = (u64)gd->ram_top & ~EFI_PAGE_MASK; + if (!ram_top) + ram_top = 0x100000000ULL; + + for (i = 0; i < num; ++i) { + if (e820[i].type == E820_RAM) { + u64 start, size, rgn_top; + + start = e820[i].addr; + size = e820[i].size; + rgn_top = start + size; + + if (start > ram_top) + continue; + + if (rgn_top > ram_top) + size -= rgn_top - ram_top; + + lmb_add(start, size); + } + } +} +#endif /* CONFIG_IS_ENABLED(LMB_ARCH_MEM_MAP) */ diff --git a/lib/Kconfig b/lib/Kconfig index b6b8b8d9c29..fc2db747dcc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1122,7 +1122,7 @@ config SPL_LMB config LMB_ARCH_MEM_MAP bool "Add an architecture specific memory map" depends on LMB - default y if FSL_LAYERSCAPE + default y if FSL_LAYERSCAPE || X86 help Some architectures have special or unique aspects which need consideration when adding memory ranges to the list of available