From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web09.9163.1638946978671392265 for ; Tue, 07 Dec 2021 23:02:58 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SVgo7ZHU; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638946977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P9PRRAKLXRcnZw0GOHpUzHgx4XzFWlHLX28diRfcimo=; b=SVgo7ZHUu5Op55WdI7F5GVh0gm4MUpAz283icJwVmT41Lco48GEU9YK3F3dzfnovaKSBPQ nFOF7IRr26IQ6QS4hXMxdPJdYys/zC5MXO8YcCgF7Yum+cI0ufOaysp+nobcRnnzDyoQ+D HoFPl5vmx7Ne9ZjHneohT45ryQU7WYo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-_ayRvrmbMzKkuTNwyA6d-g-1; Wed, 08 Dec 2021 02:02:54 -0500 X-MC-Unique: _ayRvrmbMzKkuTNwyA6d-g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A5EE1006AA3; Wed, 8 Dec 2021 07:02:53 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3583710A3945; Wed, 8 Dec 2021 07:02:07 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 212CE18000B2; Wed, 8 Dec 2021 08:01:46 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Ard Biesheuvel , Pawel Polawski , Jordan Justen , Jiewen Yao , Gerd Hoffmann Subject: [PATCH v4 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Date: Wed, 8 Dec 2021 08:01:45 +0100 Message-Id: <20211208070146.1239368-3-kraxel@redhat.com> In-Reply-To: <20211208070146.1239368-1-kraxel@redhat.com> References: <20211208070146.1239368-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Prefer the e820 map provided via qemu firmware config interface for memory detection. Use rtc cmos only as fallback, which should be rarely needed these days as qemu supports etc/e820 since 2013. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3593 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- OvmfPkg/PlatformPei/MemDetect.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 912889ab9b75..e0f2caa9cd3c 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -313,8 +313,15 @@ GetSystemMemorySizeBelow4gb ( VOID ) { - UINT8 Cmos0x34; - UINT8 Cmos0x35; + EFI_STATUS Status; + UINT64 LowerMemorySize = 0; + UINT8 Cmos0x34; + UINT8 Cmos0x35; + + Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL); + if ((Status == EFI_SUCCESS) && (LowerMemorySize > 0)) { + return (UINT32)LowerMemorySize; + } // // CMOS 0x34/0x35 specifies the system memory above 16 MB. @@ -769,7 +776,6 @@ QemuInitializeRam ( // Determine total memory size available // LowerMemorySize = GetSystemMemorySizeBelow4gb (); - UpperMemorySize = GetSystemMemorySizeAbove4gb (); if (mBootMode == BOOT_ON_S3_RESUME) { // @@ -819,8 +825,11 @@ QemuInitializeRam ( // memory size read from the CMOS. // Status = ScanOrAdd64BitE820Ram (TRUE, NULL, NULL); - if (EFI_ERROR (Status) && (UpperMemorySize != 0)) { - AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + if (EFI_ERROR (Status)) { + UpperMemorySize = GetSystemMemorySizeAbove4gb (); + if (UpperMemorySize != 0) { + AddMemoryBaseSizeHob (BASE_4GB, UpperMemorySize); + } } } -- 2.33.1