From patchwork Tue Oct 15 15:37:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 835447 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c8f:0:b0:37d:45d0:187 with SMTP id z15csp300622wrs; Tue, 15 Oct 2024 08:38:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXKoTcWqhOT1WEyzwclP0NWg3lLtqkWUgBZdcfzMFBTNmcaTN5T1+tmZ3eXdagF6RBSqHVvQA==@linaro.org X-Google-Smtp-Source: AGHT+IGkqz5yhpSQ/JhCOClkySyChydfxf2ixDasb3EOuDr/BSsZ0ZoVfcHJBDNhbf7zrwlP24bU X-Received: by 2002:a05:6e02:1d0c:b0:3a1:a26e:81a with SMTP id e9e14a558f8ab-3a3dc4a7b7fmr8370585ab.7.1729006692896; Tue, 15 Oct 2024 08:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729006692; cv=none; d=google.com; s=arc-20240605; b=PjlknAOjOpXxoEAP6xQ2Ko+8MSBLfL63ZI6F3FnZhQ8m51cvDE1rlXO6gjoO7f1F7x kh+QaRPxa/1aMLsxkz9z4TGN15/AktFC0JDMDPCaXUcCS4+KoMHDkMOjYRge9kwkhOoD cHrgVyUB9VUkStvgtZcBhiFYwVTsaNdtqH9lPjW1VIEy/12D6FHoKs5v0k3TqfcYVf8S QRpaOmkjbeb0UF0+FEPl4PVE2isaO2mwI9M5PvvwCMrktQVj/Zqnvw8D5/zDjAigHU7t 3k4AMyobnL01PWZuSkIBD02UzXLlHT6RjxKm+N7Sh1ywwO4upPDxChJYSlF+RQzSmMi4 ZWXQ== 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=/jPINX3FfJ6MU2DPrJW/EKNGj1YmWvrijZLhn6HC8F8=; fh=MYvlzMqd61VHJORtkCu1tTA+qP9jRMJFkVEqSzDEdy8=; b=BM3MRN8q7aEgUO1V1iV2M19fNkTHs5cBSZNefQoRPe3aTfrVI2uyQnRKaOezZoNXWq f4Rn3lZv4jl7viY4SjyetHtjBWadXQFTUBExdQXR+l68fGpfdTCPyi9dc2Qk0cpXKvyO OG8A7uAVdf/65fLGqLxe/Obp++y+zrl06tDc2j6i09Dtj65tRb7h8QKk6uxcr+de2NuU y98LL3DuDIxqYbEJg3A1OlM2ZDoqPmSPOg+kPqq91dGMjh+9yNtEKcS4hMS6rQshkA0c ZzB9hLiHgfRjC/aAtRPuwC3tiu3FFGDs6N/pm/k979Ur2aMpEaoiL8Yu6Ki/3+9oVDdh Jnqw==; 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 e9e14a558f8ab-3a3d70feebasi7188645ab.23.2024.10.15.08.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2024 08:38:12 -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 0429C889B3; Tue, 15 Oct 2024 17:37:53 +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 8E65D889C3; Tue, 15 Oct 2024 17:37:52 +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 2580988A24 for ; Tue, 15 Oct 2024 17:37: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 311F9153B; Tue, 15 Oct 2024 08:38:18 -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 B26C43F528; Tue, 15 Oct 2024 08:37:45 -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 03/15] lmb: add and reserve memory above ram_top Date: Tue, 15 Oct 2024 21:07:05 +0530 Message-Id: <20241015153717.401371-4-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 U-Boot does not use memory above ram_top. However, this memory does need to get registered as part of the memory map, so that subsystems like EFI pass it on to the operating system as part of the EFI memory map. Add memory above ram_top and reserve it with the LMB_NOOVERWRITE flag so that it does not get allocated or re-used. Signed-off-by: Sughosh Ganu Suggested-by: Mark Kettenis --- Changes since V3: New patch lib/lmb.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index e1e616679f0..0504a7b3407 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -281,7 +281,6 @@ 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; @@ -292,16 +291,16 @@ void lmb_add_memory(void) 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); + + /* + * Reserve memory above ram_top as + * no-overwrite so that it cannot be + * allocated + */ + if (bd->bi_dram[i].start >= ram_top) + lmb_reserve_flags(bd->bi_dram[i].start, size, + LMB_NOOVERWRITE); } } }