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.133.124]) by mx.groups.io with SMTP id smtpd.web10.566.1631804649896974365 for ; Thu, 16 Sep 2021 08:04:10 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DDk0PYoL; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631804649; 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=axYFnPiY18tDy4gTXsec2xZ8VJk5FaBJSjYpiQXbjX8=; b=DDk0PYoLCgV91MuyJs3zimoMaMc7gWyKP7pb0tz4MVOiSH4oO0wa++nyk6VioxVut6WYCd FyEBwF4To8N9W6RwMNAmnMMb0l3VxSRA79FrOIjwY4g5hN8ePWnLYjF17l1nQBzBSGSvpS BreNVjtu+aIjcR7GRzn08AXP0awscd4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-OgxB9PefONOitRq9tVvAqQ-1; Thu, 16 Sep 2021 11:04:04 -0400 X-MC-Unique: OgxB9PefONOitRq9tVvAqQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCB2C801B3D; Thu, 16 Sep 2021 15:04:03 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07AB67A8CE; Thu, 16 Sep 2021 15:04:00 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 33DD818007A8; Thu, 16 Sep 2021 17:03:52 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Philippe Mathieu-Daude , Jiewen Yao , Jordan Justen , Ard Biesheuvel , Gerd Hoffmann Subject: [PATCH v3 2/3] OvmfPkg/PlatformPei: prefer etc/e820 for memory detection Date: Thu, 16 Sep 2021 17:03:51 +0200 Message-Id: <20210916150352.2662317-3-kraxel@redhat.com> In-Reply-To: <20210916150352.2662317-1-kraxel@redhat.com> References: <20210916150352.2662317-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 500c1d4d5231..1d942b12d519 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -293,9 +293,16 @@ GetSystemMemorySizeBelow4gb ( VOID ) { + 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. // * CMOS(0x35) is the high byte @@ -722,7 +729,6 @@ QemuInitializeRam ( // Determine total memory size available // LowerMemorySize = GetSystemMemorySizeBelow4gb (); - UpperMemorySize = GetSystemMemorySizeAbove4gb (); if (mBootMode == BOOT_ON_S3_RESUME) { // @@ -769,8 +775,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.31.1